| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::StationJp::API; | 
| 2 | 1 |  |  | 1 |  | 784 | use 5.008005; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 3 | 1 |  |  | 1 |  | 4 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 33 |  | 
| 4 | 1 |  |  | 1 |  | 11 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 22 |  | 
| 5 | 1 |  |  | 1 |  | 572 | use URI; | 
|  | 1 |  |  |  |  | 4818 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 6 | 1 |  |  | 1 |  | 721 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 44541 |  | 
|  | 1 |  |  |  |  | 47 |  | 
| 7 | 1 |  |  | 1 |  | 318 | use JSON; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 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__ |