pub struct Client { /* private fields */ }
Expand description
Starting point for interacting with a lotide API
Implementations§
source§impl Client
impl Client
sourcepub fn new(instance_url: impl ToString) -> Self
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
sourcepub fn reqwest_client(&self) -> &Client
pub fn reqwest_client(&self) -> &Client
Get the internal reqwest::Client
instance
sourcepub fn reqwest_client_mut(&mut self) -> &mut Client
pub fn reqwest_client_mut(&mut self) -> &mut Client
Get the internal reqwest::Client
instance mutably
sourcepub fn instance_url(&self) -> &str
pub fn instance_url(&self) -> &str
Get the stored instance URL
This is the URL prepended to every request
sourcepub fn set_token(&mut self, token: impl ToString)
pub fn set_token(&mut self, token: impl ToString)
Set the bearer token to be used with requests
sourcepub async fn instance_info(&self) -> Result<InstanceInfo>
pub async fn instance_info(&self) -> Result<InstanceInfo>
Make a request to the instance for information about itself
sourcepub async fn login(
&self,
username: impl ToString,
password: impl ToString
) -> Result<(Client, LoginInfo)>
pub async fn login( &self, username: impl ToString, password: impl ToString ) -> Result<(Client, LoginInfo)>
Log in to the service
sourcepub async fn current_login(&self) -> Result<LoginInfo>
pub async fn current_login(&self) -> Result<LoginInfo>
Fetch current login state
sourcepub async fn register<'a>(
&self,
req: &ReqRegister<'a>
) -> Result<(Option<Client>, LoginInfo)>
pub async fn register<'a>( &self, req: &ReqRegister<'a> ) -> Result<(Option<Client>, LoginInfo)>
Register a new account
sourcepub async fn communities<'a>(
&self,
req: &ReqCommunities<'a>
) -> Result<List<CommunityInfo>>
pub async fn communities<'a>( &self, req: &ReqCommunities<'a> ) -> Result<List<CommunityInfo>>
List communities on the instance
sourcepub async fn posts<'a>(&self, req: &ReqPosts<'a>) -> Result<List<PostListPost>>
pub async fn posts<'a>(&self, req: &ReqPosts<'a>) -> Result<List<PostListPost>>
List posts on the instance
sourcepub async fn new_post<'a>(&self, req: &ReqNewPost<'a>) -> Result<PostId>
pub async fn new_post<'a>(&self, req: &ReqNewPost<'a>) -> Result<PostId>
Create a new post
sourcepub async fn media(&self, mime: &str, data: Vec<u8>) -> Result<String>
pub async fn media(&self, mime: &str, data: Vec<u8>) -> Result<String>
Updload an image to the instance
sourcepub async fn request<T: DeserializeOwned>(
&self,
method: Method,
subpath: &str
) -> Result<T, Error>
pub async fn request<T: DeserializeOwned>( &self, method: Method, subpath: &str ) -> Result<T, Error>
Make a request to the instance
sourcepub async fn request_with<T: DeserializeOwned>(
&self,
method: Method,
subpath: &str,
f: impl FnOnce(RequestBuilder) -> RequestBuilder
) -> Result<T, Error>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more