Migrate to Vue 3 and Vite
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
39
lib/service/http/generic_json_client.ex
Normal file
39
lib/service/http/generic_json_client.ex
Normal file
@@ -0,0 +1,39 @@
|
||||
defmodule Mobilizon.Service.HTTP.GenericJSONClient do
|
||||
@moduledoc """
|
||||
Tesla HTTP Client that is preconfigured to get JSON content
|
||||
"""
|
||||
|
||||
alias Mobilizon.Config
|
||||
|
||||
@default_opts [
|
||||
recv_timeout: 20_000
|
||||
]
|
||||
|
||||
@spec client(Keyword.t()) :: Tesla.Client.t()
|
||||
def client(options \\ []) do
|
||||
headers = Keyword.get(options, :headers, [])
|
||||
adapter = Application.get_env(:tesla, __MODULE__, [])[:adapter] || Tesla.Adapter.Hackney
|
||||
opts = Keyword.merge(@default_opts, Keyword.get(options, :opts, []))
|
||||
|
||||
middleware = [
|
||||
{Tesla.Middleware.Headers,
|
||||
[{"User-Agent", Config.instance_user_agent()}] ++
|
||||
headers},
|
||||
Tesla.Middleware.FollowRedirects,
|
||||
{Tesla.Middleware.Timeout, timeout: 10_000},
|
||||
Tesla.Middleware.JSON
|
||||
]
|
||||
|
||||
Tesla.client(middleware, {adapter, opts})
|
||||
end
|
||||
|
||||
@spec get(Tesla.Client.t(), String.t()) :: Tesla.Env.result()
|
||||
def get(client, url) do
|
||||
Tesla.get(client, url)
|
||||
end
|
||||
|
||||
@spec post(Tesla.Client.t(), String.t(), map() | String.t()) :: Tesla.Env.result()
|
||||
def post(client, url, data) do
|
||||
Tesla.post(client, url, data)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user