Use built-in Req stub for LastFm tests
This commit is contained in:
+4
-4
@@ -2,7 +2,7 @@ defmodule LastFm do
|
||||
def get_artist_info(musicbrainz_id, name) do
|
||||
last_fm_config = last_fm_config()
|
||||
|
||||
case last_fm_config.api.get_artist_info(
|
||||
case LastFm.APIImpl.get_artist_info(
|
||||
{:musicbrainz_id, musicbrainz_id},
|
||||
last_fm_config
|
||||
) do
|
||||
@@ -12,7 +12,7 @@ defmodule LastFm do
|
||||
{:error, :invalid_parameters} ->
|
||||
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
|
||||
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
|
||||
last_fm_config.api.get_artist_info({:name, name}, last_fm_config)
|
||||
LastFm.APIImpl.get_artist_info({:name, name}, last_fm_config)
|
||||
|
||||
error ->
|
||||
error
|
||||
@@ -22,7 +22,7 @@ defmodule LastFm do
|
||||
def get_similar_artists(musicbrainz_id, name) do
|
||||
last_fm_config = last_fm_config()
|
||||
|
||||
case last_fm_config.api.get_similar_artists(
|
||||
case LastFm.APIImpl.get_similar_artists(
|
||||
{:musicbrainz_id, musicbrainz_id},
|
||||
last_fm_config
|
||||
) do
|
||||
@@ -32,7 +32,7 @@ defmodule LastFm do
|
||||
{:error, :invalid_parameters} ->
|
||||
# Sometimes the artist info cannot be identified with the MusicBrainz ID,
|
||||
# because Last.fm doesn't have that information. In that case, we try again with the artist name.
|
||||
last_fm_config.api.get_similar_artists({:name, name}, last_fm_config)
|
||||
LastFm.APIImpl.get_similar_artists({:name, name}, last_fm_config)
|
||||
|
||||
error ->
|
||||
error
|
||||
|
||||
@@ -102,6 +102,7 @@ defmodule LastFm.APIImpl do
|
||||
],
|
||||
user_agent: config.user_agent
|
||||
)
|
||||
|> Req.Request.merge_options(config.req_options)
|
||||
|> Req.Request.put_private(:api_key, config.api_key)
|
||||
|> Req.Request.append_request_steps(log_attempt: &log_attempt/1)
|
||||
|> Req.Request.append_response_steps(parse_error: &parse_error/1)
|
||||
@@ -114,6 +115,9 @@ defmodule LastFm.APIImpl do
|
||||
|
||||
{:ok, response} ->
|
||||
{:ok, response.body}
|
||||
|
||||
error ->
|
||||
error
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@ defmodule LastFm.Config do
|
||||
user: String.t(),
|
||||
auto_refresh: boolean(),
|
||||
refresh_interval: pos_integer(),
|
||||
user_agent: String.t()
|
||||
user_agent: String.t(),
|
||||
req_options: Keyword.t()
|
||||
}
|
||||
|
||||
@enforce_keys [:api, :api_key, :user]
|
||||
@@ -14,7 +15,8 @@ defmodule LastFm.Config do
|
||||
user: "",
|
||||
auto_refresh: true,
|
||||
refresh_interval: 60_000,
|
||||
user_agent: "change me"
|
||||
user_agent: "change me",
|
||||
req_options: []
|
||||
|
||||
@schema NimbleOptions.new!(
|
||||
api: [
|
||||
@@ -43,6 +45,11 @@ defmodule LastFm.Config do
|
||||
type: :string,
|
||||
required: false,
|
||||
default: "change me"
|
||||
],
|
||||
req_options: [
|
||||
type: :keyword_list,
|
||||
required: false,
|
||||
default: []
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user