Laravel AT Protocol Client (alpha & unstable)
at dev 6.8 kB view raw
1<?php 2 3namespace SocialDept\AtpClient\Client\Requests\Ozone; 4 5use SocialDept\AtpClient\Attributes\ScopedEndpoint; 6use SocialDept\AtpClient\Client\Requests\Request; 7use SocialDept\AtpClient\Data\Responses\Ozone\Moderation\QueryEventsResponse; 8use SocialDept\AtpClient\Data\Responses\Ozone\Moderation\QueryStatusesResponse; 9use SocialDept\AtpClient\Data\Responses\Ozone\Moderation\SearchReposResponse; 10use SocialDept\AtpClient\Enums\Nsid\OzoneModeration; 11use SocialDept\AtpClient\Enums\Scope; 12use SocialDept\AtpClient\Http\Response; 13use SocialDept\AtpSchema\Generated\Tools\Ozone\Moderation\Defs\ModEventView; 14use SocialDept\AtpSchema\Generated\Tools\Ozone\Moderation\Defs\ModEventViewDetail; 15use SocialDept\AtpSchema\Generated\Tools\Ozone\Moderation\Defs\RecordViewDetail; 16use SocialDept\AtpSchema\Generated\Tools\Ozone\Moderation\Defs\RepoViewDetail; 17 18class ModerationRequestClient extends Request 19{ 20 /** 21 * Get moderation event 22 * 23 * @requires transition:generic (rpc:tools.ozone.moderation.getEvent) 24 * 25 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-event 26 */ 27 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvent')] 28 public function getModerationEvent(int $id): ModEventViewDetail 29 { 30 $response = $this->atp->client->get( 31 endpoint: OzoneModeration::GetEvent, 32 params: compact('id') 33 ); 34 35 return ModEventViewDetail::fromArray($response->json()); 36 } 37 38 /** 39 * Get moderation events 40 * 41 * @requires transition:generic (rpc:tools.ozone.moderation.getEvents) 42 * 43 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-events 44 */ 45 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getEvents')] 46 public function getModerationEvents( 47 ?string $subject = null, 48 ?array $types = null, 49 ?string $createdBy = null, 50 int $limit = 50, 51 ?string $cursor = null 52 ): Response { 53 return $this->atp->client->get( 54 endpoint: OzoneModeration::GetEvents, 55 params: array_filter( 56 compact('subject', 'types', 'createdBy', 'limit', 'cursor'), 57 fn ($v) => ! is_null($v) 58 ) 59 ); 60 } 61 62 /** 63 * Get record 64 * 65 * @requires transition:generic (rpc:tools.ozone.moderation.getRecord) 66 * 67 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-record 68 */ 69 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRecord')] 70 public function getRecord(string $uri, ?string $cid = null): RecordViewDetail 71 { 72 $response = $this->atp->client->get( 73 endpoint: OzoneModeration::GetRecord, 74 params: compact('uri', 'cid') 75 ); 76 77 return RecordViewDetail::fromArray($response->json()); 78 } 79 80 /** 81 * Get repo 82 * 83 * @requires transition:generic (rpc:tools.ozone.moderation.getRepo) 84 * 85 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-get-repo 86 */ 87 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.getRepo')] 88 public function getRepo(string $did): RepoViewDetail 89 { 90 $response = $this->atp->client->get( 91 endpoint: OzoneModeration::GetRepo, 92 params: compact('did') 93 ); 94 95 return RepoViewDetail::fromArray($response->json()); 96 } 97 98 /** 99 * Query events 100 * 101 * @requires transition:generic (rpc:tools.ozone.moderation.queryEvents) 102 * 103 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-events 104 */ 105 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryEvents')] 106 public function queryEvents( 107 ?array $types = null, 108 ?string $createdBy = null, 109 ?string $subject = null, 110 int $limit = 50, 111 ?string $cursor = null, 112 bool $sortDirection = false 113 ): QueryEventsResponse { 114 $response = $this->atp->client->get( 115 endpoint: OzoneModeration::QueryEvents, 116 params: array_filter( 117 compact('types', 'createdBy', 'subject', 'limit', 'cursor', 'sortDirection'), 118 fn ($v) => ! is_null($v) 119 ) 120 ); 121 122 return QueryEventsResponse::fromArray($response->json()); 123 } 124 125 /** 126 * Query statuses 127 * 128 * @requires transition:generic (rpc:tools.ozone.moderation.queryStatuses) 129 * 130 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-query-statuses 131 */ 132 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.queryStatuses')] 133 public function queryStatuses( 134 ?string $subject = null, 135 ?array $tags = null, 136 ?string $excludeTags = null, 137 int $limit = 50, 138 ?string $cursor = null 139 ): QueryStatusesResponse { 140 $response = $this->atp->client->get( 141 endpoint: OzoneModeration::QueryStatuses, 142 params: array_filter( 143 compact('subject', 'tags', 'excludeTags', 'limit', 'cursor'), 144 fn ($v) => ! is_null($v) 145 ) 146 ); 147 148 return QueryStatusesResponse::fromArray($response->json()); 149 } 150 151 /** 152 * Search repos 153 * 154 * @requires transition:generic (rpc:tools.ozone.moderation.searchRepos) 155 * 156 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-search-repos 157 */ 158 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.searchRepos')] 159 public function searchRepos( 160 ?string $term = null, 161 ?string $invitedBy = null, 162 int $limit = 50, 163 ?string $cursor = null 164 ): SearchReposResponse { 165 $response = $this->atp->client->get( 166 endpoint: OzoneModeration::SearchRepos, 167 params: array_filter( 168 compact('term', 'invitedBy', 'limit', 'cursor'), 169 fn ($v) => ! is_null($v) 170 ) 171 ); 172 173 return SearchReposResponse::fromArray($response->json()); 174 } 175 176 /** 177 * Emit moderation event 178 * 179 * @requires transition:generic (rpc:tools.ozone.moderation.emitEvent) 180 * 181 * @see https://docs.bsky.app/docs/api/tools-ozone-moderation-emit-event 182 */ 183 #[ScopedEndpoint(Scope::TransitionGeneric, granular: 'rpc:tools.ozone.moderation.emitEvent')] 184 public function emitEvent( 185 array $event, 186 string $subject, 187 array $subjectBlobCids = [], 188 ?string $createdBy = null 189 ): ModEventView { 190 $response = $this->atp->client->post( 191 endpoint: OzoneModeration::EmitEvent, 192 body: compact('event', 'subject', 'subjectBlobCids', 'createdBy') 193 ); 194 195 return ModEventView::fromArray($response->json()); 196 } 197}