| 1 | package WebService::Heartrails::Express; | ||
| 2 | |||
| 3 | 2 | ▶ | use 5.008005; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 2 | ▶ | use Mouse; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use WebService::Heartrails::Express::Provider; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | our $VERSION = "0.01"; | ||
| 8 | |||
| 9 | has provider => ( | ||
| 10 | is => 'ro', | ||
| 11 | isa => 'WebService::Heartrails::Express::Provider', | ||
| 12 | lazy_build => 1, | ||
| 13 | ); | ||
| 14 | |||
| 15 | has areas => ( | ||
| 16 | is => 'rw', | ||
| 17 | isa => 'ArrayRef', | ||
| 18 | lazy_build => 1 | ||
| 19 | ); | ||
| 20 | |||
| 21 | has prefs => ( | ||
| 22 | is => 'rw', | ||
| 23 | isa => 'ArrayRef', | ||
| 24 | lazy_build => 1 | ||
| 25 | ); | ||
| 26 | |||
| 27 | sub line{ | ||
| 28 | my $self = shift; | ||
| 29 | $self->provider->dispatch('line',@_); | ||
| 30 | } | ||
| 31 | |||
| 32 | sub station{ | ||
| 33 | my $self = shift; | ||
| 34 | $self->provider->dispatch('station',@_); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub near{ | ||
| 38 | my $self = shift; | ||
| 39 | $self->provider->dispatch('near',@_); | ||
| 40 | } | ||
| 41 | |||
| 42 | use Furl; | ||
| 43 | |||
| 44 | sub _build_provider{ | ||
| 45 | my $self = shift; | ||
| 46 | return WebService::Heartrails::Express::Provider->new( | ||
| 47 | furl => Furl->new( | ||
| 48 | agent => 'WebService::Heartrails::Express(Perl)', | ||
| 49 | timeout => 10, | ||
| 50 | ), | ||
| 51 | ); | ||
| 52 | } | ||
| 53 | |||
| 54 | use constant AREA_ENDPOINT => 'http://express.heartrails.com/api/json?method=getAreas'; | ||
| 55 | use constant PREF_ENDPOINT => 'http://express.heartrails.com/api/json?method=getPrefectures'; | ||
| 56 | |||
| 57 | sub _build_areas{ | ||
| 58 | my $self = shift; | ||
| 59 | my $response = $self->provider->furl->get(AREA_ENDPOINT); | ||
| 60 | my $content = JSON::decode_json($response->{content}); | ||
| 61 | return $content->{response}->{area}; | ||
| 62 | } | ||
| 63 | |||
| 64 | sub _build_prefs{ | ||
| 65 | my $self = shift; | ||
| 66 | my $response = $self->provider->furl->get(PREF_ENDPOINT); | ||
| 67 | my $content = JSON::decode_json($response->{content}); | ||
| 68 | return $content->{response}->{prefecture}; | ||
| 69 | } | ||
| 70 | |||
| 71 | no Mouse; | ||
| 72 | __PACKAGE__->meta->make_immutable; | ||
| 73 | |||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ | ||