Where possible, use built-in JSON instead of Jason
Note that it's not possible to replace any call where we encode and pretty print, as JSON doesn't have such functionality.
This commit is contained in:
@@ -133,7 +133,7 @@ defmodule LastFm.APIImpl do
|
|||||||
|
|
||||||
case Finch.request(req, LastFm.Finch, @request_opts) do
|
case Finch.request(req, LastFm.Finch, @request_opts) do
|
||||||
{:ok, response} when response.status == 200 ->
|
{:ok, response} when response.status == 200 ->
|
||||||
Jason.decode(response.body)
|
JSON.decode(response.body)
|
||||||
|> identify_body()
|
|> identify_body()
|
||||||
|
|
||||||
other ->
|
other ->
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ defmodule Mix.Tasks.MusicBrainz.RefreshFixtures do
|
|||||||
{:ok, body} ->
|
{:ok, body} ->
|
||||||
# store the fixture pretty printed
|
# store the fixture pretty printed
|
||||||
dest = Path.join(@fixtures_folder, filename)
|
dest = Path.join(@fixtures_folder, filename)
|
||||||
content = body |> Jason.decode!() |> Jason.encode!(pretty: true)
|
content = body |> JSON.decode!() |> Jason.encode!(pretty: true)
|
||||||
File.write!(dest, content)
|
File.write!(dest, content)
|
||||||
|
|
||||||
{:error, msg} ->
|
{:error, msg} ->
|
||||||
|
|||||||
@@ -439,7 +439,7 @@ defmodule MusicBrainz.APIImpl do
|
|||||||
|
|
||||||
case Finch.request(req, MusicBrainz.Finch) do
|
case Finch.request(req, MusicBrainz.Finch) do
|
||||||
{:ok, response} when response.status == 200 ->
|
{:ok, response} when response.status == 200 ->
|
||||||
{:ok, Jason.decode!(response.body)}
|
{:ok, JSON.decode!(response.body)}
|
||||||
|
|
||||||
{:ok, response} when response.status in 301..308 ->
|
{:ok, response} when response.status in 301..308 ->
|
||||||
location = :proplists.get_value("location", response.headers)
|
location = :proplists.get_value("location", response.headers)
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ defmodule OpenAI do
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
result = Agent.get(collector, & &1) |> Jason.decode!()
|
result = Agent.get(collector, & &1) |> JSON.decode!()
|
||||||
Agent.stop(collector)
|
Agent.stop(collector)
|
||||||
{:ok, result}
|
{:ok, result}
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -64,7 +64,7 @@ defmodule OpenAI.API do
|
|||||||
|
|
||||||
defp decode_body("", _), do: :ok
|
defp decode_body("", _), do: :ok
|
||||||
defp decode_body("[DONE]", _), do: :ok
|
defp decode_body("[DONE]", _), do: :ok
|
||||||
defp decode_body(json, cb), do: cb.(Jason.decode!(json))
|
defp decode_body(json, cb), do: cb.(JSON.decode!(json))
|
||||||
|
|
||||||
defp api_key do
|
defp api_key do
|
||||||
Application.get_env(:music_library, OpenAI)
|
Application.get_env(:music_library, OpenAI)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ defmodule LastFm.ArtistTest do
|
|||||||
api_response =
|
api_response =
|
||||||
@api_response_path
|
@api_response_path
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
|> Map.get("artist")
|
|> Map.get("artist")
|
||||||
|
|
||||||
assert %LastFm.Artist{
|
assert %LastFm.Artist{
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ defmodule LastFm.TrackTest do
|
|||||||
api_response =
|
api_response =
|
||||||
@api_response_path
|
@api_response_path
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
|> get_in(["recenttracks", "track"])
|
|> get_in(["recenttracks", "track"])
|
||||||
|
|
||||||
assert [
|
assert [
|
||||||
|
|||||||
@@ -4,6 +4,6 @@ defmodule LastFm.Fixtures do
|
|||||||
def artist_get_info do
|
def artist_get_info do
|
||||||
Path.join([@fixtures_folder, "artist.getinfo.json"])
|
Path.join([@fixtures_folder, "artist.getinfo.json"])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ defmodule MusicLibrary.ReleaseGroupsFixtures do
|
|||||||
def release_group(:mystery_of_time) do
|
def release_group(:mystery_of_time) do
|
||||||
Path.join([@fixtures_folder, "release_group - avantasia - the mystery of time.json"])
|
Path.join([@fixtures_folder, "release_group - avantasia - the mystery of time.json"])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_group(:marbles) do
|
def release_group(:marbles) do
|
||||||
Path.join([@fixtures_folder, "release_group - marillion - marbles.json"])
|
Path.join([@fixtures_folder, "release_group - marillion - marbles.json"])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_group(:lockdown_trilogy) do
|
def release_group(:lockdown_trilogy) do
|
||||||
@@ -38,19 +38,19 @@ defmodule MusicLibrary.ReleaseGroupsFixtures do
|
|||||||
"release_group_with_includes - mariusz duda - lockdown trilogy.json"
|
"release_group_with_includes - mariusz duda - lockdown trilogy.json"
|
||||||
])
|
])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def release(:mystery_of_time) do
|
def release(:mystery_of_time) do
|
||||||
Path.join([@fixtures_folder, "release - avantasia - the mystery of time.json"])
|
Path.join([@fixtures_folder, "release - avantasia - the mystery of time.json"])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def release(:marbles) do
|
def release(:marbles) do
|
||||||
Path.join([@fixtures_folder, "release - marillion - marbles.json"])
|
Path.join([@fixtures_folder, "release - marillion - marbles.json"])
|
||||||
|> File.read!()
|
|> File.read!()
|
||||||
|> Jason.decode!()
|
|> JSON.decode!()
|
||||||
end
|
end
|
||||||
|
|
||||||
def release_group_id(name) do
|
def release_group_id(name) do
|
||||||
|
|||||||
Reference in New Issue
Block a user