Packages

Implementation of the ATProtocol client spec in Elixir.

Current section

4 Versions

Jump to

Compare versions

11 files changed
+175 additions
-4 deletions
  @@ -19,7 +19,7 @@ The docs can be found at <https://hexdocs.pm/atproto>.
19 19
20 20 ## Usage
21 21
22 - `ATProtocol` uses `XRPC` for API communication, so we need to build an `XRPC.Client` and then we can call `ATProto` or `ATProto.BSky` functions.
22 + `ATProtocol` uses [XRPC](https://github.com/moomerman/xrpc) for API communication, so we need to build an `XRPC.Client` and then we can call `ATProto` or `ATProto.BSky` functions.
23 23
24 24 Unauthenticated example:
  @@ -8,9 +8,14 @@
8 8 <<"lib/atproto/atproto">>,<<"lib/atproto/atproto/schemas">>,
9 9 <<"lib/atproto/atproto/schemas/session.ex">>,
10 10 <<"lib/atproto/atproto/schemas/label.ex">>,<<"lib/atproto/bsky">>,
11 - <<"lib/atproto/bsky/schemas">>,
11 + <<"lib/atproto/bsky/schemas">>,<<"lib/atproto/bsky/schemas/post_view.ex">>,
12 12 <<"lib/atproto/bsky/schemas/profile_viewer_state.ex">>,
13 13 <<"lib/atproto/bsky/schemas/profile_view_detailed.ex">>,
14 + <<"lib/atproto/bsky/schemas/feed.ex">>,
15 + <<"lib/atproto/bsky/schemas/profile_view_basic.ex">>,
16 + <<"lib/atproto/bsky/schemas/feed_view_post.ex">>,
17 + <<"lib/atproto/bsky/schemas/reply.ex">>,
18 + <<"lib/atproto/bsky/schemas/feed_viewer_state.ex">>,
14 19 <<"lib/atproto/bsky/rich_text.ex">>,<<"lib/atproto.ex">>,<<"mix.exs">>,
15 20 <<"README.md">>,<<"LICENSE">>]}.
16 21 {<<"licenses">>,[<<"MIT">>]}.
  @@ -27,4 +32,4 @@
27 32 {<<"optional">>,false},
28 33 {<<"repository">>,<<"hexpm">>},
29 34 {<<"requirement">>,<<"~> 0.1.0">>}]]}.
30 - {<<"version">>,<<"0.1.0">>}.
35 + {<<"version">>,<<"0.1.1">>}.
  @@ -14,6 +14,15 @@ defmodule ATProto.BSky do
14 14 ATProto.create_record(client, repo, "app.bsky.feed.post", record)
15 15 end
16 16
17 + def get_author_feed(client, actor, params \\ []) do
18 + params = [actor: actor] |> Keyword.merge(params)
19 +
20 + case XRPC.query(client, "app.bsky.feed.getAuthorFeed", params: params) do
21 + {:ok, body} -> ATProto.BSky.Feed.new(body)
22 + result -> result
23 + end
24 + end
25 +
17 26 # app.bsky.actor (https://atproto.com/lexicons/app-bsky-actor)
18 27
19 28 def get_profile(client, actor) do
  @@ -0,0 +1,30 @@
1 + defmodule ATProto.BSky.Feed do
2 + use Ecto.Schema
3 + import Ecto.Changeset
4 +
5 + @primary_key false
6 + embedded_schema do
7 + field :cursor, :string
8 + embeds_many :feed, ATProto.BSky.FeedViewPost
9 + end
10 +
11 + def changeset(attrs), do: changeset(%__MODULE__{}, attrs)
12 +
13 + def changeset(schema, attrs) do
14 + schema
15 + |> cast(attrs, [:cursor])
16 + |> cast_embed(:feed)
17 + end
18 +
19 + def new(params) do
20 + IO.inspect(params)
21 +
22 + case changeset(params) do
23 + %Ecto.Changeset{valid?: false} = changeset ->
24 + {:error, changeset}
25 +
26 + %Ecto.Changeset{valid?: true} = changeset ->
27 + {:ok, apply_changes(changeset)}
28 + end
29 + end
30 + end
  @@ -0,0 +1,19 @@
1 + defmodule ATProto.BSky.FeedViewPost do
2 + use Ecto.Schema
3 + import Ecto.Changeset
4 +
5 + @primary_key false
6 + embedded_schema do
7 + field :reason, :map
8 + embeds_one :post, ATProto.BSky.PostView
9 + embeds_one :reply, ATProto.BSky.Reply
10 + end
11 +
12 + def changeset(schema, attrs) do
13 + schema
14 + |> cast(attrs, [:reason])
15 + |> cast_embed(:post)
16 + |> cast_embed(:reply)
17 + |> validate_required([:post])
18 + end
19 + end
Loading more files…