Struct cwmanage::Client [−][src]
Connectwise client. Initinitialize with Client::new. Use Client::api_url, Client::api_version and Client::codebase to customize. The finalize with Client::build
company_id
is your short name (ie the one you use to login to CW)public_key
is obtained by creating an api member with keysprivate_key
is obtained by creating an api member with keys- the
client_id
is generated https://developer.connectwise.com/ClientID
Implementations
impl Client
[src]
pub fn new(
company_id: String,
public_key: String,
private_key: String,
client_id: String
) -> Client
[src]
company_id: String,
public_key: String,
private_key: String,
client_id: String
) -> Client
pub fn build(&self) -> Client
[src]
pub fn api_version(self, api_version: String) -> Client
[src]
pub fn api_url(self, api_url: String) -> Client
[src]
pub fn codebase(self, codebase: String) -> Client
[src]
pub fn get_single(&self, path: &str, query: &[(&str, &str)]) -> Result<Value>
[src]
GETs a path from the connectwise api. get_single
is only used on certain api endpoints.
It is expecting the response from the connectwise api to be a single “object” and not a list
like it normally returns
Arguments
path
- the api path you want to retrieve (example/service/info
)query
- additional query options must be set. If non, use [(“”, “”)]
Known Endpoints
- /system/info
Example
Basic get, returning parsed json
use cwmanage::Client; // this example is using dotenv to load our settings from // the environment, you could also specify this manually use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("", "")]; let path = "/system/info"; let result = client.get_single(&path, &query).unwrap(); assert_eq!(&result["isCloud"], true);
Basic get, take parsed json and convert to a struct
use cwmanage::Client; use serde::{Deserialize}; #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] struct SystemInfo { version: String, is_cloud: bool, server_time_zone: String, } // this example is using dotenv to load our settings from // the environment, you could also specify this manually use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("", "")]; let path = "/system/info"; let result = client.get_single(&path, &query).unwrap(); // got our result, just like before. // now convert it into our struct let info: SystemInfo = serde_json::from_value(result).unwrap(); assert_eq!(info.is_cloud, true); assert_eq!(info.server_time_zone, "Eastern Standard Time");
pub fn get(&self, path: &str, query: &[(&str, &str)]) -> Result<Vec<Value>>
[src]
GETs a path from the connectwise api. get
will return all results so make sure you
set your query
with the appropriate conditions. This follows the api pagination so, again,
all results will be returned For example /service/tickets
will
return every ticket in the system. The result is a vec of
serde_json::value::Value
Arguments
path
- the api path you want to retrieve (example/service/tickets
)query
- additional query options must be set. If non, use [(“”, “”)]
Example
Getting all results, returning parsed json
use cwmanage::Client; // this example is using dotenv to load our settings from // the environment, you could also specify this manually use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("fields", "id")]; let path = "/system/members"; let result = client.get(&path, &query).unwrap(); assert!(result.len() > 30);
Getting all results, take parsed json and convert to a struct
use cwmanage::Client; use serde::{Deserialize}; use serde_json::Value::Array; #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] struct Member { id: i32, identifier: String, } // this example is using dotenv to load our settings from // the environment, you could also specify this manually use dotenv::dotenv; dotenv().ok(); let company_id: String = dotenv::var("CWMANAGE_COMPANY_ID").unwrap(); let public_key: String = dotenv::var("CWMANAGE_PUBLIC_KEY").unwrap(); let private_key: String = dotenv::var("CWMANAGE_PRIVATE_KEY").unwrap(); let client_id: String = dotenv::var("CWMANAGE_CLIENT_ID").unwrap(); let client = Client::new(company_id, public_key, private_key, client_id).build(); let query = [("", "")]; let path = "/system/members"; let result = client.get(&path, &query).unwrap(); // got our result, just like before. // now convert it into our struct let members: Vec<Member>= serde_json::from_value(Array(result)).unwrap(); assert_eq!(members.len(), 134);
Trait Implementations
impl Debug for Client
[src]
impl PartialEq<Client> for Client
[src]
impl StructuralPartialEq for Client
[src]
Auto Trait Implementations
impl RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnwindSafe for Client
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,