| Amazon-SimpleDB documentation | Contained in the Amazon-SimpleDB distribution. |
Amazon::SimpleDB::Response - a class representing a generic response from the SimpleDB service.
This is code is in the early stages of development. Do not consider it stable. Feedback and patches welcome.
This is a generic response class for the results of any request that does not require special handling. The class is the base class to specialized response classes such as Amazon::ErrorResponse and Amazon::QueryResponse.
Constructs an appropriate SimpleDB response object based on the HTTP::Response object provided. This method takes a required HASHREF with two required keys:
A HTTP::Response object or subclass this response from a request to the service.
A reference to the Amazon::SimpleDB account object this response is associated to.
A string defining the response type that is determined by the root element of the XML document that was returned.
Returns the HTTP::Response object used to construct this response object.
Returns the HTTP status code for the underlying response.
The parsed XML contents of the response.
Amazon::SimpleDB::ErrorResponse, Amazon::SimpleDB::GetAttributesResponse, Amazon::SimpleDB::ListDomainsResponse, Amazon::SimpleDB::QueryResponse
Please see the Amazon::SimpleDB manpage for author, copyright, and license information.
| Amazon-SimpleDB documentation | Contained in the Amazon-SimpleDB distribution. |
package Amazon::SimpleDB::Response; use strict; use warnings; use XML::Simple; use Carp qw( croak ); our %SPECIALS = ( 'ErrorResponse' => 1, 'ListDomainsResponse' => 1, 'GetAttributesResponse' => 1, 'QueryResponse' => 1, ); sub new { my $class = shift; my $args = shift || {}; croak "No account" unless $args->{account}; my $r = $args->{http_response}; croak 'No HTTP::Response object in http_response' unless ref $r && $r->isa('HTTP::Response'); my $tree; eval { my $content = $r->content; $tree = XMLin( $content, 'ForceArray' => ['Attribute', 'DomainName', 'ItemName'], 'KeepRoot' => 1 ); }; croak $@ if $@; my ($type) = keys %$tree; if ($r->is_error) { require Amazon::SimpleDB::ErrorResponse; $class = 'Amazon::SimpleDB::ErrorResponse'; } elsif ($SPECIALS{$type}) { $class = "Amazon::SimpleDB::${type}"; eval "use $class"; croak $@ if $@; } my $self = bless {}, $class; $self->{'account'} = $args->{account}; $self->{'http_response'} = $r; $self->{'http_status'} = $r->code; $self->{'content'} = $tree; $self->{'response_type'} = $type; if ($r->is_success) { # errors are stored differently $self->{'request_id'} = $tree->{$type}{ResponseMetadata}{RequestId}; $self->{'box_usage'} = $tree->{$type}{ResponseMetadata}{BoxUsage}; } return $self; } sub type { return $_[0]->{'response_type'} } sub http_response { return $_[0]->{'http_response'} } sub http_status { return $_[0]->{'http_status'} } sub content { return $_[0]->{'content'} } sub request_id { return $_[0]->{'request_id'} } sub box_usage { return $_[0]->{'box_usage'} } sub is_success { return $_[0]->{'http_response'}->is_success } sub is_error { return $_[0]->{'http_response'}->is_error } 1; __END__