A last.fm clone written in Elixir
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

28 lines
720 B

defmodule Dagon.Listens.RateLimit do
@id_listenbrainz "LB"
@id_discogs "DC"
def calculate(headers, @id_listenbrainz) do
keyword_list = convert_to_keyword_list(headers)
%{
total: Keyword.get(keyword_list, :"X-RateLimit-Limit"),
remaining: Keyword.get(keyword_list, :"X-RateLimit-Remaining")
}
end
def calculate(headers, @id_discogs) do
keyword_list = convert_to_keyword_list(headers)
%{
total: Keyword.get(keyword_list, :"X-Discogs-Ratelimit"),
remaining: Keyword.get(keyword_list, :"X-Discogs-Ratelimit-Remaining")
}
end
defp convert_to_keyword_list(list) do
Enum.map(list, fn {name, value} ->
{String.to_atom(name), value}
end)
end
end