The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Regru::API::Response - REG.API v2 response wrapper

VERSION

version 0.052

SYNOPSIS

    my $resp = Regru::API::Response->new(
        response => $response,
    );

ATTRIBUTES

is_service_fail

Flag to show whether or not the most last answer from the API service has not been finished with code HTTP 200.

    $resp = $client->bill->nop(bill_id => 123213);

    if ($resp->is_success) {
        print "It works!";
    }
    elsif ($resp->is_service_fail) {
        print "Reg.ru API is gone :(";
    }
    else {
        print "Error code: ". $resp->error_code;
    }

is_success

Flag to show whether or not the most last API request has been successful.

See example for "is_service_fail".

response

Contains a HTTP::Response object for the most last API request.

    if ($resp->is_service_fail) {
        print "HTTP code: " . $resp->response->code;
    }

answer

Contains decoded answer for the most last successful API request.

    if ($resp->is_success) {
        print Dumper($resp->answer);
    }

This is useful for debugging;

error_code

Contains error code for the most last API request if it has not been successful.

Full list error codes list is available at REG.API Common error codes.

error_text

Contains common error text for the most last API request if it has not been successful.

Default language is enlish. Language can be changed by passing option lang to the Regru::API constructor.

error_params

Contains additional parameters included into the common error text.

    $error_params = $resp->error_params;
    print "Details: " . $error_params->{error_detail};

debug

A few messages will be printed to STDERR. Default value is 0 (suppressed debug activity).

METHODS

new

Creates a response object from REG.API response. Available options:

response

Required. This should be a result of HTTP request to REG.API. In general, is a HTTP::Response object returned by LWP::UserAgent.

debug

Not required. Print some debugging messages to STDERR. Default value is 0. Because of this contructor invoked from Regru::API::Role::Client mainly so this option sets to the value which passed to Regru::API constructor.

get

Gets a value from stored in answer.

    $resp = $client->user->get_statistics;
    print "Account balance: " . $resp->get("balance_total");

SEE ALSO

Regru::API

Regru::API::Role::Client

Regru::API::Role::Serializer

Regru::API::Role::Loggable

HTTP::Response

LWP::UserAgent

REG.API Common error codes

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/regru/regru-api-perl/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHORS

  • Polina Shubina <shubina@reg.ru>

  • Anton Gerasimov <a.gerasimov@reg.ru>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 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.