Laravel AT Protocol Client (alpha & unstable)
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update Atproto clients to return typed responses

+75 -36
+4 -3
src/Client/Public/Requests/Atproto/IdentityPublicRequestClient.php
··· 3 3 namespace SocialDept\AtpClient\Client\Public\Requests\Atproto; 4 4 5 5 use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Http\Response; 7 6 8 7 class IdentityPublicRequestClient extends PublicRequest 9 8 { 10 - public function resolveHandle(string $handle): Response 9 + public function resolveHandle(string $handle): string 11 10 { 12 - return $this->atp->client->get('com.atproto.identity.resolveHandle', compact('handle')); 11 + $response = $this->atp->client->get('com.atproto.identity.resolveHandle', compact('handle')); 12 + 13 + return $response->json()['did']; 13 14 } 14 15 }
+6 -5
src/Client/Requests/Atproto/IdentityRequestClient.php
··· 5 5 use SocialDept\AtpClient\Attributes\RequiresScope; 6 6 use SocialDept\AtpClient\Client\Requests\Request; 7 7 use SocialDept\AtpClient\Enums\Scope; 8 - use SocialDept\AtpClient\Http\Response; 9 8 10 9 class IdentityRequestClient extends Request 11 10 { ··· 17 16 * @see https://docs.bsky.app/docs/api/com-atproto-identity-resolve-handle 18 17 */ 19 18 #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.identity.resolveHandle')] 20 - public function resolveHandle(string $handle): Response 19 + public function resolveHandle(string $handle): string 21 20 { 22 - return $this->atp->client->get( 21 + $response = $this->atp->client->get( 23 22 endpoint: 'com.atproto.identity.resolveHandle', 24 23 params: compact('handle') 25 24 ); 25 + 26 + return $response->json()['did']; 26 27 } 27 28 28 29 /** ··· 33 34 * @see https://docs.bsky.app/docs/api/com-atproto-identity-update-handle 34 35 */ 35 36 #[RequiresScope(Scope::Atproto, granular: 'identity:handle')] 36 - public function updateHandle(string $handle): Response 37 + public function updateHandle(string $handle): void 37 38 { 38 - return $this->atp->client->post( 39 + $this->atp->client->post( 39 40 endpoint: 'com.atproto.identity.updateHandle', 40 41 body: compact('handle') 41 42 );
+35 -15
src/Client/Requests/Atproto/RepoRequestClient.php
··· 7 7 use SocialDept\AtpClient\Attributes\RequiresScope; 8 8 use SocialDept\AtpClient\Auth\ScopeChecker; 9 9 use SocialDept\AtpClient\Client\Requests\Request; 10 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\CreateRecordResponse; 11 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DeleteRecordResponse; 12 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DescribeRepoResponse; 13 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\GetRecordResponse; 14 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\ListRecordsResponse; 15 + use SocialDept\AtpClient\Data\Responses\Atproto\Repo\PutRecordResponse; 10 16 use SocialDept\AtpClient\Enums\Scope; 11 - use SocialDept\AtpClient\Http\Response; 17 + use SocialDept\AtpSchema\Data\BlobReference; 12 18 use SplFileInfo; 13 19 use Throwable; 14 20 ··· 29 35 ?string $rkey = null, 30 36 bool $validate = true, 31 37 ?string $swapCommit = null 32 - ): Response { 38 + ): CreateRecordResponse { 33 39 $this->checkCollectionScope($collection, 'create'); 34 40 35 - return $this->atp->client->post( 41 + $response = $this->atp->client->post( 36 42 endpoint: 'com.atproto.repo.createRecord', 37 43 body: array_filter( 38 44 compact('repo', 'collection', 'record', 'rkey', 'validate', 'swapCommit'), 39 45 fn ($v) => ! is_null($v) 40 46 ) 41 47 ); 48 + 49 + return CreateRecordResponse::fromArray($response->json()); 42 50 } 43 51 44 52 /** ··· 55 63 string $rkey, 56 64 ?string $swapRecord = null, 57 65 ?string $swapCommit = null 58 - ): Response { 66 + ): DeleteRecordResponse { 59 67 $this->checkCollectionScope($collection, 'delete'); 60 68 61 - return $this->atp->client->post( 69 + $response = $this->atp->client->post( 62 70 endpoint: 'com.atproto.repo.deleteRecord', 63 71 body: array_filter( 64 72 compact('repo', 'collection', 'rkey', 'swapRecord', 'swapCommit'), 65 73 fn ($v) => ! is_null($v) 66 74 ) 67 75 ); 76 + 77 + return DeleteRecordResponse::fromArray($response->json()); 68 78 } 69 79 70 80 /** ··· 83 93 bool $validate = true, 84 94 ?string $swapRecord = null, 85 95 ?string $swapCommit = null 86 - ): Response { 96 + ): PutRecordResponse { 87 97 $this->checkCollectionScope($collection, 'update'); 88 98 89 - return $this->atp->client->post( 99 + $response = $this->atp->client->post( 90 100 endpoint: 'com.atproto.repo.putRecord', 91 101 body: array_filter( 92 102 compact('repo', 'collection', 'rkey', 'record', 'validate', 'swapRecord', 'swapCommit'), 93 103 fn ($v) => ! is_null($v) 94 104 ) 95 105 ); 106 + 107 + return PutRecordResponse::fromArray($response->json()); 96 108 } 97 109 98 110 /** ··· 108 120 string $collection, 109 121 string $rkey, 110 122 ?string $cid = null 111 - ): Response { 112 - return $this->atp->client->get( 123 + ): GetRecordResponse { 124 + $response = $this->atp->client->get( 113 125 endpoint: 'com.atproto.repo.getRecord', 114 126 params: compact('repo', 'collection', 'rkey', 'cid') 115 127 ); 128 + 129 + return GetRecordResponse::fromArray($response->json()); 116 130 } 117 131 118 132 /** ··· 129 143 int $limit = 50, 130 144 ?string $cursor = null, 131 145 bool $reverse = false 132 - ): Response { 133 - return $this->atp->client->get( 146 + ): ListRecordsResponse { 147 + $response = $this->atp->client->get( 134 148 endpoint: 'com.atproto.repo.listRecords', 135 149 params: compact('repo', 'collection', 'limit', 'cursor', 'reverse') 136 150 ); 151 + 152 + return ListRecordsResponse::fromArray($response->json()); 137 153 } 138 154 139 155 /** ··· 151 167 * @see https://docs.bsky.app/docs/api/com-atproto-repo-upload-blob 152 168 */ 153 169 #[RequiresScope(Scope::TransitionGeneric, granular: 'blob:*/*')] 154 - public function uploadBlob(UploadedFile|SplFileInfo|string $file, ?string $mimeType = null): Response 170 + public function uploadBlob(UploadedFile|SplFileInfo|string $file, ?string $mimeType = null): BlobReference 155 171 { 156 172 // Handle different input types 157 173 if ($file instanceof UploadedFile) { ··· 165 181 $data = $file; 166 182 } 167 183 168 - return $this->atp->client->postBlob( 184 + $response = $this->atp->client->postBlob( 169 185 endpoint: 'com.atproto.repo.uploadBlob', 170 186 data: $data, 171 187 mimeType: $mimeType 172 188 ); 189 + 190 + return BlobReference::fromArray($response->json()['blob']); 173 191 } 174 192 175 193 /** ··· 180 198 * @see https://docs.bsky.app/docs/api/com-atproto-repo-describe-repo 181 199 */ 182 200 #[RequiresScope(Scope::TransitionGeneric, granular: 'rpc:com.atproto.repo.describeRepo')] 183 - public function describeRepo(string $repo): Response 201 + public function describeRepo(string $repo): DescribeRepoResponse 184 202 { 185 - return $this->atp->client->get( 203 + $response = $this->atp->client->get( 186 204 endpoint: 'com.atproto.repo.describeRepo', 187 205 params: compact('repo') 188 206 ); 207 + 208 + return DescribeRepoResponse::fromArray($response->json()); 189 209 } 190 210 191 211 /**
+10 -5
src/Client/Requests/Atproto/ServerRequestClient.php
··· 4 4 5 5 use SocialDept\AtpClient\Attributes\RequiresScope; 6 6 use SocialDept\AtpClient\Client\Requests\Request; 7 + use SocialDept\AtpClient\Data\Responses\Atproto\Server\DescribeServerResponse; 8 + use SocialDept\AtpClient\Data\Responses\Atproto\Server\GetSessionResponse; 7 9 use SocialDept\AtpClient\Enums\Scope; 8 - use SocialDept\AtpClient\Http\Response; 9 10 10 11 class ServerRequestClient extends Request 11 12 { ··· 17 18 * @see https://docs.bsky.app/docs/api/com-atproto-server-get-session 18 19 */ 19 20 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.server.getSession')] 20 - public function getSession(): Response 21 + public function getSession(): GetSessionResponse 21 22 { 22 - return $this->atp->client->get( 23 + $response = $this->atp->client->get( 23 24 endpoint: 'com.atproto.server.getSession' 24 25 ); 26 + 27 + return GetSessionResponse::fromArray($response->json()); 25 28 } 26 29 27 30 /** ··· 32 35 * @see https://docs.bsky.app/docs/api/com-atproto-server-describe-server 33 36 */ 34 37 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.server.describeServer')] 35 - public function describeServer(): Response 38 + public function describeServer(): DescribeServerResponse 36 39 { 37 - return $this->atp->client->get( 40 + $response = $this->atp->client->get( 38 41 endpoint: 'com.atproto.server.describeServer' 39 42 ); 43 + 44 + return DescribeServerResponse::fromArray($response->json()); 40 45 } 41 46 }
+20 -8
src/Client/Requests/Atproto/SyncRequestClient.php
··· 4 4 5 5 use SocialDept\AtpClient\Attributes\RequiresScope; 6 6 use SocialDept\AtpClient\Client\Requests\Request; 7 + use SocialDept\AtpClient\Data\Responses\Atproto\Sync\GetRepoStatusResponse; 8 + use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListBlobsResponse; 9 + use SocialDept\AtpClient\Data\Responses\Atproto\Sync\ListReposResponse; 7 10 use SocialDept\AtpClient\Enums\Scope; 8 11 use SocialDept\AtpClient\Http\Response; 12 + use SocialDept\AtpSchema\Generated\Com\Atproto\Repo\Defs\CommitMeta; 9 13 10 14 class SyncRequestClient extends Request 11 15 { ··· 49 53 * @see https://docs.bsky.app/docs/api/com-atproto-sync-list-repos 50 54 */ 51 55 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.listRepos')] 52 - public function listRepos(int $limit = 500, ?string $cursor = null): Response 56 + public function listRepos(int $limit = 500, ?string $cursor = null): ListReposResponse 53 57 { 54 - return $this->atp->client->get( 58 + $response = $this->atp->client->get( 55 59 endpoint: 'com.atproto.sync.listRepos', 56 60 params: compact('limit', 'cursor') 57 61 ); 62 + 63 + return ListReposResponse::fromArray($response->json()); 58 64 } 59 65 60 66 /** ··· 65 71 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-latest-commit 66 72 */ 67 73 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getLatestCommit')] 68 - public function getLatestCommit(string $did): Response 74 + public function getLatestCommit(string $did): CommitMeta 69 75 { 70 - return $this->atp->client->get( 76 + $response = $this->atp->client->get( 71 77 endpoint: 'com.atproto.sync.getLatestCommit', 72 78 params: compact('did') 73 79 ); 80 + 81 + return CommitMeta::fromArray($response->json()); 74 82 } 75 83 76 84 /** ··· 102 110 ?string $since = null, 103 111 int $limit = 500, 104 112 ?string $cursor = null 105 - ): Response { 106 - return $this->atp->client->get( 113 + ): ListBlobsResponse { 114 + $response = $this->atp->client->get( 107 115 endpoint: 'com.atproto.sync.listBlobs', 108 116 params: compact('did', 'since', 'limit', 'cursor') 109 117 ); 118 + 119 + return ListBlobsResponse::fromArray($response->json()); 110 120 } 111 121 112 122 /** ··· 133 143 * @see https://docs.bsky.app/docs/api/com-atproto-sync-get-repo-status 134 144 */ 135 145 #[RequiresScope(Scope::Atproto, granular: 'rpc:com.atproto.sync.getRepoStatus')] 136 - public function getRepoStatus(string $did): Response 146 + public function getRepoStatus(string $did): GetRepoStatusResponse 137 147 { 138 - return $this->atp->client->get( 148 + $response = $this->atp->client->get( 139 149 endpoint: 'com.atproto.sync.getRepoStatus', 140 150 params: compact('did') 141 151 ); 152 + 153 + return GetRepoStatusResponse::fromArray($response->json()); 142 154 } 143 155 }