-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPublicClient.php
More file actions
212 lines (180 loc) · 6.95 KB
/
PublicClient.php
File metadata and controls
212 lines (180 loc) · 6.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<?php
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Revolution\AtProto\Lexicon\Attributes\Format;
use Revolution\AtProto\Lexicon\Attributes\Get;
use Revolution\AtProto\Lexicon\Attributes\KnownValues;
use Revolution\AtProto\Lexicon\Attributes\NSID;
use Revolution\AtProto\Lexicon\Attributes\Post;
use Revolution\AtProto\Lexicon\Attributes\Ref;
use Revolution\AtProto\Lexicon\Contracts\App\Bsky\Actor;
use Revolution\AtProto\Lexicon\Contracts\App\Bsky\Feed;
/**
* A client that does not require authentication and only uses public APIs.
*
* ```
* $client = new PublicClient();
*
* $posts = $client->searchPosts(q: '#bleusky', tag: ['bluesky'], limit: 10);
* ```
*/
class PublicClient implements Actor, Feed
{
protected const PUBLIC_ENDPOINT = 'https://public.api.bsky.app/xrpc/';
protected Client $client;
protected function client(): Client
{
return $this->client ?? new Client([
'base_uri' => self::PUBLIC_ENDPOINT,
'timeout' => 30,
]);
}
protected function get(string $xrpc, array $query = []): array
{
$response = $this->client()->get($xrpc, [
RequestOptions::QUERY => $query,
]);
return json_decode($response->getBody()->getContents(), true);
}
public function getProfile(#[Format('at-identifier')] string $actor): array
{
return $this->get(self::getProfile, compact('actor'));
}
public function getAuthorFeed(#[Format('at-identifier')] string $actor, ?int $limit = 50, ?string $cursor = null, #[KnownValues(['posts_with_replies', 'posts_no_replies', 'posts_with_media', 'posts_and_author_threads'])] ?string $filter = 'posts_with_replies', ?bool $includePins = null): array
{
return $this->get(
self::getAuthorFeed,
compact('actor', 'limit', 'cursor', 'filter', 'includePins'),
);
}
public function searchPosts(string $q, #[KnownValues(['top', 'latest'])] ?string $sort = 'latest', ?string $since = null, ?string $until = null, #[Format('at-identifier')] ?string $mentions = null, #[Format('at-identifier')] ?string $author = null, #[Format('language')] ?string $lang = null, ?string $domain = null, #[Format('uri')] ?string $url = null, ?array $tag = null, ?int $limit = 25, ?string $cursor = null): array
{
return $this->get(
self::searchPosts,
compact(
'q',
'sort',
'since',
'until',
'mentions',
'author',
'lang',
'domain',
'url',
'tag',
'limit',
'cursor',
),
);
}
// Methods that you do not use can be left unimplemented.
#[Get, NSID(self::getPreferences)]
public function getPreferences()
{
// TODO: Implement getPreferences() method.
}
#[Get, NSID(self::getProfiles)]
public function getProfiles(#[Format('at-identifier')] array $actors)
{
// TODO: Implement getProfiles() method.
}
#[Get, NSID(self::getSuggestions)]
public function getSuggestions(?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getSuggestions() method.
}
#[Post, NSID(self::putPreferences)]
public function putPreferences(#[Ref('app.bsky.actor.defs#preferences')] array $preferences)
{
// TODO: Implement putPreferences() method.
}
#[Get, NSID(self::searchActors)]
public function searchActors(?string $q = null, ?int $limit = 25, ?string $cursor = null)
{
// TODO: Implement searchActors() method.
}
#[Get, NSID(self::searchActorsTypeahead)]
public function searchActorsTypeahead(?string $q = null, ?int $limit = 10)
{
// TODO: Implement searchActorsTypeahead() method.
}
#[Get, NSID(self::describeFeedGenerator)]
public function describeFeedGenerator()
{
// TODO: Implement describeFeedGenerator() method.
}
public function getActorFeeds(#[Format('at-identifier')] string $actor, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getActorFeeds() method.
}
#[Get, NSID(self::getActorLikes)]
public function getActorLikes(#[Format('at-identifier')] string $actor, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getActorLikes() method.
}
#[Get, NSID(self::getFeed)]
public function getFeed(#[Format('at-uri')] string $feed, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getFeed() method.
}
#[Get, NSID(self::getFeedGenerator)]
public function getFeedGenerator(#[Format('at-uri')] string $feed)
{
// TODO: Implement getFeedGenerator() method.
}
#[Get, NSID(self::getFeedGenerators)]
public function getFeedGenerators(#[Format('at-uri')] array $feeds)
{
// TODO: Implement getFeedGenerators() method.
}
#[Get, NSID(self::getFeedSkeleton)]
public function getFeedSkeleton(#[Format('at-uri')] string $feed, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getFeedSkeleton() method.
}
#[Get, NSID(self::getLikes)]
public function getLikes(#[Format('at-uri')] string $uri, #[Format('cid')] ?string $cid = null, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getLikes() method.
}
#[Get, NSID(self::getListFeed)]
public function getListFeed(#[Format('at-uri')] string $list, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getListFeed() method.
}
#[Get, NSID(self::getPostThread)]
public function getPostThread(#[Format('at-uri')] string $uri, ?int $depth = 6, ?int $parentHeight = 80)
{
// TODO: Implement getPostThread() method.
}
#[Get, NSID(self::getPosts)]
public function getPosts(#[Format('at-uri')] array $uris)
{
// TODO: Implement getPosts() method.
}
#[Get, NSID(self::getQuotes)]
public function getQuotes(#[Format('at-uri')] string $uri, #[Format('cid')] ?string $cid = null, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getQuotes() method.
}
#[Get, NSID(self::getRepostedBy)]
public function getRepostedBy(#[Format('at-uri')] string $uri, #[Format('cid')] ?string $cid = null, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getRepostedBy() method.
}
#[Get, NSID(self::getSuggestedFeeds)]
public function getSuggestedFeeds(?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getSuggestedFeeds() method.
}
#[Get, NSID(self::getTimeline)]
public function getTimeline(?string $algorithm = null, ?int $limit = 50, ?string $cursor = null)
{
// TODO: Implement getTimeline() method.
}
#[Post, NSID(self::sendInteractions)]
public function sendInteractions(#[Ref('app.bsky.feed.defs#interaction')] array $interactions)
{
// TODO: Implement sendInteractions() method.
}
}