| 1 | package WebService::Walmart::Request; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use HTTP::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use WebService::Walmart::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | $Webservice::Walmart::Request::VERSION = "0.01"; | |||||||||
| 11 | |||||||||||
| 12 | 1 | has apiurl => ( is => 'rw', default => 'https://api.walmartlabs.com/v1'); | |||||||||
| 13 | 0 | ▶ | has ua => ( is => 'rw', default => sub { HTTP::Tiny->new(agent => "WebService-Walmart/$Webservice::Walmart::Request::VERSION"); },); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 14 | 1 | has api_key => ( is => 'rw'); | |||||||||
| 15 | 1 | has output => ( is => 'rw', default => 'json'); | |||||||||
| 16 | 1 | has debug => ( is => 'rw', default => 0); | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub _get { | ||||||||
|
Subroutine
_get: not called CC=5 SCAR=34.0
| |||||||||||
| 20 | 0 | my ($self, $path) = @_; | |||||||||
| 21 | 0 | my @caller = caller(1); | |||||||||
| 22 | |||||||||||
| 23 | 0 | my $full_url = $self->apiurl . "$path&format=".$self->output . "&apiKey=" . $self->api_key; | |||||||||
| 24 | 0 | ▶ | print "DEBUG: full_url is $full_url\n" if $self->debug; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | my $response = $self->ua->request('GET', $full_url); | |||||||||
| 27 | |||||||||||
| 28 | # build us a an exception if the request was not successful | ||||||||||
| 29 | # if we were called in an eval block, we need to go higher up the stack | ||||||||||
| 30 | 0 | ▶ | @caller = caller(2) if $caller[3] eq '(eval)'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if ( $response->{success} != 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | WebService::Walmart::Exception->throw({ | ||||||||||
| 34 | method => $caller[3], | ||||||||||
| 35 | message => "HTTP Request to " . $self->apiurl . " failed", | ||||||||||
| 36 | code => $response->{status}, | ||||||||||
| 37 | reason => $response->{reason}, | ||||||||||
| 38 | 0 | filename => $caller[1], | |||||||||
| 39 | linenum => $caller[2], | ||||||||||
| 40 | }); | ||||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | print "Response from _get() ", Dumper $response if ($self->debug); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | return($response); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 1 | 1; | |||||||||
| 48 | |||||||||||
| 49 | =pod | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | =head1 SYNOPSIS | ||||||||||
| 53 | |||||||||||
| 54 | This module is responsible for the HTTPS requests to the Walmart API. It is a Moose Role and | ||||||||||
| 55 | cannot be instantiated. | ||||||||||
| 56 | |||||||||||
| 57 | You probably shouldn't be calling this directly | ||||||||||
| 58 | |||||||||||
| 59 | =cut | ||||||||||