Skip to content

Instantly share code, notes, and snippets.

@linuxandchill
Created January 19, 2018 22:38
Show Gist options
  • Save linuxandchill/65b4d72cf07215b842584789d64c0dbc to your computer and use it in GitHub Desktop.
Save linuxandchill/65b4d72cf07215b842584789d64c0dbc to your computer and use it in GitHub Desktop.
defmodule Utils do
@username Application.get_env(:app_name, :username)
@password Application.get_env(:app_name, :password)
@base_url "https://api.intrinio.com/"
@headers %{"Authorization" => "Basic " <> Base.encode64("#{@username}:#{@password}")}
def page_loop(current_page \\ 1, acc \\ [], ticker \\ "") do
%HTTPoison.Response{body: response} =
HTTPoison.get! @base_url <> "prices?ticker=#{ticker}" <>
"&page_number=#{current_page}", @headers
data = response |> process_resp() |> Map.get("data")
data_list = [data | acc]
case get_total_pages(response) do
^current_page -> List.flatten data_list
_ -> page_loop(current_page + 1, data_list, ticker)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment