Struct meztide::client::Client

source ·
pub struct Client { /* private fields */ }
Expand description

Starting point for interacting with a lotide API

Implementations§

source§

impl Client

source

pub fn new(instance_url: impl ToString) -> Self

Create a new Client

instance_url should be the full base url to the instance’s API, e.g. https://lotide.example.com/api/unstable

source

pub fn set_lang(&mut self, lang: impl ToString)

Set the language

source

pub fn with_lang(self, lang: impl ToString) -> Self

Set the language

source

pub fn lang(&self) -> Option<&str>

Get the language

source

pub fn reqwest_client(&self) -> &Client

Get the internal reqwest::Client instance

source

pub fn reqwest_client_mut(&mut self) -> &mut Client

Get the internal reqwest::Client instance mutably

source

pub fn instance_url(&self) -> &str

Get the stored instance URL

This is the URL prepended to every request

source

pub fn set_token(&mut self, token: impl ToString)

Set the bearer token to be used with requests

source

pub fn has_token(&self) -> bool

Does the Client have a token set?

source

pub fn get_token(&self) -> Option<Secret<String>>

Get the stored token

source

pub async fn instance_info(&self) -> Result<InstanceInfo>

Make a request to the instance for information about itself

source

pub async fn login( &self, username: impl ToString, password: impl ToString ) -> Result<(Client, LoginInfo)>

Log in to the service

source

pub async fn current_login(&self) -> Result<LoginInfo>

Fetch current login state

source

pub async fn log_out(&self) -> Result<()>

Log out

source

pub async fn register<'a>( &self, req: &ReqRegister<'a> ) -> Result<(Option<Client>, LoginInfo)>

Register a new account

source

pub async fn communities<'a>( &self, req: &ReqCommunities<'a> ) -> Result<List<CommunityInfo>>

List communities on the instance

source

pub async fn posts<'a>(&self, req: &ReqPosts<'a>) -> Result<List<PostListPost>>

List posts on the instance

source

pub async fn new_post<'a>(&self, req: &ReqNewPost<'a>) -> Result<PostId>

Create a new post

source

pub async fn media(&self, mime: &str, data: Vec<u8>) -> Result<String>

Updload an image to the instance

source

pub async fn request<T: DeserializeOwned>( &self, method: Method, subpath: &str ) -> Result<T, Error>

Make a request to the instance

source

pub async fn request_with<T: DeserializeOwned>( &self, method: Method, subpath: &str, f: impl FnOnce(RequestBuilder) -> RequestBuilder ) -> Result<T, Error>

Like Ctx::request, but allows you to modify the RequestBuilder before sending

Trait Implementations§

source§

impl PartialEq for Client

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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