| 1 | package PagSeguro::API::Request; | ||||||||||
| 2 | 3 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 3 | ▶ | use PagSeguro::API::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # attributes | ||||||||||
| 9 | 1 | ▶ | has ua => (is => 'rw', default => sub { LWP::UserAgent->new }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | has param => (is => 'rw', default => sub { {} }); | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | # method | ||||||||||
| 14 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 15 | 0 | my $self = shift; | |||||||||
| 16 | 0 | ▶ | my $args = (@_ % 2 == 0) ? {@_} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | # error (required) | ||||||||||
| 19 | 0 | ▶ | croak "url cannot be undefined" unless $args->{url}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | |||||||||||
| 21 | 0 | my $ua = $self->ua; | |||||||||
| 22 | 0 | my $res = $ua->get($args->{url}); | |||||||||
| 23 | 0 | return $self->_parse_response($res); | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub post { | ||||||||
|
Subroutine
post: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||
| 27 | 1 | my $self = shift; | |||||||||
| 28 | 1 | ▶ | my $args = (@_ % 2 == 0) ? {@_} : undef; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | # error (required) | ||||||||||
| 31 | 1 | ▶ | croak "url cannot be undefined" unless $args->{url}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 1 | my $ua = $self->ua; | |||||||||
| 34 | 1 | my $res = $ua->post($args->{url}, $args->{params}); | |||||||||
| 35 | |||||||||||
| 36 | 1 | return $self->_parse_response($res); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | ▶ | sub _parse_response { | ||||||||
|
Subroutine
_parse_response: called CC=2 SCAR=7.1
| |||||||||||
| 40 | 1 | my ($self, $res) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 1 | my $response = PagSeguro::API::Response->new; | |||||||||
| 43 | |||||||||||
| 44 | 1 | ▶ | if ($res->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $response->data($res->decoded_content); | |||||||||
| 46 | } | ||||||||||
| 47 | else { | ||||||||||
| 48 | 1 | $response->error($res->status_line); | |||||||||
| 49 | 1 | $response->data($res->decoded_content); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | return $response; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 3 | 1; | |||||||||