File Coverage

blib/lib/WWW/KrispyKreme/HotLight.pm
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod n/a
total 23 24 95.8


line stmt bran cond sub pod time code
1             package WWW::KrispyKreme::HotLight;
2              
3 1     1   22276 use Mojo::Base -base;
  1         11321  
  1         7  
4 1     1   1072 use Mojo::UserAgent;
  1         251165  
  1         9  
5 1     1   33 use Mojo::JSON ();
  1         3  
  1         277  
6              
7             our $VERSION = '1.0';
8              
9             has 'where';
10              
11             has locations => \&_build_locations;
12              
13             sub _build_locations {
14 1     1   524 my ($self) = @_;
15 1 50       6 my $geo = $self->where or return [];
16              
17 1         20 my $search = {
18             Where => {
19             LocationTypes => ['Store', 'Commissary', 'Franchise'],
20             OpeningDate => {ComparisonType => 0}
21             },
22             # This is important. Otherwise we receive ALL locations.
23             Take => {Min => 3, DistanceRadius => 100},
24             PropertyFilters =>
25             {Attributes => ['FoursquareVenueId', 'OpeningType']},
26             };
27              
28 1         13 my $ua = Mojo::UserAgent->new;
29 1         6 my $hotlight_url = 'http://services.krispykreme.com/api/locationsearchresult/';
30 1         3 my $header = {'Referer' => 'http://www.krispykreme.com/Locate/Location-Search'};
31 1         7 my $form = {
32             lat => $geo->[0],
33             lng => $geo->[1],
34             responseType => 'Full',
35             search => Mojo::JSON::encode_json($search),
36             };
37              
38 1         433 my $json = $ua->get(
39             $hotlight_url => $header => form => $form,
40             )->res->json;
41              
42 1         396108 [map $_->{Location}, @$json];
43             }
44              
45             1;
46             __END__