pub struct Client<C: Cache + Send + Sync + 'static, R: RateLimiter + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> {
pub host: String,
pub language: Language,
/* private fields */
}
Fields§
§host: String
§language: Language
Implementations§
Source§impl Client<NoopCache, NoopRateLimiter, HttpsConnector<HttpConnector>, false>
impl Client<NoopCache, NoopRateLimiter, HttpsConnector<HttpConnector>, false>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
creates a new gw2 api client
§Warning
this is not the same as Client::default
!
This initializes a client without any caching or rate limiting.
If you want to use a default cache and rate limiter, use
Client::default
.
Source§impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Client<C, R, Conn, AUTHENTICATED>
constructing client
impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Client<C, R, Conn, AUTHENTICATED>
constructing client
Sourcepub fn host(
self,
host: impl Into<String>,
) -> Client<C, R, HttpsConnector<HttpConnector>, AUTHENTICATED>
pub fn host( self, host: impl Into<String>, ) -> Client<C, R, HttpsConnector<HttpConnector>, AUTHENTICATED>
sets the host name
default is https://api.guildwars2.com
(no trailing slash)
for non https hosts use Client::host_http
Sourcepub fn host_http(
self,
host: impl Into<String>,
) -> Client<C, R, HttpConnector, AUTHENTICATED>
pub fn host_http( self, host: impl Into<String>, ) -> Client<C, R, HttpConnector, AUTHENTICATED>
sets the non https host name
for https hosts use Client::host
Sourcepub fn identifier(self, id: impl Into<String>) -> Self
pub fn identifier(self, id: impl Into<String>) -> Self
sets a new identifier
Identifiers are used to identify authentications in the cache. Defaults to the api key
§Example
use gw2lib::{Client, Requester};
use gw2lib_model::authenticated::{
account::Account,
characters::{Character, CharacterId},
};
let client = Client::default().api_key("<subtoken>");
let account: Account = client.get().unwrap();
let client = client.identifier(&account.id);
// make a request
let characters: Vec<CharacterId> = client.ids::<Character, CharacterId>().unwrap();
let client = Client::default().api_key("<different subtoken>");
let client = client.identifier(account.id);
// cache hit
let characters: Vec<CharacterId> = client.ids::<Character, CharacterId>().unwrap();
Sourcepub fn cache<NC: Cache + Send + Sync + 'static>(
self,
cache: Arc<NC>,
) -> Client<NC, R, Conn, AUTHENTICATED>
pub fn cache<NC: Cache + Send + Sync + 'static>( self, cache: Arc<NC>, ) -> Client<NC, R, Conn, AUTHENTICATED>
sets the cache
§Example
use gw2lib::cache::InMemoryCache;
use gw2lib::Client;
use std::sync::{Arc, Mutex};
let cache = Arc::new(InMemoryCache::default());
let client = Client::empty().cache(cache);
Sourcepub fn rate_limiter<NR: RateLimiter + Send + Sync + 'static>(
self,
rate_limiter: NR,
) -> Client<C, NR, Conn, AUTHENTICATED>
pub fn rate_limiter<NR: RateLimiter + Send + Sync + 'static>( self, rate_limiter: NR, ) -> Client<C, NR, Conn, AUTHENTICATED>
allows you to set the rate limiter, for example for sharing it between multiple clients ## Example
use std::sync::Arc;
use gw2lib::cache::InMemoryCache;
use gw2lib::Client;
use gw2lib::rate_limit::BucketRateLimiter;
let client = Client::empty().cache(Arc::new(InMemoryCache::default()));
let rate_limiter = Arc::new(BucketRateLimiter::default());
let client = client.rate_limiter(rate_limiter.clone());
let new_client = Client::default().rate_limiter(rate_limiter.clone());
Trait Implementations§
Source§impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Clone + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Clone for Client<C, R, Conn, AUTHENTICATED>
impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Clone + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Clone for Client<C, R, Conn, AUTHENTICATED>
Source§impl Default for Client<InMemoryCache, BucketRateLimiter, HttpsConnector<HttpConnector>, false>
impl Default for Client<InMemoryCache, BucketRateLimiter, HttpsConnector<HttpConnector>, false>
Source§impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Requester<AUTHENTICATED, false> for Client<C, R, Conn, AUTHENTICATED>
impl<C: Cache + Send + Sync + 'static, R: RateLimiter + Send + Sync + 'static, Conn: Connect + Clone + Send + Sync + 'static, const AUTHENTICATED: bool> Requester<AUTHENTICATED, false> for Client<C, R, Conn, AUTHENTICATED>
type Caching = C
type Connector = Conn
type RateLimiting = R
Source§fn cached(
&self,
cache_duration: Duration,
) -> CachedRequest<'_, Self::Caching, Self::RateLimiting, Self::Connector, AUTHENTICATED, FORCE>
fn cached( &self, cache_duration: Duration, ) -> CachedRequest<'_, Self::Caching, Self::RateLimiting, Self::Connector, AUTHENTICATED, FORCE>
overwrites the cache duration for all requests returned from this
function ## Example Read more
Source§fn forced(
&self,
) -> CachedRequest<'_, Self::Caching, Self::RateLimiting, Self::Connector, AUTHENTICATED, true>
fn forced( &self, ) -> CachedRequest<'_, Self::Caching, Self::RateLimiting, Self::Connector, AUTHENTICATED, true>
forces a fresh copy from the api Read more
Source§fn get<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<T, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + Clone + Send + Sync + FixedEndpoint + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn get<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<T, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + Clone + Send + Sync + FixedEndpoint + 'static,
Self: 'async_trait,
'life0: 'async_trait,
call the fixed endpoint
Source§fn single<'life0, 'async_trait, T, I>(
&'life0 self,
id: impl 'async_trait + Into<I> + Send,
) -> Pin<Box<dyn Future<Output = Result<T, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + Clone + Send + Sync + EndpointWithId<IdType = I> + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Send + Sync + Clone + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn single<'life0, 'async_trait, T, I>(
&'life0 self,
id: impl 'async_trait + Into<I> + Send,
) -> Pin<Box<dyn Future<Output = Result<T, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + Clone + Send + Sync + EndpointWithId<IdType = I> + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Send + Sync + Clone + 'static,
Self: 'async_trait,
'life0: 'async_trait,
request a single item
Source§fn try_get<'life0, 'life1, 'async_trait, T, I>(
&'life0 self,
id: impl 'async_trait + Into<&'life1 I> + Send,
) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>
fn try_get<'life0, 'life1, 'async_trait, T, I>( &'life0 self, id: impl 'async_trait + Into<&'life1 I> + Send, ) -> Pin<Box<dyn Future<Output = Option<T>> + Send + 'async_trait>>
retrieves an item from cache Read more
Source§fn ids<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<I>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn ids<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<I>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
request all available ids
Source§fn many<'life0, 'async_trait, T, I>(
&'life0 self,
ids: Vec<impl 'async_trait + Into<I> + Send>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Clone + Eq + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn many<'life0, 'async_trait, T, I>(
&'life0 self,
ids: Vec<impl 'async_trait + Into<I> + Send>,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Clone + Eq + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
request multiple ids at once
Source§fn page<'life0, 'life1, 'async_trait, T>(
&'life0 self,
page: usize,
page_size: u8,
result: &'life1 mut Vec<T>,
) -> Pin<Box<dyn Future<Output = Result<usize, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + PagedEndpoint + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn page<'life0, 'life1, 'async_trait, T>(
&'life0 self,
page: usize,
page_size: u8,
result: &'life1 mut Vec<T>,
) -> Pin<Box<dyn Future<Output = Result<usize, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + PagedEndpoint + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
requests a page of items and returns the number of total items across
all pages
Source§fn all<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + Eq + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn all<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + Eq + 'static,
Self: 'async_trait,
'life0: 'async_trait,
requests all items using the most efficient method available Read more
Source§fn get_all_by_ids_all<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Clone + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn get_all_by_ids_all<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Hash + Clone + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
Gets all items by querying ids=all Read more
Source§fn get_all_by_paging<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + PagedEndpoint + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn get_all_by_paging<'life0, 'async_trait, T>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + PagedEndpoint + Clone + Send + Sync + 'static,
Self: 'async_trait,
'life0: 'async_trait,
Gets all items by querying all pages Read more
Source§fn get_all_by_requesting_ids<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + Eq + 'static,
Self: 'async_trait,
'life0: 'async_trait,
fn get_all_by_requesting_ids<'life0, 'async_trait, T, I>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>, EndpointError>> + Send + 'async_trait>>where
T: 'async_trait + DeserializeOwned + Serialize + EndpointWithId<IdType = I> + BulkEndpoint + Clone + Send + Sync + 'static,
I: 'async_trait + Display + DeserializeOwned + Serialize + Hash + Clone + Send + Sync + Eq + 'static,
Self: 'async_trait,
'life0: 'async_trait,
Gets all items by querying all ids Read more
Auto Trait Implementations§
impl<C, R, Conn, const AUTHENTICATED: bool> Freeze for Client<C, R, Conn, AUTHENTICATED>
impl<C, R, Conn, const AUTHENTICATED: bool> !RefUnwindSafe for Client<C, R, Conn, AUTHENTICATED>
impl<C, R, Conn, const AUTHENTICATED: bool> Send for Client<C, R, Conn, AUTHENTICATED>
impl<C, R, Conn, const AUTHENTICATED: bool> Sync for Client<C, R, Conn, AUTHENTICATED>
impl<C, R, Conn, const AUTHENTICATED: bool> Unpin for Client<C, R, Conn, AUTHENTICATED>
impl<C, R, Conn, const AUTHENTICATED: bool> !UnwindSafe for Client<C, R, Conn, AUTHENTICATED>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more