feat: use jiffy instead of poison
This commit is contained in:
parent
c351dcd5c4
commit
34474a01b6
|
@ -1,5 +1,7 @@
|
||||||
defmodule Gh2ntfy.GhPoll do
|
defmodule Gh2ntfy.GhPoll do
|
||||||
alias Gh2ntfy.LastPoll
|
alias Gh2ntfy.LastPoll
|
||||||
|
alias Gh2ntfy.Util
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
use GenServer
|
use GenServer
|
||||||
|
@ -33,7 +35,7 @@ defmodule Gh2ntfy.GhPoll do
|
||||||
|
|
||||||
case result do
|
case result do
|
||||||
{:ok, %{body: body}} ->
|
{:ok, %{body: body}} ->
|
||||||
case Poison.decode(body) do
|
case Util.catch_tuple(fn -> :jiffy.decode(body, [:return_maps]) end) do
|
||||||
{:ok, res} ->
|
{:ok, res} ->
|
||||||
Gh2ntfy.LastPoll.set_now()
|
Gh2ntfy.LastPoll.set_now()
|
||||||
process_response(res)
|
process_response(res)
|
||||||
|
@ -81,7 +83,7 @@ defmodule Gh2ntfy.GhPoll do
|
||||||
|
|
||||||
defp get_issuecomment_url(api_url) do
|
defp get_issuecomment_url(api_url) do
|
||||||
{:ok, %{body: body}} = Finch.build(:get, api_url) |> Finch.request(Gh2ntfy.Finch)
|
{: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
|
url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
9
lib/gh2ntfy/util.ex
Normal file
9
lib/gh2ntfy/util.ex
Normal 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
|
Loading…
Reference in a new issue