PX::API::Response - A Peekshows Web Services API response.


PX-API documentation Contained in the PX-API distribution.

Index


Code Index:

NAME

Top

PX::API::Response - A Peekshows Web Services API response.

SYNOPSIS

Top

    use PX::API;

    my $px = PX::API->new({
                        api_key => '13243432434',  #Your api key
                        secret  => 's33cr3tttt',   #Your api secret
                        });

    my $response = $px->call('px.test.echo',{
					arg1 => 'val1',
					arg2 => 'val2',
					});




DESCRIPTION

Top

A response object from the Peekshows Web Services API. PX::API::Response is a subclass of HTTP::Response allowing for access to any response parameters. Module::Pluggable::Object is used to allow an extensible 'plugin' style method for loading response modules.

CONFIGURATION AND ENVIRONMENT

Top

Along with the response parameters available from HTTP::Response, the following parameters are added for API responses.

success

Set to a 1 or 0 to signify response success or error respectively.

response

The actual content of the response returned from the API call.

err_code

The error code returned from the API call, if an error occurred.

err_string

A description of the error returned from the API call, if an error occurred.

RESPONSE PLUGINS

Top

A response plugin is simply a module that transforms the API response format into a usable perl object. Obviously this is not always necessary and the original structure is always available via $response-{_content}>.

Response plugins are required to have to following methods available via its public api:

format()

The format() method is used by PX::API::Response to match a plugin with the format argument sent to the Peekshows API. This method simply needs to return the name of the plugin format. ie: 'rest', 'json'

parse($content)

The parse() method is called upon completion of an API call and is passed the _content returned from the call. This method need only return the perl object which was created from parsing the content.

DEPENDENCIES

Top

HTTP::Response Module::Pluggable

SEE ALSO

Top

PX::API http://www.peekshows.com http://services.peekshows.com

AUTHOR

Top

Anthony Decena <anthony@1bci.com>

LICENCE AND COPYRIGHT

Top


PX-API documentation Contained in the PX-API distribution.

package PX::API::Response;
use warnings;
use strict;
use Carp;

use version; our $VERSION = qv('0.0.3');

use HTTP::Response;
our @ISA = qw(HTTP::Response);

use Module::Pluggable::Fast
	name => 'response_plugins',
	search => [ qw/PX::API::Response/ ];


sub new {
	my $class = shift;
	my $args  = shift;

	my $self = HTTP::Response->new();
	return bless $self, $class;
	}

sub _init {
	my $self = shift;
	my $args = shift;
	my $format = $args->{'format'} || "rest";

	my @classes = $self->response_plugins;
	foreach my $c(@classes) {
		if ($c->format eq $format) {
			$self->{'parser'} = $c;
			last;
			}
		}
	return $self;
	}

sub fault {
	my ($self,$err_code,$err_string) = @_;
	$self->{success} = 0;
	$self->{err_code} = $err_code;
	$self->{err_string} = $err_string;
	}

sub success {
	my ($self,$ref) = @_;
	$self->{success} = 1;
	$self->{response} = $ref;
	}


1;
__END__