Struct Client

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

Source

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

Source

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

Source

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

Source

pub fn language(self, language: impl Into<Language>) -> Self

sets the language

Source

pub fn api_key(self, key: impl Into<String>) -> Client<C, R, Conn, true>

sets a new api key

Source

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();
Source

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);
Source

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>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Client<InMemoryCache, BucketRateLimiter, HttpsConnector<HttpConnector>, false>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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>

Source§

type Caching = C

Source§

type Connector = Conn

Source§

type RateLimiting = R

Source§

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>

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,

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,

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>>
where T: 'async_trait + DeserializeOwned + Serialize + Clone + Endpoint + Send + Sync + 'static, I: 'async_trait + DeserializeOwned + Display + Hash + Clone + Sync + 'static, Self: 'async_trait, 'life0: 'async_trait, 'life1: '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,

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,

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,

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,

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,

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,

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,

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>
where R: Freeze, Conn: Freeze,

§

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>
where R: Unpin, Conn: Unpin,

§

impl<C, R, Conn, const AUTHENTICATED: bool> !UnwindSafe for Client<C, R, Conn, AUTHENTICATED>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,