Laravel AT Protocol Client (alpha & unstable)

Refactor FollowRecordClient to use RepoRequestClient with scope attributes

Changed files
+26 -22
src
Client
+26 -22
src/Client/Records/FollowRecordClient.php
··· 3 3 namespace SocialDept\AtpClient\Client\Records; 4 4 5 5 use DateTimeInterface; 6 + use SocialDept\AtpClient\Attributes\RequiresScope; 6 7 use SocialDept\AtpClient\Client\Requests\Request; 7 8 use SocialDept\AtpClient\Data\StrongRef; 9 + use SocialDept\AtpClient\Enums\Scope; 8 10 9 11 class FollowRecordClient extends Request 10 12 { 11 13 /** 12 14 * Follow a user 15 + * 16 + * @requires transition:generic OR (rpc:com.atproto.repo.createRecord AND repo:app.bsky.graph.follow?action=create) 13 17 */ 18 + #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.createRecord')] 19 + #[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=create')] 14 20 public function create( 15 21 string $subject, 16 22 ?DateTimeInterface $createdAt = null ··· 21 27 'createdAt' => ($createdAt ?? now())->format('c'), 22 28 ]; 23 29 24 - $response = $this->atp->client->post( 25 - endpoint: 'com.atproto.repo.createRecord', 26 - body: [ 27 - 'repo' => $this->atp->client->sessions->session($this->atp->client->identifier)->did(), 28 - 'collection' => 'app.bsky.graph.follow', 29 - 'record' => $record, 30 - ] 30 + $response = $this->atp->atproto->repo->createRecord( 31 + repo: $this->atp->client->session()->did(), 32 + collection: 'app.bsky.graph.follow', 33 + record: $record 31 34 ); 32 35 33 36 return StrongRef::fromResponse($response->json()); ··· 35 38 36 39 /** 37 40 * Unfollow a user (delete follow record) 41 + * 42 + * @requires transition:generic OR (rpc:com.atproto.repo.deleteRecord AND repo:app.bsky.graph.follow?action=delete) 38 43 */ 44 + #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.deleteRecord')] 45 + #[RequiresScope(Scope::TransitionGeneric, granular: 'repo:app.bsky.graph.follow?action=delete')] 39 46 public function delete(string $rkey): void 40 47 { 41 - $this->atp->client->post( 42 - endpoint: 'com.atproto.repo.deleteRecord', 43 - body: [ 44 - 'repo' => $this->atp->client->sessions->session($this->atp->client->identifier)->did(), 45 - 'collection' => 'app.bsky.graph.follow', 46 - 'rkey' => $rkey, 47 - ] 48 + $this->atp->atproto->repo->deleteRecord( 49 + repo: $this->atp->client->session()->did(), 50 + collection: 'app.bsky.graph.follow', 51 + rkey: $rkey 48 52 ); 49 53 } 50 54 51 55 /** 52 56 * Get a follow record 57 + * 58 + * @requires transition:generic (rpc:com.atproto.repo.getRecord) 53 59 */ 60 + #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.getRecord')] 54 61 public function get(string $rkey, ?string $cid = null): array 55 62 { 56 - $response = $this->atp->client->get( 57 - endpoint: 'com.atproto.repo.getRecord', 58 - params: array_filter([ 59 - 'repo' => $this->atp->client->sessions->session($this->atp->client->identifier)->did(), 60 - 'collection' => 'app.bsky.graph.follow', 61 - 'rkey' => $rkey, 62 - 'cid' => $cid, 63 - ]) 63 + $response = $this->atp->atproto->repo->getRecord( 64 + repo: $this->atp->client->session()->did(), 65 + collection: 'app.bsky.graph.follow', 66 + rkey: $rkey, 67 + cid: $cid 64 68 ); 65 69 66 70 return $response->json('value');