+6
lib/http.ex
+6
lib/http.ex
+9
-13
lib/xrpc.ex
+9
-13
lib/xrpc.ex
···
1
1
defmodule Atex.XRPC do
2
-
alias Atex.XRPC
3
-
4
-
defp adapter do
5
-
Application.get_env(:atex, :adapter, XRPC.Adapter.Req)
6
-
end
2
+
alias Atex.{HTTP, XRPC}
7
3
8
4
# TODO: automatic user-agent, and env for changing it
9
5
···
16
12
@doc """
17
13
Perform a HTTP GET on a XRPC resource. Called a "query" in lexicons.
18
14
"""
19
-
@spec get(XRPC.Client.t(), String.t(), keyword()) :: XRPC.Adapter.result()
15
+
@spec get(XRPC.Client.t(), String.t(), keyword()) :: HTTP.Adapter.result()
20
16
def get(%XRPC.Client{} = client, name, opts \\ []) do
21
17
opts = put_auth(opts, client.access_token)
22
-
adapter().get(url(client, name), opts)
18
+
HTTP.get(url(client, name), opts)
23
19
end
24
20
25
21
@doc """
26
22
Perform a HTTP POST on a XRPC resource. Called a "prodecure" in lexicons.
27
23
"""
28
-
@spec post(XRPC.Client.t(), String.t(), keyword()) :: XRPC.Adapter.result()
24
+
@spec post(XRPC.Client.t(), String.t(), keyword()) :: HTTP.Adapter.result()
29
25
def post(%XRPC.Client{} = client, name, opts \\ []) do
30
26
# TODO: look through available HTTP clients and see if they have a
31
27
# consistent way of providing JSON bodies with auto content-type. If not,
32
28
# create one for adapters.
33
29
opts = put_auth(opts, client.access_token)
34
-
adapter().post(url(client, name), opts)
30
+
HTTP.post(url(client, name), opts)
35
31
end
36
32
37
33
@doc """
38
34
Like `get/3` but is unauthenticated by default.
39
35
"""
40
-
@spec unauthed_get(String.t(), String.t(), keyword()) :: XRPC.Adapter.result()
36
+
@spec unauthed_get(String.t(), String.t(), keyword()) :: HTTP.Adapter.result()
41
37
def unauthed_get(endpoint, name, opts \\ []) do
42
-
adapter().get(url(endpoint, name), opts)
38
+
HTTP.get(url(endpoint, name), opts)
43
39
end
44
40
45
41
@doc """
46
42
Like `post/3` but is unauthenticated by default.
47
43
"""
48
-
@spec unauthed_post(String.t(), String.t(), keyword()) :: XRPC.Adapter.result()
44
+
@spec unauthed_post(String.t(), String.t(), keyword()) :: HTTP.Adapter.result()
49
45
def unauthed_post(endpoint, name, opts \\ []) do
50
-
adapter().post(url(endpoint, name), opts)
46
+
HTTP.post(url(endpoint, name), opts)
51
47
end
52
48
53
49
# TODO: use URI module for joining instead?
+2
-2
lib/xrpc/adapter.ex
lib/http/adapter.ex
+2
-2
lib/xrpc/adapter.ex
lib/http/adapter.ex
+3
-3
lib/xrpc/adapter/req.ex
lib/http/adapter/req.ex
+3
-3
lib/xrpc/adapter/req.ex
lib/http/adapter/req.ex
+5
-5
lib/xrpc/client.ex
+5
-5
lib/xrpc/client.ex
···
1
1
defmodule Atex.XRPC.Client do
2
-
@doc """
2
+
@moduledoc """
3
3
Struct to store client information for ATProto XRPC.
4
4
"""
5
5
6
-
alias Atex.XRPC
6
+
alias Atex.{XRPC, HTTP}
7
7
use TypedStruct
8
8
9
9
typedstruct do
···
39
39
iex> Atex.XRPC.Client.login("https://bsky.social", "example.com", "password123")
40
40
{:ok, %Atex.XRPC.Client{...}}
41
41
"""
42
-
@spec login(String.t(), String.t(), String.t()) :: {:ok, t()} | XRPC.Adapter.error()
42
+
@spec login(String.t(), String.t(), String.t()) :: {:ok, t()} | HTTP.Adapter.error()
43
43
@spec login(String.t(), String.t(), String.t(), String.t() | nil) ::
44
-
{:ok, t()} | XRPC.Adapter.error()
44
+
{:ok, t()} | HTTP.Adapter.error()
45
45
def login(endpoint, identifier, password, auth_factor_token \\ nil) do
46
46
json =
47
47
%{identifier: identifier, password: password}
···
67
67
@doc """
68
68
Request a new `refresh_token` for the given client.
69
69
"""
70
-
@spec refresh(t()) :: {:ok, t()} | XRPC.Adapter.error()
70
+
@spec refresh(t()) :: {:ok, t()} | HTTP.Adapter.error()
71
71
def refresh(%__MODULE__{endpoint: endpoint, refresh_token: refresh_token} = client) do
72
72
response =
73
73
XRPC.unauthed_post(