pub struct Peer { /* private fields */ }client only.Expand description
A connected platform: the version agreed with it, where its endpoints are, and the token to authenticate with.
A Peer is built by the registration handshake or, for a connection
that was established before this process started, from stored state with
Peer::builder.
use ocpi_kit::client::Peer;
use ocpi_kit::transport::CredentialsToken;
use ocpi_kit::types::{PartyRef, Url};
use ocpi_kit::{InterfaceRole, ModuleId, VersionNumber};
let peer = Peer::builder(VersionNumber::V2_3_0, CredentialsToken::new("token-c")?)
.versions_url(Url::new("https://cpo.example.com/ocpi/versions")?)
.endpoint(ModuleId::Locations, InterfaceRole::Sender,
Url::new("https://cpo.example.com/ocpi/cpo/2.3.0/locations")?)
.party(PartyRef::new("NL", "TNM")?)
.build();
assert!(peer.implements(&ModuleId::Locations, InterfaceRole::Sender));
assert!(!peer.implements(&ModuleId::Cdrs, InterfaceRole::Sender));Implementations§
Source§impl Peer
Convenience constructors hanging off a Peer.
impl Peer
Convenience constructors hanging off a Peer.
Sourcepub fn module<'a>(
&'a self,
transport: &'a Transport,
module: ModuleId,
from: PartyRef,
) -> ModuleClient<'a>
pub fn module<'a>( &'a self, transport: &'a Transport, module: ModuleId, from: PartyRef, ) -> ModuleClient<'a>
A client for an arbitrary module.
Sourcepub fn locations<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> LocationsSender<'a>
pub fn locations<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> LocationsSender<'a>
The Locations Sender client: pull Locations from this peer.
Sourcepub fn locations_receiver<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> LocationsReceiver<'a>
pub fn locations_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> LocationsReceiver<'a>
The Locations Receiver client: push Locations to this peer.
Sourcepub fn tokens<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> TokensSender<'a>
pub fn tokens<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TokensSender<'a>
The Tokens Sender client: pull Tokens from, and authorize against, this peer.
Sourcepub fn cdrs<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> CdrsClient<'a>
pub fn cdrs<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> CdrsClient<'a>
The CDRs client.
Sourcepub fn tokens_receiver<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> TokensReceiver<'a>
pub fn tokens_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TokensReceiver<'a>
The Tokens Receiver client: push Tokens to this peer.
Sourcepub fn sessions<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> SessionsSender<'a>
pub fn sessions<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> SessionsSender<'a>
The Sessions Sender client: pull Sessions from this peer.
Sourcepub fn sessions_receiver<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> SessionsReceiver<'a>
pub fn sessions_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> SessionsReceiver<'a>
The Sessions Receiver client: push Sessions to this peer.
Sourcepub fn tariffs<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> TariffsSender<'a>
pub fn tariffs<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TariffsSender<'a>
The Tariffs Sender client: pull Tariffs from this peer.
Sourcepub fn tariffs_receiver<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> TariffsReceiver<'a>
pub fn tariffs_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TariffsReceiver<'a>
The Tariffs Receiver client: push Tariffs to this peer.
Sourcepub fn commands<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> CommandsClient<'a>
pub fn commands<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> CommandsClient<'a>
The Commands client.
Sourcepub fn charging_profiles<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> ChargingProfilesClient<'a>
pub fn charging_profiles<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> ChargingProfilesClient<'a>
The Charging Profiles client.
Sourcepub fn hub_client_info<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> HubClientInfoClient<'a>
pub fn hub_client_info<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> HubClientInfoClient<'a>
The Hub Client Info client.
Sourcepub fn payments<'a>(
&'a self,
transport: &'a Transport,
from: PartyRef,
) -> PaymentsClient<'a>
pub fn payments<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> PaymentsClient<'a>
The Payments client.
Source§impl Peer
impl Peer
Sourcepub fn builder(version: VersionNumber, token: CredentialsToken) -> PeerBuilder
pub fn builder(version: VersionNumber, token: CredentialsToken) -> PeerBuilder
Starts building a peer that was registered in a previous run of this process.
Sourcepub const fn version(&self) -> &VersionNumber
pub const fn version(&self) -> &VersionNumber
The OCPI version agreed with this peer.
Sourcepub const fn token(&self) -> &CredentialsToken
pub const fn token(&self) -> &CredentialsToken
The credentials token to authenticate requests to this peer with.
Sourcepub const fn versions_url(&self) -> Option<&Url>
pub const fn versions_url(&self) -> Option<&Url>
The peer’s /versions endpoint.
Sourcepub fn parties(&self) -> &[PartyRef]
pub fn parties(&self) -> &[PartyRef]
The parties this peer speaks for, from the roles of its credentials.
Sourcepub const fn hub(&self) -> Option<&PartyRef>
pub const fn hub(&self) -> Option<&PartyRef>
The hub this peer routes through, if it declared one.
Sourcepub fn set_quirks(&mut self, quirks: Quirks)
pub fn set_quirks(&mut self, quirks: Quirks)
Replaces the interoperability profile.
Sourcepub fn set_token(&mut self, token: CredentialsToken)
pub fn set_token(&mut self, token: CredentialsToken)
Replaces the credentials token, as a credentials PUT does.
Sourcepub fn implements(&self, module: &ModuleId, role: InterfaceRole) -> bool
pub fn implements(&self, module: &ModuleId, role: InterfaceRole) -> bool
Whether the peer implements a module in a given role.
Sourcepub fn endpoint_url(
&self,
module: &ModuleId,
role: InterfaceRole,
) -> Option<&Url>
pub fn endpoint_url( &self, module: &ModuleId, role: InterfaceRole, ) -> Option<&Url>
The peer’s URL for a module and role.
Module identifiers are matched case-insensitively when
Quirks::case_insensitive_module_ids is on, which matters for the Booking module.
Sourcepub fn sender(&self, module: &ModuleId) -> Option<SenderEndpoint>
pub fn sender(&self, module: &ModuleId) -> Option<SenderEndpoint>
The Sender-interface endpoint of a module.
Sourcepub fn receiver(&self, module: &ModuleId) -> Option<ReceiverEndpoint>
pub fn receiver(&self, module: &ModuleId) -> Option<ReceiverEndpoint>
The Receiver-interface endpoint of a module.
Sourcepub fn credentials_url(&self) -> Option<&Url>
pub fn credentials_url(&self) -> Option<&Url>
The credentials endpoint, ignoring the advertised role as the specification instructs.
Sourcepub fn endpoints(
&self,
) -> impl Iterator<Item = (&ModuleId, InterfaceRole, &Url)>
pub fn endpoints( &self, ) -> impl Iterator<Item = (&ModuleId, InterfaceRole, &Url)>
Every endpoint the peer advertised.
Sourcepub fn update_endpoints(&mut self, details: &VersionDetails)
pub fn update_endpoints(&mut self, details: &VersionDetails)
Replaces the endpoint map from freshly fetched version details.
A credentials PUT requires this: “The server must fetch the client’s endpoints again,
even if the version has not changed.”
Sourcepub fn routing_for(&self, party: Option<&PartyRef>) -> RoutingScenario
pub fn routing_for(&self, party: Option<&PartyRef>) -> RoutingScenario
The routing scenario for a direct request to party, or an open request when the
destination is unknown.
Sourcepub fn default_party(&self) -> Option<&PartyRef>
pub fn default_party(&self) -> Option<&PartyRef>
The party to address a functional request to, when the caller did not name one.
A peer that speaks for exactly one party needs no explicit to.