BskyAgent

Struct BskyAgent 

Source
pub struct BskyAgent<T = ReqwestClient, S = MemorySessionStore>
where T: XrpcClient + Send + Sync, S: AtpSessionStore + Send + Sync, S::Error: Error + Send + Sync + 'static,
{ /* private fields */ }
Available on crate feature default-client only.
Expand description

A Bluesky agent.

This agent is a wrapper around the Agent that provides additional functionality for working with Bluesky. For creating an instance of this agent, use the BskyAtpAgentBuilder.

§Example

use bsky_sdk::BskyAgent;

#[tokio::main]
async fn main() {
   let agent = BskyAgent::builder().build().await.expect("failed to build agent");
}

Implementations§

Source§

impl BskyAgent

Source

pub fn builder() -> BskyAtpAgentBuilder<ReqwestClient, MemorySessionStore>

Create a new BskyAtpAgentBuilder with the default client and session store.

Source§

impl<T, S> BskyAgent<T, S>
where T: XrpcClient + Send + Sync, S: AtpSessionStore + Send + Sync, S::Error: Error + Send + Sync + 'static,

Source

pub async fn to_config(&self) -> Config

Get the agent’s current state as a Config.

Source

pub async fn get_preferences( &self, enable_bsky_labeler: bool, ) -> Result<Preferences>

Get the logged-in user’s Preferences.

This implementation does not perform migration of SavedFeedsPref to V2.

§Arguments

enable_bsky_labeler - If true, the Bluesky’s moderation labeler will be included in the moderation preferences.

Source

pub fn configure_labelers_from_preferences(&self, preferences: &Preferences)

Configure the labelers header.

Read labelers preferences from the provided Preferences and set the labelers header up to 10 labelers.

See details: https://docs.bsky.app/docs/advanced-guides/moderation#labeler-subscriptions

Source

pub async fn moderator(&self, preferences: &Preferences) -> Result<Moderator>

Make a Moderator instance with the provided Preferences.

Source§

impl<T, S> BskyAgent<T, S>
where T: XrpcClient + Send + Sync, S: AtpSessionStore + Send + Sync, S::Error: Error + Send + Sync + 'static,

Source

pub async fn create_record( &self, subject: impl Into<KnownRecord>, ) -> Result<Output>

Create a record with various types of data. For example, the Record families defined in KnownRecord are supported.

§Example
use bsky_sdk::{BskyAgent, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let agent = BskyAgent::builder().build().await?;
    let output = agent.create_record(atrium_api::app::bsky::graph::block::RecordData {
        created_at: atrium_api::types::string::Datetime::now(),
        subject: "did:fake:handle.test".parse().expect("invalid did"),
    }).await?;
    Ok(())
}
Source

pub async fn delete_record(&self, at_uri: impl AsRef<str>) -> Result<Output>

Delete a record with AT URI.

§Errors

Returns an Error::InvalidAtUri if the at_uri is invalid.

§Example
use bsky_sdk::{BskyAgent, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let agent = BskyAgent::builder().build().await?;
    agent.delete_record("at://did:fake:handle.test/app.bsky.graph.block/3kxmfwtgfxl2w").await?;
    Ok(())
}

Methods from Deref<Target = AtpAgent<S, T>>§

Source

pub async fn login( &self, identifier: impl AsRef<str>, password: impl AsRef<str>, ) -> Result<Object<OutputData>, Error<Error>>

Start a new session with this agent.

Source

pub async fn resume_session( &self, session: Object<OutputData>, ) -> Result<(), Error<Error>>

Source

pub async fn get_session(&self) -> Option<Object<OutputData>>

Get the current session.

Source

pub async fn get_endpoint(&self) -> String

Get the current endpoint.

Source

pub async fn get_labelers_header(&self) -> Option<Vec<String>>

Get the current labelers header.

Source

pub async fn get_proxy_header(&self) -> Option<String>

Get the current proxy header.

Methods from Deref<Target = Agent<Wrapper<CredentialSession<S, T>>>>§

Source

pub async fn did(&self) -> Option<Did>

Returns the DID of the current session.

Source

pub fn api_with_proxy( &self, did: Did, service_type: impl AsRef<str>, ) -> Service<Wrapper<M>>

Configures the atproto-proxy header to be applied on requests.

Returns a new client service with the proxy header configured.

Trait Implementations§

Source§

impl<T, S> Clone for BskyAgent<T, S>
where T: XrpcClient + Send + Sync + Clone, S: AtpSessionStore + Send + Sync + Clone, S::Error: Error + Send + Sync + 'static,

Source§

fn clone(&self) -> BskyAgent<T, S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, S> Deref for BskyAgent<T, S>
where T: XrpcClient + Send + Sync, S: AtpSessionStore + Send + Sync, S::Error: Error + Send + Sync + 'static,

Source§

type Target = AtpAgent<S, T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<T, S> Freeze for BskyAgent<T, S>

§

impl<T = ReqwestClient, S = MemoryStore<(), Object<OutputData>>> !RefUnwindSafe for BskyAgent<T, S>

§

impl<T, S> Send for BskyAgent<T, S>

§

impl<T, S> Sync for BskyAgent<T, S>

§

impl<T, S> Unpin for BskyAgent<T, S>

§

impl<T = ReqwestClient, S = MemoryStore<(), Object<OutputData>>> !UnwindSafe for BskyAgent<T, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, C> Cacheable<C> for T

Source§

fn cached(self, cache: C) -> Cached<T, C>

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<P, T> Throttleable<P> for T
where P: Default,

Source§

fn throttled(self) -> Throttled<T, P>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T