package API::ParallelsWPB::Response; use strict; use warnings; use JSON::XS qw/decode_json/; # ABSTRACT: processing of API responses our $VERSION = '0.03'; # VERSION our $AUTHORITY = 'cpan:IMAGO'; # AUTHORITY sub new { my ( $class, $res ) = @_; my $success = $res->is_success; my $status = $res->status_line; my ( $json_content, $response, $error ); if ( $success ) { $json_content = $res->content; $response = decode_json( $json_content )->{response} if $json_content; } else { my $error_json = $res->content; eval { $error = decode_json( $error_json )->{error}->{message}; 1; } or do { $error = $error_json }; } return bless( { success => $success, json => $json_content, error => $error, response => $response, status => $status }, $class ); } sub json { my $self = shift; return $self->{json}; } sub success { my $self = shift; return $self->{success}; } sub response { my $self = shift; return $self->{response}; } sub status { my $self = shift; return $self->{status}; } sub error { my $self = shift; return $self->{error}; } 1; __END__ =pod =encoding UTF-8 =head1 NAME API::ParallelsWPB::Response - processing of API responses =head1 VERSION version 0.03 =head1 METHODS =head2 B Creates new API::ParallelsWPB::Response object. $res - HTTP::Response object. =head2 B Returns original JSON answer. =head2 B Returns 1 if request succeeded, 0 otherwise. =head2 B Returns munged response from service. According to method, it can be scalar, hashref of arrayref. =head2 B Returns response status line. =head2 B Returns munged error text. =head1 SEE ALSO L L L =head1 AUTHORS =over 4 =item * Alexander Ruzhnikov =item * Polina Shubina =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2014 by REG.RU LLC. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut