Struct WebwareClient

Source
pub struct WebwareClient<State = Unregistered> { /* private fields */ }
Expand description

The web client to consume SoftENGINE’s WEBSERVICES

Implementations§

Source§

impl WebwareClient

Source

pub fn builder() -> InternalWebwareClientBuilder

Creates a builder for the client

Source

pub async fn register(self) -> WWClientResult<WebwareClient<Registered>>

Sends a REGISTER request to the WEBWARE instance and returns a registered client or an error

Source

pub async fn with_registered<F, T>(self, f: F) -> WWClientResult<T>
where F: for<'a> FnOnce(&'a mut WebwareClient<Registered>) -> BoxFuture<'a, T>,

Provides a harness for operating with the client by registering, running the provided closure and then deregistering the client.

§Example
use wwsvc_rs::futures::FutureExt;

#[tokio::main]
async fn main() {
    let client = wwsvc_rs::WebwareClient::builder()
           .webware_url("https://meine-webware.de")
           .vendor_hash("my-vendor-hash")
           .app_hash("my-app-hash")
           .secret("1")
           .revision(1)
           .build();

    let article_result = client
        .with_registered(|registered_client| async {
            // Do something with the registered client
        }.boxed())
        .await;
}
Source§

impl<State: Ready> WebwareClient<State>

Source

pub fn create_cursor(self, max_lines: u32) -> WebwareClient<OpenCursor>

Creates a new pagination cursor and makes it available for the next requests (until it is closed)

Source

pub fn credentials(&self) -> &Credentials

Generates a set of credentials from the current client.

Source

pub fn set_result_max_lines(&mut self, max_lines: u32)

Sets the maximum amount of results that are returned in a response

Source

pub fn get_default_headers( &mut self, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<HeaderMap>

Returns a set of headers, that are required on all requests to the WEBSERVICES (except REGISTER).

This will automatically append necessary authentication headers and increase the request ID, if register() was successful.

Source

pub fn get_bin_headers( &mut self, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<HeaderMap>

Returns the same set of headers, that get_default_headers() returns, except the result type header is set to BIN instead.

Source

pub async fn deregister(self) -> WWClientResult<WebwareClient<Unregistered>>

Sends a DEREGISTER request to the WEBWARE instance, in order to invalidate the service pass.

Source

pub fn prepare_request( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Request>

Prepares a request to the WEBSERVICES.

This will return a [reqwest::Request] object, that can be executed using the execute_request method.

NOTE: This method will also update the internal state of the client, such as the request ID and cursor.

Source

pub async fn execute_request( &mut self, request: Request, ) -> WWClientResult<Response>

Executes a prepared request to the WEBSERVICES.

This will execute the prepared request and return a response object.

NOTE: This method will also update the internal state of the client, such as the request ID and cursor.

Source

pub async fn request( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Value>

Performs a request to the WEBSERVICES and returns a JSON value.

Source

pub async fn request_as_response( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<Response>

Performs a request to the WEBSERVICES and returns a response object.

Source

pub async fn request_generic<T>( &mut self, method: Method, function: &str, version: u32, parameters: HashMap<&str, &str>, additional_headers: Option<HashMap<&str, &str>>, ) -> WWClientResult<T>

Performs a request to the WEBSERVICES and deserializes the response to the type T.

NOTE: Due to the nature of the WEBSERVICES, deserialization might fail due to structural issues. In that case, use request() instead.

Source§

impl WebwareClient<OpenCursor>

Source

pub fn suspend_cursor(&mut self)

Suspends the cursor, so that it is not used for the next request

Source

pub fn resume_cursor(&mut self)

Resumes the cursor, so that it is used for the next request

Source

pub fn cursor_closed(&self) -> bool

Returns whether the current cursor is closed.

Returns None, if no cursor is available.

Trait Implementations§

Source§

impl<State: Clone> Clone for WebwareClient<State>

Source§

fn clone(&self) -> WebwareClient<State>

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 From<InternalWebwareClient> for WebwareClient<Unregistered>

Source§

fn from(client: InternalWebwareClient) -> Self

Converts to this type from the input type.
Source§

impl TryFrom<InternalWebwareClient> for WebwareClient<Registered>

Source§

type Error = WWSVCError

The type returned in the event of a conversion error.
Source§

fn try_from(client: InternalWebwareClient) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<State> Freeze for WebwareClient<State>

§

impl<State = Unregistered> !RefUnwindSafe for WebwareClient<State>

§

impl<State> Send for WebwareClient<State>
where State: Send,

§

impl<State> Sync for WebwareClient<State>
where State: Sync,

§

impl<State> Unpin for WebwareClient<State>
where State: Unpin,

§

impl<State = Unregistered> !UnwindSafe for WebwareClient<State>

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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,