Laravel AT Protocol Client (alpha & unstable)

Remove public client hierarchy

-22
src/Client/Public/AtpPublicClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public; 4 - 5 - use SocialDept\AtpClient\Concerns\HasExtensions; 6 - 7 - class AtpPublicClient 8 - { 9 - use HasExtensions; 10 - public PublicClient $client; 11 - public BskyPublicClient $bsky; 12 - public AtprotoPublicClient $atproto; 13 - 14 - public function __construct(string $serviceUrl = null) 15 - { 16 - $serviceUrl = $serviceUrl ?? config('client.public.service_url'); 17 - 18 - $this->client = new PublicClient($serviceUrl); 19 - $this->bsky = new BskyPublicClient($this); 20 - $this->atproto = new AtprotoPublicClient($this); 21 - } 22 - }
···
-38
src/Client/Public/AtprotoPublicClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\Atproto\IdentityPublicRequestClient; 6 - use SocialDept\AtpClient\Client\Public\Requests\Atproto\RepoPublicRequestClient; 7 - use SocialDept\AtpClient\Concerns\HasDomainExtensions; 8 - 9 - class AtprotoPublicClient 10 - { 11 - use HasDomainExtensions; 12 - 13 - protected AtpPublicClient $atp; 14 - public IdentityPublicRequestClient $identity; 15 - public RepoPublicRequestClient $repo; 16 - 17 - public function __construct(AtpPublicClient $parent) 18 - { 19 - $this->atp = $parent; 20 - $this->identity = new IdentityPublicRequestClient($this); 21 - $this->repo = new RepoPublicRequestClient($this); 22 - } 23 - 24 - protected function getDomainName(): string 25 - { 26 - return 'atproto'; 27 - } 28 - 29 - protected function getRootClientClass(): string 30 - { 31 - return AtpPublicClient::class; 32 - } 33 - 34 - public function root(): AtpPublicClient 35 - { 36 - return $this->atp; 37 - } 38 - }
···
-44
src/Client/Public/BskyPublicClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\Bsky\ActorPublicRequestClient; 6 - use SocialDept\AtpClient\Client\Public\Requests\Bsky\FeedPublicRequestClient; 7 - use SocialDept\AtpClient\Client\Public\Requests\Bsky\GraphPublicRequestClient; 8 - use SocialDept\AtpClient\Client\Public\Requests\Bsky\LabelerPublicRequestClient; 9 - use SocialDept\AtpClient\Concerns\HasDomainExtensions; 10 - 11 - class BskyPublicClient 12 - { 13 - use HasDomainExtensions; 14 - 15 - protected AtpPublicClient $atp; 16 - public ActorPublicRequestClient $actor; 17 - public FeedPublicRequestClient $feed; 18 - public GraphPublicRequestClient $graph; 19 - public LabelerPublicRequestClient $labeler; 20 - 21 - public function __construct(AtpPublicClient $parent) 22 - { 23 - $this->atp = $parent; 24 - $this->actor = new ActorPublicRequestClient($this); 25 - $this->feed = new FeedPublicRequestClient($this); 26 - $this->graph = new GraphPublicRequestClient($this); 27 - $this->labeler = new LabelerPublicRequestClient($this); 28 - } 29 - 30 - protected function getDomainName(): string 31 - { 32 - return 'bsky'; 33 - } 34 - 35 - protected function getRootClientClass(): string 36 - { 37 - return AtpPublicClient::class; 38 - } 39 - 40 - public function root(): AtpPublicClient 41 - { 42 - return $this->atp; 43 - } 44 - }
···
-35
src/Client/Public/PublicClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public; 4 - 5 - use BackedEnum; 6 - use Illuminate\Support\Facades\Http; 7 - use SocialDept\AtpClient\Exceptions\AtpResponseException; 8 - use SocialDept\AtpClient\Http\Response; 9 - 10 - class PublicClient 11 - { 12 - public function __construct( 13 - protected string $serviceUrl 14 - ) {} 15 - 16 - public function get(string|BackedEnum $endpoint, array $params = []): Response 17 - { 18 - $endpoint = $endpoint instanceof BackedEnum ? $endpoint->value : $endpoint; 19 - $url = rtrim($this->serviceUrl, '/') . '/xrpc/' . $endpoint; 20 - $params = array_filter($params, fn ($v) => !is_null($v)); 21 - 22 - $response = Http::get($url, $params); 23 - 24 - if ($response->failed() || isset($response->json()['error'])) { 25 - throw AtpResponseException::fromResponse($response, $endpoint); 26 - } 27 - 28 - return new Response($response); 29 - } 30 - 31 - public function serviceUrl(): string 32 - { 33 - return $this->serviceUrl; 34 - } 35 - }
···
-19
src/Client/Public/Requests/Atproto/IdentityPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Atproto; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Enums\Nsid\AtprotoIdentity; 7 - 8 - class IdentityPublicRequestClient extends PublicRequest 9 - { 10 - public function resolveHandle(string $handle): string 11 - { 12 - $response = $this->atp->client->get( 13 - endpoint: AtprotoIdentity::ResolveHandle, 14 - params: compact('handle') 15 - ); 16 - 17 - return $response->json()['did']; 18 - } 19 - }
···
-69
src/Client/Public/Requests/Atproto/RepoPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Atproto; 4 - 5 - use BackedEnum; 6 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 7 - use SocialDept\AtpClient\Data\Responses\Atproto\Repo\DescribeRepoResponse; 8 - use SocialDept\AtpClient\Data\Responses\Atproto\Repo\GetRecordResponse; 9 - use SocialDept\AtpClient\Data\Responses\Atproto\Repo\ListRecordsResponse; 10 - use SocialDept\AtpClient\Enums\Nsid\AtprotoRepo; 11 - 12 - class RepoPublicRequestClient extends PublicRequest 13 - { 14 - /** 15 - * Get a record 16 - * 17 - * @see https://docs.bsky.app/docs/api/com-atproto-repo-get-record 18 - */ 19 - public function getRecord( 20 - string $repo, 21 - string|BackedEnum $collection, 22 - string $rkey, 23 - ?string $cid = null 24 - ): GetRecordResponse { 25 - $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 26 - $response = $this->atp->client->get( 27 - endpoint: AtprotoRepo::GetRecord, 28 - params: compact('repo', 'collection', 'rkey', 'cid') 29 - ); 30 - 31 - return GetRecordResponse::fromArray($response->json()); 32 - } 33 - 34 - /** 35 - * List records in a collection 36 - * 37 - * @see https://docs.bsky.app/docs/api/com-atproto-repo-list-records 38 - */ 39 - public function listRecords( 40 - string $repo, 41 - string|BackedEnum $collection, 42 - int $limit = 50, 43 - ?string $cursor = null, 44 - bool $reverse = false 45 - ): ListRecordsResponse { 46 - $collection = $collection instanceof BackedEnum ? $collection->value : $collection; 47 - $response = $this->atp->client->get( 48 - endpoint: AtprotoRepo::ListRecords, 49 - params: compact('repo', 'collection', 'limit', 'cursor', 'reverse') 50 - ); 51 - 52 - return ListRecordsResponse::fromArray($response->json()); 53 - } 54 - 55 - /** 56 - * Describe the repository 57 - * 58 - * @see https://docs.bsky.app/docs/api/com-atproto-repo-describe-repo 59 - */ 60 - public function describeRepo(string $repo): DescribeRepoResponse 61 - { 62 - $response = $this->atp->client->get( 63 - endpoint: AtprotoRepo::DescribeRepo, 64 - params: compact('repo') 65 - ); 66 - 67 - return DescribeRepoResponse::fromArray($response->json()); 68 - } 69 - }
···
-64
src/Client/Public/Requests/Bsky/ActorPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Bsky; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Enums\Nsid\BskyActor; 7 - use SocialDept\AtpClient\Data\Responses\Bsky\Actor\GetProfilesResponse; 8 - use SocialDept\AtpClient\Data\Responses\Bsky\Actor\GetSuggestionsResponse; 9 - use SocialDept\AtpClient\Data\Responses\Bsky\Actor\SearchActorsResponse; 10 - use SocialDept\AtpClient\Data\Responses\Bsky\Actor\SearchActorsTypeaheadResponse; 11 - use SocialDept\AtpSchema\Generated\App\Bsky\Actor\Defs\ProfileViewDetailed; 12 - 13 - class ActorPublicRequestClient extends PublicRequest 14 - { 15 - public function getProfile(string $actor): ProfileViewDetailed 16 - { 17 - $response = $this->atp->client->get( 18 - endpoint: BskyActor::GetProfile, 19 - params: compact('actor') 20 - ); 21 - 22 - return ProfileViewDetailed::fromArray($response->json()); 23 - } 24 - 25 - public function getProfiles(array $actors): GetProfilesResponse 26 - { 27 - $response = $this->atp->client->get( 28 - endpoint: BskyActor::GetProfiles, 29 - params: compact('actors') 30 - ); 31 - 32 - return GetProfilesResponse::fromArray($response->json()); 33 - } 34 - 35 - public function getSuggestions(int $limit = 50, ?string $cursor = null): GetSuggestionsResponse 36 - { 37 - $response = $this->atp->client->get( 38 - endpoint: BskyActor::GetSuggestions, 39 - params: compact('limit', 'cursor') 40 - ); 41 - 42 - return GetSuggestionsResponse::fromArray($response->json()); 43 - } 44 - 45 - public function searchActors(string $q, int $limit = 25, ?string $cursor = null): SearchActorsResponse 46 - { 47 - $response = $this->atp->client->get( 48 - endpoint: BskyActor::SearchActors, 49 - params: compact('q', 'limit', 'cursor') 50 - ); 51 - 52 - return SearchActorsResponse::fromArray($response->json()); 53 - } 54 - 55 - public function searchActorsTypeahead(string $q, int $limit = 10): SearchActorsTypeaheadResponse 56 - { 57 - $response = $this->atp->client->get( 58 - endpoint: BskyActor::SearchActorsTypeahead, 59 - params: compact('q', 'limit') 60 - ); 61 - 62 - return SearchActorsTypeaheadResponse::fromArray($response->json()); 63 - } 64 - }
···
-162
src/Client/Public/Requests/Bsky/FeedPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Bsky; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Enums\Nsid\BskyFeed; 7 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\DescribeFeedGeneratorResponse; 8 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetActorFeedsResponse; 9 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetActorLikesResponse; 10 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetAuthorFeedResponse; 11 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedGeneratorResponse; 12 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedGeneratorsResponse; 13 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetFeedResponse; 14 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetLikesResponse; 15 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetPostsResponse; 16 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetPostThreadResponse; 17 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetQuotesResponse; 18 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetRepostedByResponse; 19 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\GetSuggestedFeedsResponse; 20 - use SocialDept\AtpClient\Data\Responses\Bsky\Feed\SearchPostsResponse; 21 - 22 - class FeedPublicRequestClient extends PublicRequest 23 - { 24 - public function describeFeedGenerator(): DescribeFeedGeneratorResponse 25 - { 26 - $response = $this->atp->client->get( 27 - endpoint: BskyFeed::DescribeFeedGenerator 28 - ); 29 - 30 - return DescribeFeedGeneratorResponse::fromArray($response->json()); 31 - } 32 - 33 - public function getAuthorFeed(string $actor, int $limit = 50, ?string $cursor = null, ?string $filter = null): GetAuthorFeedResponse 34 - { 35 - $response = $this->atp->client->get( 36 - endpoint: BskyFeed::GetAuthorFeed, 37 - params: compact('actor', 'limit', 'cursor', 'filter') 38 - ); 39 - 40 - return GetAuthorFeedResponse::fromArray($response->json()); 41 - } 42 - 43 - public function getActorFeeds(string $actor, int $limit = 50, ?string $cursor = null): GetActorFeedsResponse 44 - { 45 - $response = $this->atp->client->get( 46 - endpoint: BskyFeed::GetActorFeeds, 47 - params: compact('actor', 'limit', 'cursor') 48 - ); 49 - 50 - return GetActorFeedsResponse::fromArray($response->json()); 51 - } 52 - 53 - public function getActorLikes(string $actor, int $limit = 50, ?string $cursor = null): GetActorLikesResponse 54 - { 55 - $response = $this->atp->client->get( 56 - endpoint: BskyFeed::GetActorLikes, 57 - params: compact('actor', 'limit', 'cursor') 58 - ); 59 - 60 - return GetActorLikesResponse::fromArray($response->json()); 61 - } 62 - 63 - public function getFeed(string $feed, int $limit = 50, ?string $cursor = null): GetFeedResponse 64 - { 65 - $response = $this->atp->client->get( 66 - endpoint: BskyFeed::GetFeed, 67 - params: compact('feed', 'limit', 'cursor') 68 - ); 69 - 70 - return GetFeedResponse::fromArray($response->json()); 71 - } 72 - 73 - public function getFeedGenerator(string $feed): GetFeedGeneratorResponse 74 - { 75 - $response = $this->atp->client->get( 76 - endpoint: BskyFeed::GetFeedGenerator, 77 - params: compact('feed') 78 - ); 79 - 80 - return GetFeedGeneratorResponse::fromArray($response->json()); 81 - } 82 - 83 - public function getFeedGenerators(array $feeds): GetFeedGeneratorsResponse 84 - { 85 - $response = $this->atp->client->get( 86 - endpoint: BskyFeed::GetFeedGenerators, 87 - params: compact('feeds') 88 - ); 89 - 90 - return GetFeedGeneratorsResponse::fromArray($response->json()); 91 - } 92 - 93 - public function getLikes(string $uri, int $limit = 50, ?string $cursor = null, ?string $cid = null): GetLikesResponse 94 - { 95 - $response = $this->atp->client->get( 96 - endpoint: BskyFeed::GetLikes, 97 - params: compact('uri', 'limit', 'cursor', 'cid') 98 - ); 99 - 100 - return GetLikesResponse::fromArray($response->json()); 101 - } 102 - 103 - public function getPostThread(string $uri, int $depth = 6, int $parentHeight = 80): GetPostThreadResponse 104 - { 105 - $response = $this->atp->client->get( 106 - endpoint: BskyFeed::GetPostThread, 107 - params: compact('uri', 'depth', 'parentHeight') 108 - ); 109 - 110 - return GetPostThreadResponse::fromArray($response->json()); 111 - } 112 - 113 - public function getPosts(array $uris): GetPostsResponse 114 - { 115 - $response = $this->atp->client->get( 116 - endpoint: BskyFeed::GetPosts, 117 - params: compact('uris') 118 - ); 119 - 120 - return GetPostsResponse::fromArray($response->json()); 121 - } 122 - 123 - public function getQuotes(string $uri, int $limit = 50, ?string $cursor = null, ?string $cid = null): GetQuotesResponse 124 - { 125 - $response = $this->atp->client->get( 126 - endpoint: BskyFeed::GetQuotes, 127 - params: compact('uri', 'limit', 'cursor', 'cid') 128 - ); 129 - 130 - return GetQuotesResponse::fromArray($response->json()); 131 - } 132 - 133 - public function getRepostedBy(string $uri, int $limit = 50, ?string $cursor = null, ?string $cid = null): GetRepostedByResponse 134 - { 135 - $response = $this->atp->client->get( 136 - endpoint: BskyFeed::GetRepostedBy, 137 - params: compact('uri', 'limit', 'cursor', 'cid') 138 - ); 139 - 140 - return GetRepostedByResponse::fromArray($response->json()); 141 - } 142 - 143 - public function getSuggestedFeeds(int $limit = 50, ?string $cursor = null): GetSuggestedFeedsResponse 144 - { 145 - $response = $this->atp->client->get( 146 - endpoint: BskyFeed::GetSuggestedFeeds, 147 - params: compact('limit', 'cursor') 148 - ); 149 - 150 - return GetSuggestedFeedsResponse::fromArray($response->json()); 151 - } 152 - 153 - public function searchPosts(string $q, int $limit = 25, ?string $cursor = null, ?string $sort = null): SearchPostsResponse 154 - { 155 - $response = $this->atp->client->get( 156 - endpoint: BskyFeed::SearchPosts, 157 - params: compact('q', 'limit', 'cursor', 'sort') 158 - ); 159 - 160 - return SearchPostsResponse::fromArray($response->json()); 161 - } 162 - }
···
-108
src/Client/Public/Requests/Bsky/GraphPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Bsky; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Enums\Nsid\BskyGraph; 7 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowersResponse; 8 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetFollowsResponse; 9 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetKnownFollowersResponse; 10 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetListResponse; 11 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetListsResponse; 12 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetRelationshipsResponse; 13 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetStarterPacksResponse; 14 - use SocialDept\AtpClient\Data\Responses\Bsky\Graph\GetSuggestedFollowsByActorResponse; 15 - use SocialDept\AtpSchema\Generated\App\Bsky\Graph\Defs\StarterPackView; 16 - 17 - class GraphPublicRequestClient extends PublicRequest 18 - { 19 - public function getFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetFollowersResponse 20 - { 21 - $response = $this->atp->client->get( 22 - endpoint: BskyGraph::GetFollowers, 23 - params: compact('actor', 'limit', 'cursor') 24 - ); 25 - 26 - return GetFollowersResponse::fromArray($response->json()); 27 - } 28 - 29 - public function getFollows(string $actor, int $limit = 50, ?string $cursor = null): GetFollowsResponse 30 - { 31 - $response = $this->atp->client->get( 32 - endpoint: BskyGraph::GetFollows, 33 - params: compact('actor', 'limit', 'cursor') 34 - ); 35 - 36 - return GetFollowsResponse::fromArray($response->json()); 37 - } 38 - 39 - public function getKnownFollowers(string $actor, int $limit = 50, ?string $cursor = null): GetKnownFollowersResponse 40 - { 41 - $response = $this->atp->client->get( 42 - endpoint: BskyGraph::GetKnownFollowers, 43 - params: compact('actor', 'limit', 'cursor') 44 - ); 45 - 46 - return GetKnownFollowersResponse::fromArray($response->json()); 47 - } 48 - 49 - public function getList(string $list, int $limit = 50, ?string $cursor = null): GetListResponse 50 - { 51 - $response = $this->atp->client->get( 52 - endpoint: BskyGraph::GetList, 53 - params: compact('list', 'limit', 'cursor') 54 - ); 55 - 56 - return GetListResponse::fromArray($response->json()); 57 - } 58 - 59 - public function getLists(string $actor, int $limit = 50, ?string $cursor = null): GetListsResponse 60 - { 61 - $response = $this->atp->client->get( 62 - endpoint: BskyGraph::GetLists, 63 - params: compact('actor', 'limit', 'cursor') 64 - ); 65 - 66 - return GetListsResponse::fromArray($response->json()); 67 - } 68 - 69 - public function getRelationships(string $actor, array $others = []): GetRelationshipsResponse 70 - { 71 - $response = $this->atp->client->get( 72 - endpoint: BskyGraph::GetRelationships, 73 - params: compact('actor', 'others') 74 - ); 75 - 76 - return GetRelationshipsResponse::fromArray($response->json()); 77 - } 78 - 79 - public function getStarterPack(string $starterPack): StarterPackView 80 - { 81 - $response = $this->atp->client->get( 82 - endpoint: BskyGraph::GetStarterPack, 83 - params: compact('starterPack') 84 - ); 85 - 86 - return StarterPackView::fromArray($response->json()['starterPack']); 87 - } 88 - 89 - public function getStarterPacks(array $uris): GetStarterPacksResponse 90 - { 91 - $response = $this->atp->client->get( 92 - endpoint: BskyGraph::GetStarterPacks, 93 - params: compact('uris') 94 - ); 95 - 96 - return GetStarterPacksResponse::fromArray($response->json()); 97 - } 98 - 99 - public function getSuggestedFollowsByActor(string $actor): GetSuggestedFollowsByActorResponse 100 - { 101 - $response = $this->atp->client->get( 102 - endpoint: BskyGraph::GetSuggestedFollowsByActor, 103 - params: compact('actor') 104 - ); 105 - 106 - return GetSuggestedFollowsByActorResponse::fromArray($response->json()); 107 - } 108 - }
···
-20
src/Client/Public/Requests/Bsky/LabelerPublicRequestClient.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests\Bsky; 4 - 5 - use SocialDept\AtpClient\Client\Public\Requests\PublicRequest; 6 - use SocialDept\AtpClient\Data\Responses\Bsky\Labeler\GetServicesResponse; 7 - use SocialDept\AtpClient\Enums\Nsid\BskyLabeler; 8 - 9 - class LabelerPublicRequestClient extends PublicRequest 10 - { 11 - public function getServices(array $dids, bool $detailed = false): GetServicesResponse 12 - { 13 - $response = $this->atp->client->get( 14 - endpoint: BskyLabeler::GetServices, 15 - params: compact('dids', 'detailed') 16 - ); 17 - 18 - return GetServicesResponse::fromArray($response->json(), $detailed); 19 - } 20 - }
···
-15
src/Client/Public/Requests/PublicRequest.php
··· 1 - <?php 2 - 3 - namespace SocialDept\AtpClient\Client\Public\Requests; 4 - 5 - use SocialDept\AtpClient\Client\Public\AtpPublicClient; 6 - 7 - class PublicRequest 8 - { 9 - protected AtpPublicClient $atp; 10 - 11 - public function __construct($parent) 12 - { 13 - $this->atp = $parent->root(); 14 - } 15 - }
···