···11+defmodule Atex.HTTP do
22+ @adapter Application.compile_env(:atex, :adapter, Atex.HTTP.Adapter.Req)
33+44+ defdelegate get(url, opts), to: @adapter
55+ defdelegate post(url, opts), to: @adapter
66+end
+9-13
lib/xrpc.ex
···11defmodule Atex.XRPC do
22- alias Atex.XRPC
33-44- defp adapter do
55- Application.get_env(:atex, :adapter, XRPC.Adapter.Req)
66- end
22+ alias Atex.{HTTP, XRPC}
7384 # TODO: automatic user-agent, and env for changing it
95···1612 @doc """
1713 Perform a HTTP GET on a XRPC resource. Called a "query" in lexicons.
1814 """
1919- @spec get(XRPC.Client.t(), String.t(), keyword()) :: XRPC.Adapter.result()
1515+ @spec get(XRPC.Client.t(), String.t(), keyword()) :: HTTP.Adapter.result()
2016 def get(%XRPC.Client{} = client, name, opts \\ []) do
2117 opts = put_auth(opts, client.access_token)
2222- adapter().get(url(client, name), opts)
1818+ HTTP.get(url(client, name), opts)
2319 end
24202521 @doc """
2622 Perform a HTTP POST on a XRPC resource. Called a "prodecure" in lexicons.
2723 """
2828- @spec post(XRPC.Client.t(), String.t(), keyword()) :: XRPC.Adapter.result()
2424+ @spec post(XRPC.Client.t(), String.t(), keyword()) :: HTTP.Adapter.result()
2925 def post(%XRPC.Client{} = client, name, opts \\ []) do
3026 # TODO: look through available HTTP clients and see if they have a
3127 # consistent way of providing JSON bodies with auto content-type. If not,
3228 # create one for adapters.
3329 opts = put_auth(opts, client.access_token)
3434- adapter().post(url(client, name), opts)
3030+ HTTP.post(url(client, name), opts)
3531 end
36323733 @doc """
3834 Like `get/3` but is unauthenticated by default.
3935 """
4040- @spec unauthed_get(String.t(), String.t(), keyword()) :: XRPC.Adapter.result()
3636+ @spec unauthed_get(String.t(), String.t(), keyword()) :: HTTP.Adapter.result()
4137 def unauthed_get(endpoint, name, opts \\ []) do
4242- adapter().get(url(endpoint, name), opts)
3838+ HTTP.get(url(endpoint, name), opts)
4339 end
44404541 @doc """
4642 Like `post/3` but is unauthenticated by default.
4743 """
4848- @spec unauthed_post(String.t(), String.t(), keyword()) :: XRPC.Adapter.result()
4444+ @spec unauthed_post(String.t(), String.t(), keyword()) :: HTTP.Adapter.result()
4945 def unauthed_post(endpoint, name, opts \\ []) do
5050- adapter().post(url(endpoint, name), opts)
4646+ HTTP.post(url(endpoint, name), opts)
5147 end
52485349 # TODO: use URI module for joining instead?
+2-2
lib/xrpc/adapter.ex
lib/http/adapter.ex
···11-defmodule Atex.XRPC.Adapter do
11+defmodule Atex.HTTP.Adapter do
22 @moduledoc """
33- Behaviour for defining a HTTP client adapter to be used for XRPC.
33+ Behaviour for defining a HTTP client adapter to be used within atex.
44 """
5566 @type success() :: {:ok, map()}
+3-3
lib/xrpc/adapter/req.ex
lib/http/adapter/req.ex
···11-defmodule Atex.XRPC.Adapter.Req do
11+defmodule Atex.HTTP.Adapter.Req do
22 @moduledoc """
33- `Req` adapter for XRPC.
33+ `Req` adapter for atex.
44 """
5566- @behaviour Atex.XRPC.Adapter
66+ @behaviour Atex.HTTP.Adapter
7788 def get(url, opts) do
99 Req.get(url, opts) |> adapt()
+5-5
lib/xrpc/client.ex
···11defmodule Atex.XRPC.Client do
22- @doc """
22+ @moduledoc """
33 Struct to store client information for ATProto XRPC.
44 """
5566- alias Atex.XRPC
66+ alias Atex.{XRPC, HTTP}
77 use TypedStruct
8899 typedstruct do
···3939 iex> Atex.XRPC.Client.login("https://bsky.social", "example.com", "password123")
4040 {:ok, %Atex.XRPC.Client{...}}
4141 """
4242- @spec login(String.t(), String.t(), String.t()) :: {:ok, t()} | XRPC.Adapter.error()
4242+ @spec login(String.t(), String.t(), String.t()) :: {:ok, t()} | HTTP.Adapter.error()
4343 @spec login(String.t(), String.t(), String.t(), String.t() | nil) ::
4444- {:ok, t()} | XRPC.Adapter.error()
4444+ {:ok, t()} | HTTP.Adapter.error()
4545 def login(endpoint, identifier, password, auth_factor_token \\ nil) do
4646 json =
4747 %{identifier: identifier, password: password}
···6767 @doc """
6868 Request a new `refresh_token` for the given client.
6969 """
7070- @spec refresh(t()) :: {:ok, t()} | XRPC.Adapter.error()
7070+ @spec refresh(t()) :: {:ok, t()} | HTTP.Adapter.error()
7171 def refresh(%__MODULE__{endpoint: endpoint, refresh_token: refresh_token} = client) do
7272 response =
7373 XRPC.unauthed_post(