Skip to content

Commit

Permalink
Update BlueskyClient.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kawax committed Oct 14, 2024
1 parent 5eba858 commit 9153846
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/BlueskyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Revolution\Bluesky\Contracts\Factory;
use Revolution\Bluesky\Enums\AtProto;
use Revolution\Bluesky\Notifications\BlueskyMessage;
use Revolution\Bluesky\Support\Identity;

class BlueskyClient implements Factory
{
Expand Down Expand Up @@ -69,19 +70,32 @@ public function login(string $identifier, #[\SensitiveParameter] string $passwor
}

/**
* @param string $handle e.g. "alice.test"
*
* @throws ConnectionException
*/
public function resolveHandle(string $handle): Response
{
if (! Identity::isHandle($handle)) {
throw new InvalidArgumentException("The handle '$handle' is not a valid handle.");
}

return Http::baseUrl($this->baseUrl())
->withToken($this->session('accessJwt'))
->get(AtProto::resolveHandle->value, [
'handle' => $handle,
]);
}

/**
* @param string $did e.g. "did:plc:1234..." "did:web:alice.test"
*/
public function resolveDID(string $did): Response
{
if (! Identity::isDID($did)) {
throw new InvalidArgumentException("The did '$did' is not a valid DID.");
}

$url = match (true) {
Str::startsWith($did, 'did:plc:') => 'https://plc.directory/'.$did,
Str::startsWith($did, 'did:web:') => 'https://'.Str::remove('did:web:', $did).'/.well-known/did.json',
Expand Down

0 comments on commit 9153846

Please sign in to comment.