diff --git a/src/BlueskyClient.php b/src/BlueskyClient.php index 92e838ae..05423ee7 100644 --- a/src/BlueskyClient.php +++ b/src/BlueskyClient.php @@ -14,7 +14,7 @@ class BlueskyClient implements Factory { use Macroable; - protected Collection $session; + protected ?Collection $session = null; public function __construct(protected string $service = 'https://bsky.social') { @@ -28,9 +28,9 @@ public function service(string $service): static return $this; } - public function session(string $key): mixed + public function session(string $key = null): mixed { - return $this->session->get($key); + return empty($key) ? $this->session : $this->session?->get($key); } /** diff --git a/tests/Feature/Client/ClientTest.php b/tests/Feature/Client/ClientTest.php index 140939ed..a510c1f6 100644 --- a/tests/Feature/Client/ClientTest.php +++ b/tests/Feature/Client/ClientTest.php @@ -28,6 +28,19 @@ public function test_login() $this->assertSame('test', $client->session('accessJwt')); } + public function test_session() + { + Http::fake(fn () => ['accessJwt' => 'test', 'did' => 'test']); + + $client = new BlueskyClient(); + + $client->service('https://bsky.social') + ->login(identifier: 'identifier', password: 'password'); + + $this->assertSame(['accessJwt' => 'test', 'did' => 'test'], $client->session()->toArray()); + $this->assertSame('test', $client->session('accessJwt')); + } + public function test_feed() { Http::fakeSequence()