| 1 | package WebService::Bonusly::Service; | ||||||||||||||||||||||||||||||||
| 2 | 1 | $WebService::Bonusly::Service::VERSION = '1.001'; | |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | # ABSTRACT: A utility class for WebService::Bonusly services | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | has ws => ( | |||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 14 | isa => 'WebService::Bonusly', | ||||||||||||||||||||||||||||||||
| 15 | required => 1, | ||||||||||||||||||||||||||||||||
| 16 | weak_ref => 1, | ||||||||||||||||||||||||||||||||
| 17 | handles => [ qw( token base_url ua _json_flags print_debug ) ], | ||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 97 | ▶ | sub _perform_action { | ||||||||||||||||||||||||||||||
|
Subroutine
_perform_action: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||
| 21 | 97 | my ($self, $method, $path_info, $params, $tokenless) = @_; | |||||||||||||||||||||||||||||||
| 22 | 97 | my %clean = %$params; | |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | 97 | my $res; | |||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | 97 | my $path = $self->base_url . $path_info; | |||||||||||||||||||||||||||||||
| 27 | 97 | $path =~ s/:(\w+)/delete $clean{$1}/ge; | |||||||||||||||||||||||||||||||
| 28 | 97 | ▶ | if ($method eq 'GET' || $method eq 'DELETE') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$method eq "GET" or $method eq "DELETE"
MC/DC100%2/2
$method eq "GET" or $method eq "DELETE"
$method eq "GET"
$method eq "DELETE"
Truth table100%3/3
A or B
A= $method eq "GET"B= $method eq "DELETE"
| |||||||||||||||||||||||||||||||||
| 29 | 68 | $path .= '?'; | |||||||||||||||||||||||||||||||
| 30 | 68 | ▶ | $path .= 'access_token=' . $self->token unless $tokenless; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 31 | 68 | for my $k (sort keys %clean) { | |||||||||||||||||||||||||||||||
| 32 | 174 | my $v = $clean{$k}; | |||||||||||||||||||||||||||||||
| 33 | 174 | $path .= '&' . uri_escape($k) . '=' . uri_escape($v); | |||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | 68 | $self->print_debug("SEND>> $method $path"); | |||||||||||||||||||||||||||||||
| 37 | 68 | ▶ | if ($method eq 'GET') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 66 | $res = $self->ua->get($path); | |||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||
| 41 | 2 | $res = $self->ua->delete($path); | |||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||
| 44 | ▶ | elsif ($method eq 'POST' || $method eq 'PUT') { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$method eq "POST" or $method eq "PUT"
MC/DC0%0/2
$method eq "POST" or $method eq "PUT"
$method eq "POST"
$method eq "PUT"
Truth table66%2/3
A or B
A= $method eq "POST"B= $method eq "PUT"
| |||||||||||||||||||||||||||||||||
| 45 | 29 | ▶ | $path .= '?access_token=' . $self->token unless $tokenless; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 46 | 29 | my $content = to_json(\%clean, $self->_json_flags); | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 29 | $self->print_debug("SEND>> $method $path"); | |||||||||||||||||||||||||||||||
| 49 | 29 | $self->print_debug("SEND>> Content-Type: application/json"); | |||||||||||||||||||||||||||||||
| 50 | 29 | $self->print_debug("SEND>> $content"); | |||||||||||||||||||||||||||||||
| 51 | 29 | ▶ | if ($method eq 'POST') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 16 | $res = $self->ua->post($path, 'Content-Type' => 'application/json', Content => $content); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||||||
| 55 | 13 | $res = $self->ua->put($path, 'Content-Type' => 'application/json', Content => $content); | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||
| 59 | 0 | die "Bad Method " . $method; | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | 97 | $self->print_debug("RECV>> ", $res->content); | |||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 97 | ▶ | try { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 65 | 97 | from_json($res->content); | |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | } catch { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 67 | +{ | ||||||||||||||||||||||||||||||||
| 68 | 0 | success => JSON::false, | |||||||||||||||||||||||||||||||
| 69 | message => $res->message, | ||||||||||||||||||||||||||||||||
| 70 | content => $res->content, | ||||||||||||||||||||||||||||||||
| 71 | status => $res->code, | ||||||||||||||||||||||||||||||||
| 72 | response_object => $res, | ||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | 97 | }; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||