| 1 | package WebService::Walmart; | ||||||||||
| 2 | # ABSTRACT: Interface to Walmart's open API | ||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | $WebService::Walmart::VERSION = "0.01"; | |||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use JSON::MaybeXS qw/ decode_json /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use WebService::Walmart::Store; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use WebService::Walmart::Item; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use WebService::Walmart::Review; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use WebService::Walmart::Taxonomy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | #use WebService::Walmart::Exception; | ||||||||||
| 18 | 1 | with 'WebService::Walmart::Request'; | |||||||||
| 19 | |||||||||||
| 20 | 0 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my $self = shift; | |||||||||
| 22 | } | ||||||||||
| 23 | # Lookup API | ||||||||||
| 24 | 0 | ▶ | sub items { | ||||||||
|
Subroutine
items: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 0 | my ($self, $args) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $path = "/items/"; | |||||||||
| 28 | 0 | $path .= "$args->{id}?"; | |||||||||
| 29 | |||||||||||
| 30 | 0 | my $response = $self->_get($path); | |||||||||
| 31 | |||||||||||
| 32 | 0 | my $content = $response->{content}; | |||||||||
| 33 | 0 | my $status = $response->{status}; | |||||||||
| 34 | |||||||||||
| 35 | 0 | my $h = decode_json($content); | |||||||||
| 36 | #return $h; | ||||||||||
| 37 | 0 | my $item = WebService::Walmart::Item->new($h); | |||||||||
| 38 | 0 | return $item; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | # reviews API | ||||||||||
| 42 | 0 | ▶ | sub reviews { | ||||||||
|
Subroutine
reviews: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 43 | 0 | my ($self, $args) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $path = "/reviews/"; | |||||||||
| 46 | 0 | $path .= "$args->{id}?"; | |||||||||
| 47 | |||||||||||
| 48 | 0 | my $response = $self->_get($path); | |||||||||
| 49 | |||||||||||
| 50 | 0 | my $content = $response->{content}; | |||||||||
| 51 | 0 | my $status = $response->{status}; | |||||||||
| 52 | 0 | my $h = decode_json($content); | |||||||||
| 53 | 0 | my $r = $h->{reviews}; | |||||||||
| 54 | |||||||||||
| 55 | 0 | my @reviews; | |||||||||
| 56 | 0 | foreach my $store_json (@$r) { | |||||||||
| 57 | 0 | my $store = WebService::Walmart::Review->new($store_json); | |||||||||
| 58 | 0 | push @reviews, $store; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | return @reviews; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | # search API | ||||||||||
| 64 | 0 | ▶ | sub search { | ||||||||
|
Subroutine
search: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 65 | 0 | my ($self, $args) = @_; | |||||||||
| 66 | |||||||||||
| 67 | 0 | my $path = "/search?"; | |||||||||
| 68 | 0 | $path .= "query=$args->{query}?"; | |||||||||
| 69 | 0 | ▶ | $path .= "&facet=$args->{facet}" if ($args->{facet}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | ▶ | $path .= "&facet.filter=$args->{'facet.filter'}" if ($args->{'facet.filter'}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | |||||||||||
| 72 | 0 | my $response = $self->_get($path); | |||||||||
| 73 | |||||||||||
| 74 | 0 | my $content = $response->{content}; | |||||||||
| 75 | 0 | my $status = $response->{status}; | |||||||||
| 76 | |||||||||||
| 77 | 0 | my $h = decode_json($content); | |||||||||
| 78 | |||||||||||
| 79 | 0 | my $s = $h->{items}; | |||||||||
| 80 | |||||||||||
| 81 | 0 | my @searches; | |||||||||
| 82 | 0 | foreach my $search_json (@$s) { | |||||||||
| 83 | 0 | my $search = WebService::Walmart::Item->new($search_json); | |||||||||
| 84 | 0 | push @searches, $search; | |||||||||
| 85 | } | ||||||||||
| 86 | 0 | return @searches; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | # value of the data | ||||||||||
| 90 | 0 | ▶ | sub vod { | ||||||||
|
Subroutine
vod: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 91 | 0 | my $self = shift; | |||||||||
| 92 | |||||||||||
| 93 | 0 | my $path = "/vod?"; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my $response = $self->_get($path); | |||||||||
| 96 | |||||||||||
| 97 | 0 | my $content = $response->{content}; | |||||||||
| 98 | 0 | my $status = $response->{status}; | |||||||||
| 99 | |||||||||||
| 100 | 0 | my $h = decode_json($content); | |||||||||
| 101 | # return $h; | ||||||||||
| 102 | 0 | my $item = WebService::Walmart::Item->new($h); | |||||||||
| 103 | 0 | return $item; | |||||||||
| 104 | } | ||||||||||
| 105 | |||||||||||
| 106 | # taxonomy | ||||||||||
| 107 | 0 | ▶ | sub taxonomy { | ||||||||
|
Subroutine
taxonomy: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 108 | 0 | my $self = shift; | |||||||||
| 109 | |||||||||||
| 110 | 0 | my $path = "/taxonomy?"; | |||||||||
| 111 | |||||||||||
| 112 | 0 | my $response = $self->_get($path); | |||||||||
| 113 | |||||||||||
| 114 | 0 | my $content = $response->{content}; | |||||||||
| 115 | 0 | my $status = $response->{status}; | |||||||||
| 116 | |||||||||||
| 117 | 0 | my $h = decode_json($content); | |||||||||
| 118 | 0 | my $s = $h->{categories}; | |||||||||
| 119 | 0 | my @taxonomy; | |||||||||
| 120 | 0 | foreach my $taxonomy_json (@$s) { | |||||||||
| 121 | 0 | my $tax = WebService::Walmart::Taxonomy->new($taxonomy_json); | |||||||||
| 122 | 0 | push @taxonomy, $tax; | |||||||||
| 123 | } | ||||||||||
| 124 | 0 | return @taxonomy; | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | # store locators | ||||||||||
| 128 | 0 | ▶ | sub stores { | ||||||||
|
Subroutine
stores: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 129 | 0 | my ($self, $args) = @_; | |||||||||
| 130 | |||||||||||
| 131 | 0 | my $path = "/stores?"; | |||||||||
| 132 | 0 | ▶ | $path .= "lat=$args->{lat}" if ($args->{lat}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 133 | 0 | ▶ | $path .= "lon=$args->{lon}" if ($args->{lon}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | 0 | ▶ | $path .= "city=$args->{city}" if ($args->{city}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 135 | 0 | ▶ | $path .= "zip=$args->{zip}" if ($args->{zip}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | |||||||||||
| 137 | 0 | my $response = $self->_get($path); | |||||||||
| 138 | |||||||||||
| 139 | 0 | my $content = $response->{content}; | |||||||||
| 140 | 0 | my $status = $response->{status}; | |||||||||
| 141 | 0 | my $success = $response->{success}; | |||||||||
| 142 | 0 | my $reason = $response->{reason}; | |||||||||
| 143 | |||||||||||
| 144 | 0 | my $h = decode_json($content); | |||||||||
| 145 | 0 | my @stores; | |||||||||
| 146 | 0 | foreach my $store_json (@$h) { | |||||||||
| 147 | 0 | my $store = WebService::Walmart::Store->new($store_json); | |||||||||
| 148 | 0 | push @stores, $store; | |||||||||
| 149 | } | ||||||||||
| 150 | 0 | return @stores; | |||||||||
| 151 | } | ||||||||||
| 152 | |||||||||||
| 153 | # trending api | ||||||||||
| 154 | 0 | ▶ | sub trends { | ||||||||
|
Subroutine
trends: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 155 | 0 | my $self = shift; | |||||||||
| 156 | |||||||||||
| 157 | 0 | my $path = "/trends?"; | |||||||||
| 158 | |||||||||||
| 159 | 0 | my $response = $self->_get($path); | |||||||||
| 160 | |||||||||||
| 161 | 0 | my $content = $response->{content}; | |||||||||
| 162 | 0 | my $status = $response->{status}; | |||||||||
| 163 | |||||||||||
| 164 | 0 | my $h = decode_json($content); | |||||||||
| 165 | # return $h; | ||||||||||
| 166 | 0 | my $s = $h->{items}; | |||||||||
| 167 | |||||||||||
| 168 | 0 | my @trends; | |||||||||
| 169 | 0 | foreach my $search_json (@$s) { | |||||||||
| 170 | 0 | my $trend = WebService::Walmart::Item->new($search_json); | |||||||||
| 171 | 0 | push @trends, $trend; | |||||||||
| 172 | } | ||||||||||
| 173 | 0 | return @trends; | |||||||||
| 174 | } | ||||||||||
| 175 | |||||||||||
| 176 | 0 | ▶ | sub paginated { | ||||||||
|
Subroutine
paginated: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 177 | 0 | my $self = shift; | |||||||||
| 178 | } | ||||||||||
| 179 | |||||||||||
| 180 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 181 | 1 | 1; | |||||||||
| 182 | |||||||||||
| 183 | =pod | ||||||||||
| 184 | |||||||||||
| 185 | |||||||||||
| 186 | =head1 SYNOPSIS | ||||||||||
| 187 | |||||||||||
| 188 | WebService::Walmart - Generic API to Walmart Labs Open API | ||||||||||
| 189 | |||||||||||
| 190 | =head1 DESCRIPTION | ||||||||||
| 191 | |||||||||||
| 192 | WebService::Walmart is an experimental Perl interface to the Walmart Open API. | ||||||||||
| 193 | While this module will attempt to implement the full API, the Walmart API is in heavy | ||||||||||
| 194 | development, and this module is still figuring out how to implement it. | ||||||||||
| 195 | |||||||||||
| 196 | In order to use the API, you will need to sign up for an account and get an API key | ||||||||||
| 197 | located at https://developer.walmartlabs.com/ | ||||||||||
| 198 | |||||||||||
| 199 | B<NOTE:> This is an B<EXPERIMENTAL release>. The methods are subject to change. Walmart will most likely | ||||||||||
| 200 | change their data structures as they implement more of the API. | ||||||||||
| 201 | |||||||||||
| 202 | In order to use the methods below, you will first need to create an instance of this module to work with. | ||||||||||
| 203 | |||||||||||
| 204 | my $walmart = WebService::Walmart->new( | ||||||||||
| 205 | api_key => '123456781234567812345678', | ||||||||||
| 206 | format => 'json', | ||||||||||
| 207 | debug => 0, | ||||||||||
| 208 | ); | ||||||||||
| 209 | |||||||||||
| 210 | |||||||||||
| 211 | =head1 METHODS | ||||||||||
| 212 | |||||||||||
| 213 | Every method in this module currently throws a fatal exception B<WebService::Walmart::Exception> on failure. You | ||||||||||
| 214 | will either want to wrap method calls with an L<eval> statement | ||||||||||
| 215 | or use something like L<Try::Tiny> or L<Try::Catch>. | ||||||||||
| 216 | |||||||||||
| 217 | =head2 stores | ||||||||||
| 218 | |||||||||||
| 219 | my @stores = $walmart->stores( | ||||||||||
| 220 | lat => 'latitude', | ||||||||||
| 221 | lon => 'longitude', | ||||||||||
| 222 | city => 'City Name', | ||||||||||
| 223 | zip => zipcode, | ||||||||||
| 224 | ); | ||||||||||
| 225 | |||||||||||
| 226 | Search the API for stores with the criteria supplied and return an array containing objects of L<WebService::Walmart::Store> | ||||||||||
| 227 | for stores based upon Latitude/Longitude, City Name, or Zipcode. | ||||||||||
| 228 | More information on the response data can be found at https://developer.walmartlabs.com/docs/read/Store_Locator_API | ||||||||||
| 229 | |||||||||||
| 230 | Example: | ||||||||||
| 231 | |||||||||||
| 232 | my @stores = $walmart->stores( zip=> 72716); | ||||||||||
| 233 | print $stores[0]->phoneNumber; | ||||||||||
| 234 | |||||||||||
| 235 | =head2 items | ||||||||||
| 236 | |||||||||||
| 237 | my $item = $walmart->item( id => itemid); | ||||||||||
| 238 | |||||||||||
| 239 | This method will search for an item based upon ID and return a scalar object containing L<WebService::Walmart::Item>. | ||||||||||
| 240 | |||||||||||
| 241 | Example: | ||||||||||
| 242 | |||||||||||
| 243 | my $item = $walmart->items( id => 42608121); | ||||||||||
| 244 | print $item->name; | ||||||||||
| 245 | |||||||||||
| 246 | =head2 reviews | ||||||||||
| 247 | |||||||||||
| 248 | $walmart->reviews( | ||||||||||
| 249 | id => itemid | ||||||||||
| 250 | ); | ||||||||||
| 251 | |||||||||||
| 252 | This method will retrieve the reviews for an item based up on ID and return an array of L<WebService::Walmart::Review>. | ||||||||||
| 253 | Example: | ||||||||||
| 254 | |||||||||||
| 255 | my @reviews = $walmart->reviews({ id => '42608121'}); | ||||||||||
| 256 | print $review[0]->name; | ||||||||||
| 257 | |||||||||||
| 258 | =head2 search | ||||||||||
| 259 | |||||||||||
| 260 | $walmart->search( | ||||||||||
| 261 | query => 'string', # a string to search for | ||||||||||
| 262 | categoryId => 1234, # a Category ID to search for. This should match the ID in the WebService::Walmart::Taxonomy package | ||||||||||
| 263 | facet => 'string', # enable facets | ||||||||||
| 264 | facet.filter => 'string', # filter to apply to the facets | ||||||||||
| 265 | ); | ||||||||||
| 266 | |||||||||||
| 267 | This method will search for items and return an array of L<Webservice::Walmart::Item>. | ||||||||||
| 268 | Example: | ||||||||||
| 269 | |||||||||||
| 270 | my @items = $walmart->search({ query => 'ipod'}); | ||||||||||
| 271 | print "the first item has ". $search[0]->numReviews . " reviews to read!\n"; | ||||||||||
| 272 | |||||||||||
| 273 | =head2 vod | ||||||||||
| 274 | |||||||||||
| 275 | $walmart->vod(); | ||||||||||
| 276 | |||||||||||
| 277 | This method will return the value of the day in scalar format. It will return a L<WebService::Walmart::Item> object. | ||||||||||
| 278 | Example: | ||||||||||
| 279 | |||||||||||
| 280 | my $vod = $walmart->vod(); | ||||||||||
| 281 | print "Today's Value of the Day is ". $vod->name . "\n"; | ||||||||||
| 282 | |||||||||||
| 283 | =head2 trends | ||||||||||
| 284 | |||||||||||
| 285 | $walmart->trends(); | ||||||||||
| 286 | |||||||||||
| 287 | Returns trending items on Walmart.com. This will be an array of L<WebService::Walmart::Item> objects. | ||||||||||
| 288 | Example: | ||||||||||
| 289 | |||||||||||
| 290 | my @trends = $walmart->trends(); | ||||||||||
| 291 | print "The big name in today's trends are ". $_->name . "\n" foreach @trends | ||||||||||
| 292 | |||||||||||
| 293 | =head2 taxonomy | ||||||||||
| 294 | |||||||||||
| 295 | $walmart->taxonomy(); | ||||||||||
| 296 | |||||||||||
| 297 | Returns a L<WebService::Walmart::Taxonomy> objects as an array. This is how Walmart.com categorizes items. | ||||||||||
| 298 | Example: | ||||||||||
| 299 | |||||||||||
| 300 | my @taxonomy = $walmart->taxonomy(); | ||||||||||
| 301 | use Data::Dumper; | ||||||||||
| 302 | print Dumper @taxonomy; | ||||||||||
| 303 | |||||||||||
| 304 | |||||||||||
| 305 | =head1 BUGS | ||||||||||
| 306 | |||||||||||
| 307 | There will likely be many. Please file a report and I'll fix it as soon as possible. | ||||||||||
| 308 | |||||||||||
| 309 | =head1 SEE ALSO | ||||||||||
| 310 | |||||||||||
| 311 | https://developer.walmartlabs.com/ | ||||||||||
| 312 | |||||||||||
| 313 | =cut | ||||||||||