Laravel AT Protocol Client (alpha & unstable)
1<?php
2
3namespace SocialDept\AtpClient\Client\Requests\Bsky;
4
5use SocialDept\AtpClient\Attributes\PublicEndpoint;
6use SocialDept\AtpClient\Attributes\ScopedEndpoint;
7use SocialDept\AtpClient\Client\Requests\Request;
8use SocialDept\AtpClient\Data\Responses\Bsky\Feed\DescribeFeedGeneratorResponse;
9use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetActorFeedsResponse;
10use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetActorLikesResponse;
11use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetAuthorFeedResponse;
12use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedGeneratorResponse;
13use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedGeneratorsResponse;
14use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedResponse;
15use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetLikesResponse;
16use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetPostsResponse;
17use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetPostThreadResponse;
18use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetQuotesResponse;
19use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetRepostedByResponse;
20use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetSuggestedFeedsResponse;
21use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetTimelineResponse;
22use SocialDept\AtpClient\Data\Responses\Bsky\Feed\SearchPostsResponse;
23use SocialDept\AtpClient\Enums\Nsid\BskyFeed;
24use SocialDept\AtpClient\Enums\Scope;
25
26class FeedRequestClient extends Request
27{
28 /**
29 * Describe feed generator
30 *
31 * @see https://docs.bsky.app/docs/api/app-bsky-feed-describe-feed-generator
32 */
33 #[PublicEndpoint]
34 public function describeFeedGenerator(): DescribeFeedGeneratorResponse
35 {
36 $response = $this->atp->client->get(
37 endpoint: BskyFeed::DescribeFeedGenerator
38 );
39
40 return DescribeFeedGeneratorResponse::fromArray($response->json());
41 }
42
43 /**
44 * Get timeline feed (requires authentication)
45 *
46 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-timeline
47 */
48 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:app.bsky.feed.getTimeline')]
49 public function getTimeline(int $limit = 50, ?string $cursor = null): GetTimelineResponse
50 {
51 $response = $this->atp->client->get(
52 endpoint: BskyFeed::GetTimeline,
53 params: compact('limit', 'cursor')
54 );
55
56 return GetTimelineResponse::fromArray($response->json());
57 }
58
59 /**
60 * Get author feed
61 *
62 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-author-feed
63 */
64 #[PublicEndpoint]
65 public function getAuthorFeed(
66 string $actor,
67 int $limit = 50,
68 ?string $cursor = null,
69 ?string $filter = null
70 ): GetAuthorFeedResponse {
71 $response = $this->atp->client->get(
72 endpoint: BskyFeed::GetAuthorFeed,
73 params: compact('actor', 'limit', 'cursor', 'filter')
74 );
75
76 return GetAuthorFeedResponse::fromArray($response->json());
77 }
78
79 /**
80 * Get feeds created by an actor
81 *
82 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-actor-feeds
83 */
84 #[PublicEndpoint]
85 public function getActorFeeds(string $actor, int $limit = 50, ?string $cursor = null): GetActorFeedsResponse
86 {
87 $response = $this->atp->client->get(
88 endpoint: BskyFeed::GetActorFeeds,
89 params: compact('actor', 'limit', 'cursor')
90 );
91
92 return GetActorFeedsResponse::fromArray($response->json());
93 }
94
95 /**
96 * Get posts liked by an actor
97 *
98 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-actor-likes
99 */
100 #[PublicEndpoint]
101 public function getActorLikes(string $actor, int $limit = 50, ?string $cursor = null): GetActorLikesResponse
102 {
103 $response = $this->atp->client->get(
104 endpoint: BskyFeed::GetActorLikes,
105 params: compact('actor', 'limit', 'cursor')
106 );
107
108 return GetActorLikesResponse::fromArray($response->json());
109 }
110
111 /**
112 * Get a feed
113 *
114 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed
115 */
116 #[PublicEndpoint]
117 public function getFeed(string $feed, int $limit = 50, ?string $cursor = null): GetFeedResponse
118 {
119 $response = $this->atp->client->get(
120 endpoint: BskyFeed::GetFeed,
121 params: compact('feed', 'limit', 'cursor')
122 );
123
124 return GetFeedResponse::fromArray($response->json());
125 }
126
127 /**
128 * Get a feed generator
129 *
130 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed-generator
131 */
132 #[PublicEndpoint]
133 public function getFeedGenerator(string $feed): GetFeedGeneratorResponse
134 {
135 $response = $this->atp->client->get(
136 endpoint: BskyFeed::GetFeedGenerator,
137 params: compact('feed')
138 );
139
140 return GetFeedGeneratorResponse::fromArray($response->json());
141 }
142
143 /**
144 * Get multiple feed generators
145 *
146 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-feed-generators
147 */
148 #[PublicEndpoint]
149 public function getFeedGenerators(array $feeds): GetFeedGeneratorsResponse
150 {
151 $response = $this->atp->client->get(
152 endpoint: BskyFeed::GetFeedGenerators,
153 params: compact('feeds')
154 );
155
156 return GetFeedGeneratorsResponse::fromArray($response->json());
157 }
158
159 /**
160 * Get post thread
161 *
162 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-post-thread
163 */
164 #[PublicEndpoint]
165 public function getPostThread(string $uri, int $depth = 6, int $parentHeight = 80): GetPostThreadResponse
166 {
167 $response = $this->atp->client->get(
168 endpoint: BskyFeed::GetPostThread,
169 params: compact('uri', 'depth', 'parentHeight')
170 );
171
172 return GetPostThreadResponse::fromArray($response->json());
173 }
174
175 /**
176 * Get multiple posts by URI
177 *
178 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-posts
179 */
180 #[PublicEndpoint]
181 public function getPosts(array $uris): GetPostsResponse
182 {
183 $response = $this->atp->client->get(
184 endpoint: BskyFeed::GetPosts,
185 params: compact('uris')
186 );
187
188 return GetPostsResponse::fromArray($response->json());
189 }
190
191 /**
192 * Get likes for a post
193 *
194 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-likes
195 */
196 #[PublicEndpoint]
197 public function getLikes(
198 string $uri,
199 int $limit = 50,
200 ?string $cursor = null,
201 ?string $cid = null
202 ): GetLikesResponse {
203 $response = $this->atp->client->get(
204 endpoint: BskyFeed::GetLikes,
205 params: compact('uri', 'limit', 'cursor', 'cid')
206 );
207
208 return GetLikesResponse::fromArray($response->json());
209 }
210
211 /**
212 * Get quotes of a post
213 *
214 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-quotes
215 */
216 #[PublicEndpoint]
217 public function getQuotes(
218 string $uri,
219 int $limit = 50,
220 ?string $cursor = null,
221 ?string $cid = null
222 ): GetQuotesResponse {
223 $response = $this->atp->client->get(
224 endpoint: BskyFeed::GetQuotes,
225 params: compact('uri', 'limit', 'cursor', 'cid')
226 );
227
228 return GetQuotesResponse::fromArray($response->json());
229 }
230
231 /**
232 * Get reposts for a post
233 *
234 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-reposted-by
235 */
236 #[PublicEndpoint]
237 public function getRepostedBy(
238 string $uri,
239 int $limit = 50,
240 ?string $cursor = null,
241 ?string $cid = null
242 ): GetRepostedByResponse {
243 $response = $this->atp->client->get(
244 endpoint: BskyFeed::GetRepostedBy,
245 params: compact('uri', 'limit', 'cursor', 'cid')
246 );
247
248 return GetRepostedByResponse::fromArray($response->json());
249 }
250
251 /**
252 * Get suggested feeds
253 *
254 * @see https://docs.bsky.app/docs/api/app-bsky-feed-get-suggested-feeds
255 */
256 #[PublicEndpoint]
257 public function getSuggestedFeeds(int $limit = 50, ?string $cursor = null): GetSuggestedFeedsResponse
258 {
259 $response = $this->atp->client->get(
260 endpoint: BskyFeed::GetSuggestedFeeds,
261 params: compact('limit', 'cursor')
262 );
263
264 return GetSuggestedFeedsResponse::fromArray($response->json());
265 }
266
267 /**
268 * Search posts
269 *
270 * @see https://docs.bsky.app/docs/api/app-bsky-feed-search-posts
271 */
272 #[PublicEndpoint]
273 public function searchPosts(
274 string $q,
275 int $limit = 25,
276 ?string $cursor = null,
277 ?string $sort = null
278 ): SearchPostsResponse {
279 $response = $this->atp->client->get(
280 endpoint: BskyFeed::SearchPosts,
281 params: compact('q', 'limit', 'cursor', 'sort')
282 );
283
284 return SearchPostsResponse::fromArray($response->json());
285 }
286}