Skip to content

Commit

Permalink
Merge branch 'post-builder' into bss-46: PostBuilder API added in com…
Browse files Browse the repository at this point in the history
…pliance with the official post specification..
  • Loading branch information
shahmal1yev committed Oct 13, 2024
2 parents d3b0442 + 7c0d52c commit 47ae425
Show file tree
Hide file tree
Showing 128 changed files with 4,041 additions and 275 deletions.
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,15 @@ fabric.properties
# Build data
/build/

# End of https://www.toptal.com/developers/gitignore/api/phpstorm+all,composer,phpunit
### PHP-CS-Fixer ###
# Covers PHP CS Fixer
# Reference: https://cs.symfony.com/

# Generated files
.php-cs-fixer.cache

# Local config See: https://cs.symfony.com/doc/config.html
.php-cs-fixer.php

# End of https://www.toptal.com/developers/gitignore/api/php-cs-fixer

74 changes: 37 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions src/API/App/Bsky/Actor/GetProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public function __construct()
*/
public function setActor($actor)
{
if (! is_string($actor))
if (! is_string($actor)) {
throw new InvalidArgumentException("'actor' must be a string");
}

$this->body->actor = $actor;
}
Expand Down Expand Up @@ -146,8 +147,9 @@ public function boot($authResponse)
*/
public function getBody()
{
if (! isset($this->body->actor))
if (! isset($this->body->actor)) {
throw new RequestBodyHasMissingRequiredFields('actor');
}

return ['actor' => $this->body->actor];
}
Expand Down
23 changes: 15 additions & 8 deletions src/API/Com/Atrproto/Repo/CreateRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public function __construct()
*/
public function setRepo($repo)
{
if (!is_string($repo))
if (!is_string($repo)) {
throw new InvalidArgumentException("'repo' must be a string");
}

$this->body->repo = $repo;

Expand All @@ -75,11 +76,13 @@ public function getRepo()
*/
public function setRkey($rkey)
{
if (! is_string($rkey))
if (! is_string($rkey)) {
throw new InvalidArgumentException("'key' must be a string");
}

if (strlen($rkey) > 15 || 1 > strlen($rkey))
if (strlen($rkey) > 15 || 1 > strlen($rkey)) {
throw new InvalidArgumentException("'key' length must be between 1 and 15 characters");
}

$this->body->rkey = $rkey;

Expand All @@ -105,8 +108,9 @@ public function getRkey()
*/
public function setValidate($validate)
{
if (! is_bool($validate))
if (! is_bool($validate)) {
throw new InvalidArgumentException("'validate' must be a boolean");
}

$this->body->validate = $validate;

Expand Down Expand Up @@ -163,11 +167,13 @@ public function setCollection($collection)
'app.bsky.graph.follow'
];

if (! is_string($collection))
if (! is_string($collection)) {
throw new InvalidArgumentException("'collection' must be a string");
}

if (! in_array($collection, $acceptableCollections))
if (! in_array($collection, $acceptableCollections)) {
throw new InvalidArgumentException("'collection' must be one of '" . implode("', '", $acceptableCollections) . "'");
}

$this->body->collection = $collection;

Expand Down Expand Up @@ -286,8 +292,9 @@ public function getBody()
array_keys($fields)
);

if (! empty($missingFields))
if (! empty($missingFields)) {
throw new RequestBodyHasMissingRequiredFields(implode(', ', $missingFields));
}

return json_encode($fields);
}
Expand Down Expand Up @@ -315,4 +322,4 @@ public function boot($authResponse)

$this->body->repo = $authResponse->did;
}
}
}
14 changes: 9 additions & 5 deletions src/API/Com/Atrproto/Repo/UploadBlob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Atproto\Contracts\HTTP\RequestContract;
use Atproto\Exceptions\Http\Request\RequestBodyHasMissingRequiredFields;
use Atproto\Helpers\File;
use Atproto\Support\File;
use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource;
use InvalidArgumentException;

Expand Down Expand Up @@ -55,15 +55,18 @@ public function setBlob($filePath)
{
$file = new File($filePath);

if (! $file->exists())
if (! $file->exists()) {
throw new InvalidArgumentException("File '$filePath' does not exist");
}

if (! $file->isFile())
if (! $file->isFile()) {
throw new InvalidArgumentException("File '$filePath' is not a file");
}

$maxSize = 1000000;
if ($file->getFileSize() > $maxSize)
if ($file->getFileSize() > $maxSize) {
throw new InvalidArgumentException("File '$filePath' is too big. Max file size is $maxSize bytes.");
}

$this->body->blob = $file;

Expand All @@ -88,8 +91,9 @@ public function getBlob()
*/
public function getBody()
{
if (! isset($this->body->blob))
if (! isset($this->body->blob)) {
throw new RequestBodyHasMissingRequiredFields(implode(', ', ['blob']));
}

return $this->body
->blob
Expand Down
5 changes: 3 additions & 2 deletions src/Auth/Strategies/PasswordAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Atproto\Contracts\AuthStrategyContract;
use Atproto\Exceptions\Auth\AuthFailed;
use \InvalidArgumentException;
use InvalidArgumentException;

/**
* Class PasswordAuthentication
Expand Down Expand Up @@ -85,8 +85,9 @@ public function authenticate(array $credentials)
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($statusCode !== 200)
if ($statusCode !== 200) {
throw new AuthFailed("Authentication failed: " . ($response ? json_decode($response)->message : "Unknown error"));
}

return json_decode($response);
}
Expand Down
Loading

0 comments on commit 47ae425

Please sign in to comment.