NAME
Zenoss::Response - Handles responses from Zenoss::Router
SYNOPSIS
use Zenoss;
use Data::Dumper;
# Create a Zenoss object
my $api = Zenoss->connect(
{
username => 'admin',
password => 'zenoss',
url => 'http://zenossinstance:8080',
}
);
# Issue a request to get all devices from Zenoss
my $response = $api->device_getDevices();
# $response is now an instance of Zenoss::Response
# now we can do things like
print $response->json();
print $response->http_code();
# get the response in hashref form
my $response_hash = $response->hash();
print Dumper $response_hash;
DESCRIPTION
This module is NOT instantiated directly. When the Zenoss API issues a response to a request initiated by Zenoss::Router, a Zenoss::Response instance is created. To call methods from this module create an instance of Zenoss and issue a request to the Zenoss API.
Please review the SYNOPSIS for examples.
ATTRIBUTES
Attributes can be retrieved by calling $obj->attribute.
transaction_id
This attribute is set upon the creation of Zenoss::Response by Zenoss::Router. Each request issued to the Zenoss API is coded with a transaction_id (tid). The response transaction_id should match the transaction_id of the inital request. This attribute is provided to allow the ability to check if the request transaction id matches response transaction id. This may not be greatly important now, but will show its value once composite transactions are supported by Zenoss (IE send multiple requests in one call).
METHODS
$obj->json()
Returns the response, from the Zenoss API request, in JSON format.
$obj->hash()
Returns the response, from the Zenoss API request, in a PERL hashref.
$obj->raw_response()
Returns a textual representation of the response.
$obj->http_code()
Returns a 3 digit number that encodes the overall outcome of a HTTP response.
For example 200, for OK.
$obj->http_code_description()
Returns a short human readable single line string that explains the response code.
For example, OK.
$obj->http_status()
Returns the string "<http_code> <http_code_description>". If the http_code_description attribute is not set then the official name of <code> (see HTTP::Status) is substituted.
$obj->is_success()
Returns true if the response was successful.
See HTTP::Status for the meaning of these.
$obj->is_error()
Returns true if the response had an error.
See HTTP::Status for the meaning of these.
$obj->error_as_HTML()
Returns a string containing a complete HTML document indicating what error occurred. This method should only be called when $obj->is_error is TRUE.
$obj->header()
This is used to get header values and it is inherited from HTTP::Headers via HTTP::Message.
$obj->request_time()
Calculates the "current age" of the response as specified by RFC 2616 section 13.2.3. The age of a response is the time since it was sent by the origin server. The returned value is a number representing the age in seconds.
$obj->transaction_id()
Returns the transaction_id (tid) of the request to the Zenoss API. This can be compared to the tid in $obj->json() or $obj->hash(); Zenoss should return the same tid that was sent in the inital request.
SEE ALSO
AUTHOR
Patrick Baker <patricksbaker@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Patrick Baker <patricksbaker@gmail.com>
This module is free software: you can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You can obtain the Artistic License 2.0 by either viewing the LICENSE file provided with this distribution or by navigating to http://opensource.org/licenses/artistic-license-2.0.php.