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 keys
  • private_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]

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(&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]

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 allowed PatchOp values (Add | Replace | Remove)
  • path_path - field you want to modify (example summmary, member/id)
  • value - the value you want to update (example New Name)

Example

see main docs

Trait Implementations

impl Clone for Client[src]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.