Struct geeny_api::ConnectApi
[−]
[src]
pub struct ConnectApi(_);
Interface for Geeny Connect APIs
ConnectApi
is an interface for interacting with the Geeny Connect API.
The full specification of these APIs may be found in the
API Specification.
Methods
impl ConnectApi
[src]
fn new(host: String, port: u16) -> Self
[src]
Create a new Connect API handle
Example
use geeny_api::ConnectApi; let api = ConnectApi::new("https://connect.geeny.io".into(), 443);
fn login(&self, req: &AuthLoginRequest) -> Result<AuthLoginResponse>
[src]
Perform a Basic Auth login and obtain an API token
If the response was successful, Ok(AuthLoginResponse)
is returned.
If a network or server error occurred, or if the credentials were incorrect,
an Err
is returned.
Example
extern crate geeny_api; use geeny_api::ConnectApi; use geeny_api::models::*; fn main() { let api = ConnectApi::default(); let log_req = AuthLoginRequest { email: "demo@email.com".into(), password: "S3cureP@ssword!".into(), }; let response = api.login(&log_req).unwrap(); println!("token: {}", response.token); }
fn check_token(&self, req: &AuthLoginResponse) -> Result<()>
[src]
Check the validity of an API token
If the response was successful, Ok(())
is returned. If a network or
server error occurred, or if the token is invalid, an Err
is returned.
Example
extern crate geeny_api; use geeny_api::ConnectApi; use geeny_api::models::*; fn main() { let api = ConnectApi::default(); // first, obtain a token let log_req = AuthLoginRequest { email: "demo@email.com".into(), password: "S3cureP@ssword!".into(), }; let response = api.login(&log_req).unwrap(); // then, verify the token api.check_token(&response).unwrap(); }
fn refresh_token(&self, req: &AuthLoginResponse) -> Result<AuthLoginResponse>
[src]
Refresh an API token
If the response was successful, Ok(AuthLoginResponse)
is returned.
If a network or server error occurred, or if the token is not refreshable,
an Err
is returned.
The token returned should be used for all further API requests, and the original token should be discarded on successful refresh.
Example
extern crate geeny_api; use geeny_api::ConnectApi; use geeny_api::models::*; fn main() { let api = ConnectApi::default(); // first, obtain a token let log_req = AuthLoginRequest { email: "demo@email.com".into(), password: "S3cureP@ssword!".into(), }; let response = api.login(&log_req).unwrap(); println!("1st Token: {}", response.token); // then, refresh the token let new_response = api.refresh_token(&response).unwrap(); println!("2nd Token: {}", new_response.token); }
Trait Implementations
impl Debug for ConnectApi
[src]
impl Clone for ConnectApi
[src]
fn clone(&self) -> ConnectApi
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Hash for ConnectApi
[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
[src]
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more