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
+4 -2
View File
@@ -4,14 +4,16 @@ defmodule LastFm.Config do
api_key: String.t(),
user: String.t(),
auto_refresh: boolean(),
refresh_interval: pos_integer()
refresh_interval: pos_integer(),
user_agent: String.t()
}
defstruct api: LastFm.Api,
api_key: "",
user: "",
auto_refresh: true,
refresh_interval: 60_000
refresh_interval: 60_000,
user_agent: "change me"
@spec resolve(atom) :: t
def resolve(otp_app) do