feat: use jiffy instead of poison

This commit is contained in:
LordMZTE 2023-02-08 22:02:38 +01:00
parent c351dcd5c4
commit 34474a01b6
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
3 changed files with 14 additions and 3 deletions

View file

@ -1,5 +1,7 @@
defmodule Gh2ntfy.GhPoll do
alias Gh2ntfy.LastPoll
alias Gh2ntfy.Util
require Logger
use GenServer
@ -33,7 +35,7 @@ defmodule Gh2ntfy.GhPoll do
case result do
{:ok, %{body: body}} ->
case Poison.decode(body) do
case Util.catch_tuple(fn -> :jiffy.decode(body, [:return_maps]) end) do
{:ok, res} ->
Gh2ntfy.LastPoll.set_now()
process_response(res)
@ -81,7 +83,7 @@ defmodule Gh2ntfy.GhPoll do
defp get_issuecomment_url(api_url) do
{:ok, %{body: body}} = Finch.build(:get, api_url) |> Finch.request(Gh2ntfy.Finch)
%{"html_url" => url} = Poison.decode!(body)
%{"html_url" => url} = :jiffy.decode(body, [:return_maps])
url
end
end

9
lib/gh2ntfy/util.ex Normal file
View file

@ -0,0 +1,9 @@
defmodule Gh2ntfy.Util do
def catch_tuple(f) when is_function(f, 0) do
try do
{:ok, f.()}
rescue
e -> {:error, e}
end
end
end

View file

@ -28,7 +28,7 @@ defmodule Gh2ntfy.MixProject do
defp deps do
[
{:finch, "~> 0.14.0"},
{:poison, "~> 5.0"}
{:jiffy, "~> 1.1"}
]
end
end