Initial commit

This commit is contained in:
2021-07-12 14:29:27 +03:00
parent 6c7cd5aee2
commit b48a9f5c58
28 changed files with 472 additions and 13 deletions

View File

@@ -0,0 +1,8 @@
defmodule ExDataGovUA.Fetchers.Base do
@type data :: map()
@type status :: Atom.t()
@type url :: String.t()
@type method :: Atom.t()
@callback fetch(method, url) :: {status, data}
end

View File

@@ -0,0 +1,19 @@
defmodule ExDataGovUA.Fetchers.FinchFetcher do
@behaviour ExDataGovUA.Fetchers.Base
@impl true
def fetch(method, url) do
start()
with request <- Finch.build(method, url),
{:ok, %Finch.Response{body: body}} <- Finch.request(request, MyFinchFetcher) do
{:ok, body}
end
end
defp start() do
case Finch.start_link(name: MyFinchFetcher) do
{:ok, pid} -> pid
{:error, {:already_started, pid}} -> pid
end
end
end