pub struct DshApiClientFactory { /* private fields */ }Expand description
§Factory for DSH API client
Implementations§
Source§impl DshApiClientFactory
impl DshApiClientFactory
Sourcepub fn new() -> DshApiClientFactory
pub fn new() -> DshApiClientFactory
§Create default factory for DSH API client
This function will create a new DshApiClientFactory from the default environment variables.
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;
let client_factory = DshApiClientFactory::new();
if let Ok(client) = client_factory.client().await {
println!("rest api version is {}", client.api_version());
}§Panics
This function will panic if it cannot create a new DshApiClientFactory from the default
environment variables. If you want to capture such a failure, use the
create() function.
Sourcepub fn create(tenant: DshApiTenant, secret: String) -> Result<Self, DshApiError>
pub fn create(tenant: DshApiTenant, secret: String) -> Result<Self, DshApiError>
§Create factory for DSH API client
This function will create a new DshApiClientFactory from the provided parameters.
§Parameters
tenant- Tenant struct, containing the platform, tenant name and the tenant’s group and user id.secret- The secret used to retrieve the DSH API tokens.
§Returns
Ok<DshApiClientFactory>- the created client factoryErr<String>- when the client factory could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;
use dsh_api::dsh_api_tenant::DshApiTenant;
let secret = "...".to_string();
let tenant = DshApiTenant::from_tenant("greenbox".to_string())?;
let client_factory = DshApiClientFactory::create(tenant, secret)?;
let client = client_factory.client().await?;
println!("rest api version is {}", client.api_version());Sourcepub fn try_default() -> Result<Self, DshApiError>
pub fn try_default() -> Result<Self, DshApiError>
§Create default factory for DSH API client
This function will create a new DshApiClientFactory from the default platform and tenant.
§Returns
Ok<DshApiClientFactory>- the created client factoryErr<String>- when the client factory could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;
let client_factory = DshApiClientFactory::try_default()?;
let client = client_factory.client().await?;
println!("rest api version is {}", client.api_version());Sourcepub fn platform(&self) -> &DshPlatform
pub fn platform(&self) -> &DshPlatform
§Returns the factories platform
Sourcepub fn tenant(&self) -> &DshApiTenant
pub fn tenant(&self) -> &DshApiTenant
§Returns the factories tenant
Sourcepub fn tenant_name(&self) -> &str
pub fn tenant_name(&self) -> &str
§Returns the name of the factories tenant
Sourcepub async fn client(&self) -> Result<DshApiClient<'_>, DshApiError>
pub async fn client(&self) -> Result<DshApiClient<'_>, DshApiError>
§Create an DSH API client
This function will create a new DshApiClient.
§Returns
Ok<DshApiClient>- the created clientErr<String>- error message when the client could not be created
§Examples
use dsh_api::dsh_api_client_factory::DshApiClientFactory;
let client_factory = DshApiClientFactory::new();
match client_factory.client().await {
Ok(client) => println!("rest api version is {}", client.api_version()),
Err(error) => println!("could not create client ({})", error),
}Trait Implementations§
Source§impl Debug for DshApiClientFactory
impl Debug for DshApiClientFactory
Source§impl Default for DshApiClientFactory
impl Default for DshApiClientFactory
Source§fn default() -> Self
fn default() -> Self
§Create default factory for DSH API client
For the explanation, see the new() function,
which delegates to the default implementation.
§Panics
This function will panic if it cannot create a new DshApiClientFactory from the default
environment variables. If you want to capture such a failure, use the
create() function.
Auto Trait Implementations§
impl !Freeze for DshApiClientFactory
impl !RefUnwindSafe for DshApiClientFactory
impl Send for DshApiClientFactory
impl Sync for DshApiClientFactory
impl Unpin for DshApiClientFactory
impl !UnwindSafe for DshApiClientFactory
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> 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