| 1 | package WWW::KrispyKreme::HotLight; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Mojo::Base -base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Mojo::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Mojo::JSON (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '1.0'; | |||||||||
| 8 | |||||||||||
| 9 | 1 | has 'where'; | |||||||||
| 10 | |||||||||||
| 11 | 1 | has locations => \&_build_locations; | |||||||||
| 12 | |||||||||||
| 13 | sub _build_locations { | ||||||||||
| 14 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_locations: called CC=2 SCAR=6.9
| |||||||||||
| 15 | 1 | ▶ | my $geo = $self->where or return []; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | 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 | my $ua = Mojo::UserAgent->new; | |||||||||
| 29 | 1 | my $hotlight_url = 'http://services.krispykreme.com/api/locationsearchresult/'; | |||||||||
| 30 | 1 | my $header = {'Referer' => 'http://www.krispykreme.com/Locate/Location-Search'}; | |||||||||
| 31 | 1 | my $form = { | |||||||||
| 32 | lat => $geo->[0], | ||||||||||
| 33 | lng => $geo->[1], | ||||||||||
| 34 | responseType => 'Full', | ||||||||||
| 35 | search => Mojo::JSON::encode_json($search), | ||||||||||
| 36 | }; | ||||||||||
| 37 | |||||||||||
| 38 | 1 | my $json = $ua->get( | |||||||||
| 39 | $hotlight_url => $header => form => $form, | ||||||||||
| 40 | )->res->json; | ||||||||||
| 41 | |||||||||||
| 42 | 1 | [map $_->{Location}, @$json]; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 1 | 1; | |||||||||
| 46 | __END__ | ||||||||||