Skip to content

Commit

Permalink
Change return type to Response
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Mar 11, 2024
1 parent c49be90 commit 1cd564d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
13 changes: 7 additions & 6 deletions docs/bluesky-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@ Only my posts and reposts.
```php
use Revolution\Bluesky\Facades\Bluesky;

/** @var \Illuminate\Support\Collection $response */
/** @var \Illuminate\Http\Client\Response $response */
$response = Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
->feed();

dump($response);
dump($response->json());
```

## Viewing my timeline
```php
use Revolution\Bluesky\Facades\Bluesky;

/** @var \Illuminate\Support\Collection $response */
/** @var \Illuminate\Http\Client\Response $response */
$response = Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
->timeline();
->timeline()
->throw();

dump($response);
dump($response->collect());
```

## Creating a post

```php
use Revolution\Bluesky\Facades\Bluesky;

/** @var \Illuminate\Support\Collection $response */
/** @var \Illuminate\Http\Client\Response $response */
Bluesky::login(identifier: config('bluesky.identifier'), password: config('bluesky.password'))
->post('test');

Expand Down
28 changes: 10 additions & 18 deletions src/BlueskyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Revolution\Bluesky;

use Illuminate\Http\Client\RequestException;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Traits\Macroable;
use Revolution\Bluesky\Contracts\Factory;
use Revolution\Bluesky\Enums\AtProto;

class BlueskyClient implements Factory
{
Expand Down Expand Up @@ -51,41 +53,33 @@ public function login(string $identifier, string $password): static

/**
* My feed.
*
* @throws RequestException
*/
public function feed(string $filter = 'posts_with_replies'): Collection
public function feed(string $filter = 'posts_with_replies'): Response
{
return Http::baseUrl($this->baseUrl())
->withToken($this->session('accessJwt'))
->get(AtProto::getAuthorFeed->value, [
'actor' => $this->session('did'),
'filter' => $filter,
])
->throw()
->collect();
]);
}

/**
* My timeline.
*
* @throws RequestException
*/
public function timeline(string $cursor = ''): Collection
*/
public function timeline(string $cursor = ''): Response
{
return Http::baseUrl($this->baseUrl())
->withToken($this->session('accessJwt'))
->get(AtProto::getTimeline->value, [
'cursor' => $cursor,
])
->throw()
->collect();
]);
}

/**
* @throws RequestException
* Create new post.
*/
public function post(string $text): Collection
public function post(string $text): Response
{
return Http::baseUrl($this->baseUrl())
->withToken($this->session('accessJwt'))
Expand All @@ -96,9 +90,7 @@ public function post(string $text): Collection
'text' => $text,
'createdAt' => now()->toISOString(),
]
])
->throw()
->collect();
]);
}

private function baseUrl(): string
Expand Down
2 changes: 1 addition & 1 deletion src/AtProto.php → src/Enums/AtProto.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Revolution\Bluesky;
namespace Revolution\Bluesky\Enums;

enum AtProto: string
{
Expand Down
8 changes: 4 additions & 4 deletions src/Facades/Bluesky.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Revolution\Bluesky\Facades;

use Illuminate\Support\Collection;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Facade;
use Revolution\Bluesky\Contracts\Factory;

/**
* @method static static service(string $service)
* @method static mixed session(string $key)
* @method static static login(string $identifier, string $password)
* @method static Collection feed(string $filter = 'posts_with_replies')
* @method static Collection timeline(string $cursor = '')
* @method static Collection post(string $text)
* @method static Response feed(string $filter = 'posts_with_replies')
* @method static Response timeline(string $cursor = '')
* @method static Response post(string $text)
*/
class Bluesky extends Facade
{
Expand Down
7 changes: 6 additions & 1 deletion src/Notifications/BlueskyChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Revolution\Bluesky\Notifications;

use Illuminate\Http\Client\RequestException;
use Illuminate\Notifications\Notification;
use Revolution\Bluesky\Facades\Bluesky;

class BlueskyChannel
{
/**
* @throws RequestException
*/
public function send(mixed $notifiable, Notification $notification): void
{
/** @var BlueskyMessage $message */
Expand All @@ -27,6 +31,7 @@ public function send(mixed $notifiable, Notification $notification): void

Bluesky::service($route->service)
->login($route->identifier, $route->password)
->post($message->text);
->post($message->text)
->throw();
}
}
6 changes: 3 additions & 3 deletions tests/Feature/Client/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test_feed()
$response = Bluesky::login(identifier: 'identifier', password: 'password')
->feed(filter: 'posts_with_replies');

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

public function test_timeline()
Expand All @@ -62,7 +62,7 @@ public function test_timeline()
$response = Bluesky::login(identifier: 'identifier', password: 'password')
->timeline(cursor: '1');

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

public function test_post()
Expand All @@ -74,6 +74,6 @@ public function test_post()
$response = Bluesky::login(identifier: 'identifier', password: 'password')
->post(text: 'test');

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

0 comments on commit 1cd564d

Please sign in to comment.