[][src]Struct cp_api::Response

pub struct Response {
    pub data: Value,
    pub objects: Vec<Value>,
    // some fields omitted
}

A Response from the API.

Fields

data: Value

Contains the JSON value from the API after running a call.

objects: Vec<Value>

Contains the JSON value from the API after running a query.

Methods

impl Response[src]

pub fn status(&self) -> u16[src]

Get the status of this Response.

Reference: IANA HTTP Status Codes

let res = client.call("show-host", json!({"name": "host1"}))?;
if res.is_success() {
    println!("host1 IP = {}", res.data["ipv4-address"]);
}
else if res.is_client_error() {
    eprintln!("Client error");
}
else if res.is_server_error() {
    eprintln!("Server error");
}

pub fn is_informational(&self) -> bool[src]

Check if the status is between 100-199.

pub fn is_success(&self) -> bool[src]

Check if the status is between 200-299.

pub fn is_not_success(&self) -> bool[src]

Check if the status is not successful.

pub fn is_redirection(&self) -> bool[src]

Check if the status is between 300-399.

pub fn is_client_error(&self) -> bool[src]

Check if the status is between 400-499.

pub fn is_server_error(&self) -> bool[src]

Check if the status is between 500-599.

pub fn url(&self) -> &str[src]

Get the URL of this Response.

let res = client.call("show-host", json!({"name": "host1"}))?;
assert_eq!(res.url() "https://192.168.1.10/web_api/show-host")

pub fn headers(&self) -> HashMap<String, String>[src]

Get the headers of this Response.

let login = client.login("user", "pass")?;
println!("{:#?}", login.headers());

pub fn save_data(&self, file: &str) -> Result<()>[src]

Save data from a call to a file.

let host = client.call("show-host", json!({"name": "host1"}))?;
host.save_data("/home/admin/host.txt")?;

pub fn save_objects(&self, file: &str) -> Result<()>[src]

Save objects from a query to a file.

let hosts = client.query("show-hosts", "standard")?;
hosts.save_objects("/home/admin/hosts.txt")?;

Trait Implementations

impl Debug for Response[src]

impl Serialize for Response[src]

Auto Trait Implementations

impl Send for Response

impl Sync for Response

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T