From 678284c829e661e513f18cf78da989c3853d4b96 Mon Sep 17 00:00:00 2001 From: Octavio Simone Date: Sun, 27 Aug 2023 21:09:14 +0200 Subject: [PATCH] add doc tests --- src/provisioning/mod.rs | 144 +++++++++++++++++++++++++++++++++++++ src/provisioning/models.rs | 4 +- 2 files changed, 146 insertions(+), 2 deletions(-) diff --git a/src/provisioning/mod.rs b/src/provisioning/mod.rs index b13dc81..51511fc 100644 --- a/src/provisioning/mod.rs +++ b/src/provisioning/mod.rs @@ -16,37 +16,181 @@ use crate::{ }; #[async_trait] +/// This trait contains all methods for customer provisioning. +/// To use this trait, you need to create a client in `Provisioning` state. +/// +/// ```no_run +/// +/// use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; +/// +/// #[tokio::main] +/// async fn main() { +/// // the client only requires passing the base url and a provisioning token +/// // other API calls are *not* supported in this state. +/// let dracoon = Dracoon::builder() +/// .with_base_url("https://dracoon.team") +/// .with_provisioning_token("some_token") +/// .build_provisioning() +/// .unwrap(); +/// +/// // now you can use the client in provisioning state +/// let customers = dracoon.get_customers(None).await.unwrap(); +/// +/// } pub trait CustomerProvisioning { + /// Returns a list of customers + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let customers = dracoon.get_customers(None).await.unwrap(); + /// # } async fn get_customers( &self, params: Option, ) -> Result; + /// Creates a new customer + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning, provisioning::{FirstAdminUser, NewCustomerRequest}}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let first_admin = FirstAdminUser::new_local("admin", "admin", None, "admin@localhost", None); + /// let customer = NewCustomerRequest::builder("pay", 100000, 100, first_admin).build(); + /// let customer = dracoon.create_customer(customer).await.unwrap(); + /// # } async fn create_customer( &self, req: NewCustomerRequest, ) -> Result; + /// Gets a customer by id + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning, provisioning::{FirstAdminUser, NewCustomerRequest}}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let customer = dracoon.get_customer(123, None).await.unwrap(); + /// + /// // include attributes + /// let customer = dracoon.get_customer(123, Some(true)).await.unwrap(); + /// # } async fn get_customer( &self, id: u64, include_attributes: Option, ) -> Result; + /// Updates a customer by id + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning, provisioning::UpdateCustomerRequest}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// + /// let update = UpdateCustomerRequest::builder() + /// .with_company_name("Foo Inc.") + /// .build(); + + /// let customer = dracoon.update_customer(123, update).await.unwrap(); + /// + /// # } async fn update_customer( &self, id: u64, req: UpdateCustomerRequest, ) -> Result; + /// Deletes a customer by id + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// + /// dracoon.delete_customer(123).await.unwrap(); + /// + /// # } async fn delete_customer(&self, id: u64) -> Result<(), DracoonClientError>; + /// Returns a list of customer users + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let users = dracoon.get_customer_users(123, None).await.unwrap(); + /// # } async fn get_customer_users(&self, id: u64, params: Option) -> Result; + /// Returns a list of customer attributes + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let attributes = dracoon.get_customer_attributes(123, None).await.unwrap(); + /// # } async fn get_customer_attributes( &self, id: u64, params: Option, ) -> Result; + /// Updates / sets customer attributes + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning, provisioning::CustomerAttributes}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// let mut attributes = CustomerAttributes::new(); + /// attributes.add_attribute("foo", "bar"); + /// let customer = dracoon.update_customer_attributes(123, attributes).await.unwrap(); + /// # } async fn update_customer_attributes( &self, id: u64, req: CustomerAttributes, ) -> Result; + /// Deletes customer attribute by key + /// ```no_run + /// # use dco3::{Dracoon, OAuth2Flow, CustomerProvisioning}; + /// # #[tokio::main] + /// # async fn main() { + /// # let dracoon = Dracoon::builder() + /// # .with_base_url("https://dracoon.team") + /// # .with_provisioning_token("some_token") + /// # .build_provisioning() + /// # .unwrap(); + /// dracoon.delete_customer_attribute(123, "foo".to_string()).await.unwrap(); + /// # } async fn delete_customer_attribute( &self, id: u64, diff --git a/src/provisioning/models.rs b/src/provisioning/models.rs index e3e2f1a..94fd65d 100644 --- a/src/provisioning/models.rs +++ b/src/provisioning/models.rs @@ -14,8 +14,8 @@ impl CustomerAttributes { CustomerAttributes::default() } - pub fn add_attribute(&mut self, key: String, value: String) { - let attrib = KeyValueEntry { key, value }; + pub fn add_attribute(&mut self, key: impl Into, value: impl Into) { + let attrib = KeyValueEntry { key: key.into(), value: value.into() }; self.items.push(attrib); } }