Created
January 19, 2018 22:38
-
-
Save linuxandchill/65b4d72cf07215b842584789d64c0dbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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