Skip to content

Bsky Facade

Eldar Shahmaliyev edited this page Jan 27, 2025 · 1 revision

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.

  • 🏠 Home
    Introduction to the SDK and its features

  • 🚀 Quick Start
    Get started quickly with the basics of using the Bluesky SDK

  • ⚙️ Installation
    Step-by-step guide to installing the SDK

  • 🛠️ Architecture Overview
    Learn about the SDK's structure and design principles

  • 📖 BskyFacade
    Simplify API interactions with the facade

  • 💾 Serialization
    Serialize and deserialize data effectively

  • 🔄 Session Management
    Manage authentication and session reuse

  • 🧹 Casting
    Explore type-safe response casting in the SDK

  • 💡 Examples
    Practical usage examples for various features

Clone this wiki locally