Skip to content

Commit 819a2b2

Browse files
begedinjoshsmith
authored andcommitted
Further cleanup
1 parent fdac404 commit 819a2b2

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/code_corps/github/api/eager_api.ex

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,15 @@ defmodule CodeCorps.GitHub.EagerAPI do
4343
end
4444

4545
def extract_total_pages(links_string) do
46-
links = String.split(links_string, ", ")
47-
last_page_url = Enum.map(links, fn link ->
48-
[_, name] = Regex.run(~r{rel="([a-z]+)"}, link)
49-
[_, url] = Regex.run(~r{<([^>]+)>}, link)
50-
51-
{name, url}
52-
end) |> Enum.into(%{}) |> Map.get("last")
53-
54-
last_page_url
55-
|> URI.parse
56-
|> Map.get(:query)
57-
|> URI.decode_query
58-
|> Map.get("page")
59-
|> String.to_integer
46+
links_string
47+
|> String.split(", ")
48+
|> Enum.map(fn link ->
49+
rel = Regex.run(~r{rel="([a-z]+)"}, link) |> List.last
50+
page = Regex.run(~r{[&/?]page=([^>&]+)}, link) |> List.last |> String.to_integer
51+
52+
{rel, page}
53+
end)
54+
|> Enum.into(%{})
55+
|> Map.get("last")
6056
end
6157
end

lib/code_corps/github/api/repository.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ defmodule CodeCorps.GitHub.API.Repository do
4646
elapsed = Timex.diff(after_operation, before_operation)
4747
IO.puts("Stream: #{count} records, #{per_page} records per page, #{pages} pages total, #{elapsed} microseconds")
4848

49-
results
49+
# results
5050
end
5151

5252
defp fetch_lazy(path, opts) do

0 commit comments

Comments
 (0)