[][src]Struct threema_gateway::ApiBuilder

pub struct ApiBuilder {
    pub id: String,
    pub secret: String,
    pub private_key: Option<SecretKey>,
    pub endpoint: Cow<'static, str>,
}

A convenient way to set up the API object.

Examples

Simple API

use threema_gateway::{ApiBuilder, SimpleApi};

let gateway_id = "*3MAGWID";
let gateway_secret = "hihghrg98h00ghrg";

let api: SimpleApi = ApiBuilder::new(gateway_id, gateway_secret).into_simple();

E2E API

use threema_gateway::{ApiBuilder, E2eApi};

let gateway_id = "*3MAGWID";
let gateway_secret = "hihghrg98h00ghrg";
let private_key = "998730fbcac1c57dbb181139de41d12835b3fae6af6acdf6ce91670262e88453";

let api: E2eApi = ApiBuilder::new(gateway_id, gateway_secret)
                             .with_private_key_str(private_key)
                             .and_then(|builder| builder.into_e2e())
                             .unwrap();

Fields

id: Stringsecret: Stringprivate_key: Option<SecretKey>endpoint: Cow<'static, str>

Methods

impl ApiBuilder[src]

pub fn new<I: Into<String>, S: Into<String>>(id: I, secret: S) -> Self[src]

Initialize the ApiBuilder with the Gateway ID and the Gateway Secret.

pub fn with_custom_endpoint<E: Into<Cow<'static, str>>>(
    self,
    endpoint: E
) -> Self
[src]

Set a custom API endpoint.

The API endpoint should be a HTTPS URL without trailing slash.

pub fn into_simple(self) -> SimpleApi[src]

Return a SimpleAPI instance.

pub fn with_private_key(self, private_key: SecretKey) -> Self[src]

Set the private key. Only needed for E2e mode.

pub fn with_private_key_bytes(
    self,
    private_key: &[u8]
) -> Result<Self, ApiBuilderError>
[src]

Set the private key from a byte slice. Only needed for E2e mode.

pub fn with_private_key_str(
    self,
    private_key: &str
) -> Result<Self, ApiBuilderError>
[src]

Set the private key from a hex-encoded string reference. Only needed for E2e mode.

pub fn into_e2e(self) -> Result<E2eApi, ApiBuilderError>[src]

Return a E2eAPI instance.

Trait Implementations

impl Debug for ApiBuilder[src]

Auto Trait Implementations

impl Send for ApiBuilder

impl Sync for ApiBuilder

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T