pub struct ModuleClient<'a> { /* private fields */ }client only.Expand description
The shared plumbing of every module client.
Implementations§
Source§impl<'a> ModuleClient<'a>
impl<'a> ModuleClient<'a>
Sourcepub fn new(
transport: &'a Transport,
peer: &'a Peer,
module: ModuleId,
from: PartyRef,
) -> Self
pub fn new( transport: &'a Transport, peer: &'a Peer, module: ModuleId, from: PartyRef, ) -> Self
Builds a client for one module of one peer.
from is the party this process is speaking as; to is the party at the peer, which
defaults to the peer’s only party when it has just one.
Sourcepub fn to(self, party: PartyRef) -> Self
pub fn to(self, party: PartyRef) -> Self
Addresses a specific party at the peer, for a platform that hosts several.
Sourcepub fn open_routing(self) -> Self
pub fn open_routing(self) -> Self
Omits the OCPI-to-* headers, making this an Open Routing Request.
For an Open Routing Request, the TO headers in the request from the requesting party to the Hub MUST be omitted.
Sourcepub fn sender_endpoint(&self) -> Option<SenderEndpoint>
pub fn sender_endpoint(&self) -> Option<SenderEndpoint>
The Sender endpoint of this module, if the peer implements it.
Sourcepub fn receiver_endpoint(&self) -> Option<ReceiverEndpoint>
pub fn receiver_endpoint(&self) -> Option<ReceiverEndpoint>
The Receiver endpoint of this module, if the peer implements it.
Sourcepub async fn get_page<T: DeserializeOwned>(
&self,
url: Url,
) -> Result<Page<T>, OcpiError>
pub async fn get_page<T: DeserializeOwned>( &self, url: Url, ) -> Result<Page<T>, OcpiError>
GET {url}, decoding one page of a list endpoint.
§Errors
Propagates transport, decoding and OCPI-level errors.
Sourcepub async fn put<T: Serialize + Validate>(
&self,
url: Url,
body: &T,
) -> Result<(), OcpiError>
pub async fn put<T: Serialize + Validate>( &self, url: Url, body: &T, ) -> Result<(), OcpiError>
PUT {url} with a body, discarding the response payload.
§Errors
Returns OcpiError::Invalid when the body does not conform and the client is configured
to check outgoing objects, plus the usual transport and OCPI errors.
Sourcepub async fn post<B: Serialize + Validate, T: DeserializeOwned>(
&self,
url: Url,
body: &B,
) -> Result<T, OcpiError>
pub async fn post<B: Serialize + Validate, T: DeserializeOwned>( &self, url: Url, body: &B, ) -> Result<T, OcpiError>
Sourcepub async fn patch<T>(
&self,
url: Url,
patch: &Patch<T>,
) -> Result<(), OcpiError>
pub async fn patch<T>( &self, url: Url, patch: &Patch<T>, ) -> Result<(), OcpiError>
PATCH {url} with a merge patch.
The patch must carry last_updated; the specification’s own example of a 2001 Invalid or missing parameters is a PATCH that does not.
§Errors
Returns OcpiError::Decode when the patch has no last_updated, plus the usual
transport and OCPI errors.
Sourcepub async fn get_bridged<T: DeserializeOwned>(
&self,
url: Url,
kind: ObjectKind,
) -> Result<T, OcpiError>
pub async fn get_bridged<T: DeserializeOwned>( &self, url: Url, kind: ObjectKind, ) -> Result<T, OcpiError>
GET {url}, translating the peer’s version into the canonical model.
§Errors
As ModuleClient::get, plus OcpiError::Decode when the peer’s document is not the
object this endpoint carries, and OcpiError::Unsupported when this build has no
conversions for the peer’s version.
Sourcepub async fn put_bridged<T: Serialize + Validate>(
&self,
url: Url,
body: &T,
kind: ObjectKind,
) -> Result<(), OcpiError>
pub async fn put_bridged<T: Serialize + Validate>( &self, url: Url, body: &T, kind: ObjectKind, ) -> Result<(), OcpiError>
PUT {url}, writing the body in the version the peer speaks.
§Errors
As ModuleClient::put, plus OcpiError::Unsupported when this build cannot write the
peer’s version.
Sourcepub async fn post_bridged<B: Serialize + Validate, T: DeserializeOwned>(
&self,
url: Url,
body: &B,
request_kind: Option<ObjectKind>,
response_kind: Option<ObjectKind>,
) -> Result<T, OcpiError>
pub async fn post_bridged<B: Serialize + Validate, T: DeserializeOwned>( &self, url: Url, body: &B, request_kind: Option<ObjectKind>, response_kind: Option<ObjectKind>, ) -> Result<T, OcpiError>
POST {url}, writing the body in the peer’s version and reading the answer back out of it.
request_kind and response_kind are separate because two OCPI endpoints send one object
and answer with another — POST {tokens}/{uid}/authorize takes a LocationReferences and
returns an AuthorizationInfo.
§Errors
As ModuleClient::post, plus the translation errors of
ModuleClient::get_bridged.
Sourcepub async fn patch_bridged<T>(
&self,
url: Url,
patch: &Patch<T>,
kind: ObjectKind,
) -> Result<(), OcpiError>
pub async fn patch_bridged<T>( &self, url: Url, patch: &Patch<T>, kind: ObjectKind, ) -> Result<(), OcpiError>
PATCH {url} against a peer on another version.
A merge patch is not an object, so it cannot be decoded, converted and re-encoded. It does not have to be: a patch writing only fields the two versions agree about means the same thing in both. One that writes a field they disagree about is refused, with the specification’s own GET → PUT recovery in the message.
§Errors
As ModuleClient::patch, plus OcpiError::Unsupported when the patch writes a field
whose shape differs between the two versions.
Sourcepub fn list_bridged<T: DeserializeOwned + Send + 'static>(
&self,
query: PageQuery,
kind: ObjectKind,
) -> Result<PageStream<'a, T>, OcpiError>
pub fn list_bridged<T: DeserializeOwned + Send + 'static>( &self, query: PageQuery, kind: ObjectKind, ) -> Result<PageStream<'a, T>, OcpiError>
Crawls a list endpoint, translating every page into the canonical model.
§Errors
Sourcepub fn list<T: DeserializeOwned + Send + 'static>(
&self,
query: PageQuery,
) -> Result<PageStream<'a, T>, OcpiError>
pub fn list<T: DeserializeOwned + Send + 'static>( &self, query: PageQuery, ) -> Result<PageStream<'a, T>, OcpiError>
Crawls every page of a Sender list endpoint.
The objects arrive exactly as the peer wrote them; see ModuleClient::list_bridged for
the version-translating form the typed clients use.
§Errors
Returns OcpiError::NotFound when the peer does not implement the Sender interface.
Source§impl<'a> ModuleClient<'a>
impl<'a> ModuleClient<'a>
Sourcepub fn list_from<T: DeserializeOwned + Send + 'static>(
&self,
base: &Url,
query: &PageQuery,
) -> PageStream<'a, T>
pub fn list_from<T: DeserializeOwned + Send + 'static>( &self, base: &Url, query: &PageQuery, ) -> PageStream<'a, T>
A paginated crawl starting from an explicit URL rather than the module’s own list endpoint.
Most modules have one list endpoint and list finds it. Payments is the
exception: it declares a single ModuleID and then addresses its two interfaces through
two different endpoint variables, which version discovery cannot express, so the sub-path
has to come from the caller. See
SenderEndpoint::payments_terminals.
Trait Implementations§
Source§impl<'a> Clone for ModuleClient<'a>
impl<'a> Clone for ModuleClient<'a>
Source§fn clone(&self) -> ModuleClient<'a>
fn clone(&self) -> ModuleClient<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more