Bsky Facade - shahmal1yev/blueskysdk GitHub Wiki

The BskyFacade simplifies API interactions by providing a centralized, singleton-based interface for commonly used operations. With this facade, you can streamline your SDK usage and avoid deep method chains.

Why Use BskyFacade?

  • Simplified API Calls: Replace complex chains with straightforward methods.
  • Helper Function: Use the bskyFacade() helper for quick access to the instance.
  • Singleton Design: Maintains a consistent, shared instance.
  • Error Handling: Ensures a valid Client is set during the first call, throwing an InvalidArgumentException otherwise.

Example Usage

Initialize and use the BskyFacade as follows:

// Access the facade using the helper function
$facade = bskyFacade($client); // or Atproto\BskyFacade::getInstance($client);

// Create a post
$post = $facade->post()->text("Hello, BlueSky!");
$createdRecord = $facade->createRecord()->record($post)->send();

echo $createdRecord->uri(); // Output: URI of the created post

[!TIP] The Client must be provided during the first usage of BskyFacade. After that, it will be reused automatically in subsequent calls.

Updating the Client Instance

If needed, you can update the Client instance at any point:

$client1 = new Client();
$client2 = new Client();

// Set or replace the current client
bskyFacade($client1); // First instance
bskyFacade($client2); // Replaces the previous client

This ensures flexibility while maintaining the simplicity of the singleton design.