Struct cwmanage::Client [−][src]
pub struct Client { /* fields omitted */ }
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]
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
Creates a new client using the default values
pub fn build(&self) -> Client
[src]
Builds (finalizes the client)
pub fn api_version(self, api_version: String) -> Client
[src]
overrides the default api_version
pub fn api_url(self, api_url: String) -> Client
[src]
overrides the default api_url
pub fn codebase(self, codebase: String) -> Client
[src]
overrides the default codebase
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_custom_field(&self, path: &str, field: &str) -> Result<Option<Value>>
[src]
This will get a custom field Value, it helps with some of the juggleing of all of the custom fields that get returned
Arguments
path
- The ’path“ is the exact url to the object (/projects/project/123
, etc).field
- The field we want to update (also known as the “Caption”)
Example
getting a field
use cwmanage::Client; use serde_json::json; // 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 path = "/project/projects/1799"; let field_name = "EPL"; let expected = Some(json!(false)); let result = client.get_custom_field(path, field_name); assert_eq!(result.unwrap(), expected);
pub fn patch_custom_field(
&self,
path: &str,
field: &str,
value: &str
) -> Result<()>
[src]
&self,
path: &str,
field: &str,
value: &str
) -> Result<()>
This will Patch a custom field, this abstracts out some of the operations.
Arguments
path
- The ’path“ is the exact url to the object (/projects/project/123
, etc).field
- The field we want to update (also known as the “Caption”)value
- The value we want to update it to. This is sent as a string and then parsed to the appropriate datatype (ie it is sent as json). Example “1234” for1234
, “true” fortrue
, etc
Example
updating a field
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 path = "/project/projects/1799"; let field_name = "EPL"; let field_value = "false"; let expected = (); let result = client.patch_custom_field(path, field_name, field_value); assert_eq!(result.unwrap(), expected);
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);
pub fn post(&self, path: &str, body: String) -> Result<Value>
[src]
POSTS a body to an api endpoint The expected return is the object was created If an error occurs (api level, not http level) it will return an error message
Arguments
path
- the api path you want to retrieve (example/service/info
)body
- the body of the post (see api docs for details). formated as json
Example
see main docs
pub fn patch(
&self,
path: &str,
op: PatchOp,
patch_path: &str,
value: Value
) -> Result<Value>
[src]
&self,
path: &str,
op: PatchOp,
patch_path: &str,
value: Value
) -> Result<Value>
Patch (aka updated) to provided patch_path
(field) on the object specified by path
The expected return is the new version of the object that was modified
If an error occurs (api level, not http level) it will return an error message
Arguments
path
- the api path you want to retrieve (example/service/info
)op
- one fo the allowedPatchOp
values (Add | Replace | Remove)path_path
- field you want to modify (examplesummmary
,member/id
)value
- the value you want to update (exampleNew Name
)
Example
see main docs
Trait Implementations
impl StructuralPartialEq for Client
[src]
impl StructuralPartialEq for Client
[src]Auto Trait Implementations
impl RefUnwindSafe for Client
impl RefUnwindSafe for Client
impl UnwindSafe for Client
impl UnwindSafe for Client
Blanket Implementations
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]