| 1 | package WWW::StationJp::API; | ||
| 2 | 1 | ▶ | use 5.008005; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | ▶ | use URI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use LWP::UserAgent; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | our $VERSION = "0.01"; | ||
| 10 | |||
| 11 | use constant BASE_URL => 'http://www.ekidata.jp/api'; | ||
| 12 | |||
| 13 | use Mouse; | ||
| 14 | |||
| 15 | sub response{ | ||
| 16 | my($self,$url) = @_; | ||
| 17 | my $ua = LWP::UserAgent->new; | ||
| 18 | my $res = $ua->get($url); | ||
| 19 | } | ||
| 20 | |||
| 21 | sub pref{ | ||
| 22 | my($self,$pref) = @_; | ||
| 23 | my $url = URI->new(BASE_URL."/p/".$pref->{prefcode}.".json"); | ||
| 24 | my $res = $self->response($url); | ||
| 25 | $res = xml_parse($res->content); | ||
| 26 | return JSON::decode_json($res); | ||
| 27 | } | ||
| 28 | |||
| 29 | sub line{ | ||
| 30 | my($self,$line) = @_; | ||
| 31 | my $url = URI->new(BASE_URL."/l/".$line->{linecode}.".json"); | ||
| 32 | my $res = $self->response($url); | ||
| 33 | $res = xml_parse($res->content); | ||
| 34 | return JSON::decode_json($res); | ||
| 35 | } | ||
| 36 | |||
| 37 | sub station{ | ||
| 38 | my($self,$station) = @_; | ||
| 39 | my $url = URI->new(BASE_URL."/s/".$station->{stationcode}.".json"); | ||
| 40 | my $res = $self->response($url); | ||
| 41 | $res = xml_parse($res->content); | ||
| 42 | return JSON::decode_json($res); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub group{ | ||
| 46 | my($self,$group) = @_; | ||
| 47 | my $url = URI->new(BASE_URL."/g/".$group->{stationcode}.".json"); | ||
| 48 | my $res = $self->response($url); | ||
| 49 | $res = xml_parse($res->content); | ||
| 50 | return JSON::decode_json($res); | ||
| 51 | } | ||
| 52 | |||
| 53 | sub near{ | ||
| 54 | my($self,$near) = @_; | ||
| 55 | my $url = URI->new(BASE_URL."/n/".$near->{linecode}.".json"); | ||
| 56 | my $res = $self->response($url); | ||
| 57 | $res = xml_parse($res->content); | ||
| 58 | return JSON::decode_json($res); | ||
| 59 | } | ||
| 60 | |||
| 61 | sub xml_parse{ | ||
| 62 | my ($content) = @_; | ||
| 63 | $content =~ s/if\(typeof\(xml\)==\'undefined\'\) xml = {};//; | ||
| 64 | $content =~ s/xml.data = //; | ||
| 65 | $content =~ s/if\(typeof\(xml.onload\)==\'function\'\) xml.onload\(xml.data\);//; | ||
| 66 | return $content; | ||
| 67 | } | ||
| 68 | |||
| 69 | 1; | ||
| 70 | __END__ | ||