Make LastFm user agent configurable

This commit is contained in:
Claudio Ortolina
2024-12-04 10:07:25 +00:00
parent 0cae20a390
commit 14518870a0
4 changed files with 15 additions and 9 deletions
+4 -5
View File
@@ -30,7 +30,7 @@ defmodule LastFm.APIImpl do
Logger.debug("Fetching data from #{sanitize_url(url, config.api_key)}")
case json_get(url) do
case json_get(url, config.user_agent) do
{:ok, response} ->
{:ok,
response
@@ -61,7 +61,7 @@ defmodule LastFm.APIImpl do
Logger.debug("Fetching data from #{sanitize_url(url, config.api_key)}")
case json_get(url) do
case json_get(url, config.user_agent) do
{:ok, response} ->
{:ok,
response
@@ -77,11 +77,10 @@ defmodule LastFm.APIImpl do
end
end
defp json_get(url) do
defp json_get(url, user_agent) do
req =
Finch.build(:get, url, [
# TODO: move user agent to config
{"User-Agent", "MusicLibrary/0.1.0 ( cloud8421@gmail.com )"}
{"User-Agent", user_agent}
])
case Finch.request(req, LastFm.Finch, @request_opts) do