Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
5use SocialDept\AtpClient\Attributes\PublicEndpoint;
6use SocialDept\AtpClient\Client\Requests\Request;
7use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowersResponse;
8use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowsResponse;
9use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetKnownFollowersResponse;
10use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetListResponse;
11use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetListsResponse;
12use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetRelationshipsResponse;
13use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetStarterPacksResponse;
14use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetSuggestedFollowsByActorResponse;
15use SocialDept\AtpClient\Enums\Nsid\BskyGraph;
16use SocialDept\AtpSchema\Generated\App\Bsky\Graph\Defs\StarterPackView;
17
18class GraphRequestClient extends Request
19{
20 /**
21 * Get followers of an actor
22 *
23 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-followers
24 */
25 #[PublicEndpoint]
26 public function getFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetFollowersResponse
27 {
28 $response = $this->atp->client->get(
29 endpoint: BskyGraph::GetFollowers,
30 params: compact('actor', 'limit', 'cursor')
31 );
32
33 return GetFollowersResponse::fromArray($response->json());
34 }
35
36 /**
37 * Get accounts that an actor follows
38 *
39 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-follows
40 */
41 #[PublicEndpoint]
42 public function getFollows(string $actor, int $limit = 50, ?string $cursor = null): GetFollowsResponse
43 {
44 $response = $this->atp->client->get(
45 endpoint: BskyGraph::GetFollows,
46 params: compact('actor', 'limit', 'cursor')
47 );
48
49 return GetFollowsResponse::fromArray($response->json());
50 }
51
52 /**
53 * Get followers of an actor that you also follow
54 *
55 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-known-followers
56 */
57 #[PublicEndpoint]
58 public function getKnownFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetKnownFollowersResponse
59 {
60 $response = $this->atp->client->get(
61 endpoint: BskyGraph::GetKnownFollowers,
62 params: compact('actor', 'limit', 'cursor')
63 );
64
65 return GetKnownFollowersResponse::fromArray($response->json());
66 }
67
68 /**
69 * Get a list by URI
70 *
71 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-list
72 */
73 #[PublicEndpoint]
74 public function getList(string $list, int $limit = 50, ?string $cursor = null): GetListResponse
75 {
76 $response = $this->atp->client->get(
77 endpoint: BskyGraph::GetList,
78 params: compact('list', 'limit', 'cursor')
79 );
80
81 return GetListResponse::fromArray($response->json());
82 }
83
84 /**
85 * Get lists created by an actor
86 *
87 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-lists
88 */
89 #[PublicEndpoint]
90 public function getLists(string $actor, int $limit = 50, ?string $cursor = null): GetListsResponse
91 {
92 $response = $this->atp->client->get(
93 endpoint: BskyGraph::GetLists,
94 params: compact('actor', 'limit', 'cursor')
95 );
96
97 return GetListsResponse::fromArray($response->json());
98 }
99
100 /**
101 * Get relationships between actors
102 *
103 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-relationships
104 */
105 #[PublicEndpoint]
106 public function getRelationships(string $actor, array $others = []): GetRelationshipsResponse
107 {
108 $response = $this->atp->client->get(
109 endpoint: BskyGraph::GetRelationships,
110 params: compact('actor', 'others')
111 );
112
113 return GetRelationshipsResponse::fromArray($response->json());
114 }
115
116 /**
117 * Get a starter pack by URI
118 *
119 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-starter-pack
120 */
121 #[PublicEndpoint]
122 public function getStarterPack(string $starterPack): StarterPackView
123 {
124 $response = $this->atp->client->get(
125 endpoint: BskyGraph::GetStarterPack,
126 params: compact('starterPack')
127 );
128
129 return StarterPackView::fromArray($response->json()['starterPack']);
130 }
131
132 /**
133 * Get multiple starter packs
134 *
135 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-starter-packs
136 */
137 #[PublicEndpoint]
138 public function getStarterPacks(array $uris): GetStarterPacksResponse
139 {
140 $response = $this->atp->client->get(
141 endpoint: BskyGraph::GetStarterPacks,
142 params: compact('uris')
143 );
144
145 return GetStarterPacksResponse::fromArray($response->json());
146 }
147
148 /**
149 * Get suggested follows based on an actor
150 *
151 * @see https://docs.bsky.app/docs/api/app-bsky-graph-get-suggested-follows-by-actor
152 */
153 #[PublicEndpoint]
154 public function getSuggestedFollowsByActor(string $actor): GetSuggestedFollowsByActorResponse
155 {
156 $response = $this->atp->client->get(
157 endpoint: BskyGraph::GetSuggestedFollowsByActor,
158 params: compact('actor')
159 );
160
161 return GetSuggestedFollowsByActorResponse::fromArray($response->json());
162 }
163}