Struct harmony_rust_sdk::client::Client[][src]

pub struct Client { /* fields omitted */ }

Client implementation for Harmony.

Implementations

impl Client[src]

pub async fn new(
    homeserver_url: Url,
    session: Option<Session>
) -> ClientResult<Self>
[src]

Create a new Client from a homeserver Url (URL) and an (optional) session.

If port is not specified in the URL, this will add the default port 2289 to it. If scheme is not specified, this will assume the scheme is https.

Example

let client = Client::new("https://chat.harmonyapp.io:2289".parse().unwrap(), None).await?;

pub async fn request<Req: ClientRequest<Resp>, Resp, IntoReq: Into<Req>>(
    &self,
    request: IntoReq
) -> ClientResult<Resp>
[src]

Send a request.

Example

client
 .request::<ProfileUpdateRequest, _, _>(
   ProfileUpdate::default()
       .new_status(UserStatus::OnlineUnspecified)
       .new_is_bot(true),
  )
  .await?;

pub fn auth_status(&self) -> AuthStatus[src]

Get the current auth status.

Example

assert!(!client.auth_status().is_authenticated());

pub fn homeserver_url(&self) -> &Url[src]

Get the stored homeserver URL.

Example

assert_eq!(&client.homeserver_url().to_string(), "https://chat.harmonyapp.io:2289/");

pub fn make_hmc(&self, id: impl ToString) -> Hmc[src]

Makes an HMC with homeserver’s authority and the given ID.

Example

assert_eq!(client.make_hmc("404"), Hmc::new("chat.harmonyapp.io:2289", "404"));

pub async fn begin_auth(&self) -> ClientResult<()>[src]

Start an authentication session.

Example

client.begin_auth().await?;
// Do auth stuff here

pub async fn next_auth_step(
    &self,
    response: AuthStepResponse
) -> ClientResult<Option<AuthStep>>
[src]

Request the next authentication step from the server.

Returns Ok(None) if authentication was completed. Returns Ok(Some(AuthStep)) if extra step is requested from the server.

Example

client.begin_auth().await?;
let next_step = client.next_auth_step(AuthStepResponse::Initial).await?;
// Do more auth stuff here

pub async fn prev_auth_step(&self) -> ClientResult<AuthStep>[src]

Go back to the previous authentication step.

Example

client.begin_auth().await?;
// Call next step and whatnot here
// Oops, user wants to do something else, lets go back
let prev_step = client.prev_auth_step().await?;
// Do more auth stuff here

pub async fn subscribe_events(
    &self,
    subscriptions: Vec<EventSource>
) -> ClientResult<EventsSocket>
[src]

Subscribe to events coming from specified event sources.

Example

// Auth here
let event_stream = client.subscribe_events(vec![EventSource::Homeserver, EventSource::Action]).await?;
// Do more auth stuff here

Trait Implementations

impl Clone for Client[src]

impl Debug for Client[src]

Auto Trait Implementations

impl !RefUnwindSafe for Client

impl Send for Client

impl Sync for Client

impl Unpin for Client

impl !UnwindSafe for Client

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> IntoRequest<T> for T[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,