Skip to content

Commit

Permalink
Add uploadBlob
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Sep 4, 2024
1 parent f3d8ba8 commit 7e957f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/BlueskyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ public function post(string $text, ?array $facets = null, ?array $embed = null):
]);
}

/**
* Upload blob.
*
* @throws ConnectionException
*/
public function uploadBlob(mixed $data): Response
{
return Http::baseUrl($this->baseUrl())
->withToken($this->session('accessJwt'))
->withBody($data)
->post(AtProto::uploadBlob->value);
}

public function check(): bool
{
return ! empty($this->session['accessJwt']);
Expand Down
1 change: 1 addition & 0 deletions src/Enums/AtProto.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ enum AtProto: string

case createSession = 'com.atproto.server.createSession';
case createRecord = 'com.atproto.repo.createRecord';
case uploadBlob = 'com.atproto.repo.uploadBlob';
}
1 change: 1 addition & 0 deletions src/Facades/Bluesky.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @method static Response feed(int $limit = 50, string $cursor = '', string $filter = 'posts_with_replies')
* @method static Response timeline(int $limit = 50, string $cursor = '')
* @method static Response post(string $text, ?array $facets = null, ?array $embed = null)
* @method static Response uploadBlob(mixed $data)
* @method static void macro(string $name, object|callable $macro)
* @method static \Revolution\Bluesky\BlueskyClient|Response|mixed when(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null)
* @method static \Revolution\Bluesky\BlueskyClient|Response|mixed unless(\Closure|mixed|null $value = null, callable|null $callback = null, callable|null $default = null)
Expand Down
12 changes: 12 additions & 0 deletions tests/Feature/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,16 @@ public function test_post()

$this->assertTrue($response->collect()->has('uri'));
}

public function test_upload_blob()
{
Http::fakeSequence()
->push(['accessJwt' => 'test', 'did' => 'test'])
->push(['blob' => '...']);

$response = Bluesky::login(identifier: 'identifier', password: 'password')
->uploadBlob('test');

$this->assertTrue($response->collect()->has('blob'));
}
}

0 comments on commit 7e957f3

Please sign in to comment.