| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Stickam::API; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 9 |  |  | 9 |  | 216233 | use strict; | 
|  | 9 |  |  |  |  | 20 |  | 
|  | 9 |  |  |  |  | 288 |  | 
| 4 | 9 |  |  | 9 |  | 43 | use warnings; | 
|  | 9 |  |  |  |  | 20 |  | 
|  | 9 |  |  |  |  | 338 |  | 
| 5 | 9 |  |  | 9 |  | 49 | use base qw/Class::Accessor::Fast/; | 
|  | 9 |  |  |  |  | 23 |  | 
|  | 9 |  |  |  |  | 8269 |  | 
| 6 | 9 |  |  | 9 |  | 43608 | use XML::Simple; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | use UNIVERSAL::require; | 
| 8 |  |  |  |  |  |  | use JSON::XS ; | 
| 9 |  |  |  |  |  |  | use Time::HiRes; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | our $VERSION = '0.02'; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | __PACKAGE__->mk_accessors(qw/data content error tv_interval/); | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | sub call { | 
| 16 |  |  |  |  |  |  | my ( $s , $pkg , $args ) = @_; | 
| 17 |  |  |  |  |  |  | my $t0 = [ Time::HiRes::gettimeofday() ]; | 
| 18 |  |  |  |  |  |  | $pkg =~ s/\//::/g; | 
| 19 |  |  |  |  |  |  | $pkg = 'WWW::Stickam::API::' . $pkg ; | 
| 20 |  |  |  |  |  |  | $pkg->require or die "The API call[$pkg] is not available...[$@]"; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | my $api = $pkg->new(); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | if( $api->call( $args ) ) { | 
| 25 |  |  |  |  |  |  | $s->{content} = $api->content; | 
| 26 |  |  |  |  |  |  | $s->{tv_interval} = Time::HiRes::tv_interval( $t0 ); | 
| 27 |  |  |  |  |  |  | return 1; | 
| 28 |  |  |  |  |  |  | } | 
| 29 |  |  |  |  |  |  | else { | 
| 30 |  |  |  |  |  |  | $s->{error} = $api->error; | 
| 31 |  |  |  |  |  |  | $s->{tv_interval} = Time::HiRes::tv_interval( $t0 ); | 
| 32 |  |  |  |  |  |  | return ; | 
| 33 |  |  |  |  |  |  | } | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub get { | 
| 37 |  |  |  |  |  |  | my $s = shift; | 
| 38 |  |  |  |  |  |  | return XMLin( $s->{content} ); | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub get_XML { | 
| 42 |  |  |  |  |  |  | my $s = shift; | 
| 43 |  |  |  |  |  |  | return $s->{content}; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub get_JSON { | 
| 47 |  |  |  |  |  |  | my $s = shift; | 
| 48 |  |  |  |  |  |  | my $data = $s->get(); | 
| 49 |  |  |  |  |  |  | return JSON::XS->new->utf8->pretty(1)->encode( $data );; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | 1; | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =head1 NAME | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | WWW::Stickam::API - Perl implementation of Stickam API | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head1 SYNOPSYS | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | my $api = WWW::Stickam::API->new(); | 
| 61 |  |  |  |  |  |  | if( $api->call('User/Profile' , { user_name => 'stickam' } ) ) { | 
| 62 |  |  |  |  |  |  | print Dumper $api->get(); | 
| 63 |  |  |  |  |  |  | print $api->get_XML(); | 
| 64 |  |  |  |  |  |  | print $api->get_JSON(); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | else { | 
| 67 |  |  |  |  |  |  | print $api->error ; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | Perl implementation of Stickam API. See http://labs.stickam.jp/api/ | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | =head1 METHOD | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head2 new | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =head2 call | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | This method call stickam API , take API name and parameters. | 
| 81 |  |  |  |  |  |  | Return true for success , false for fail. | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 get | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | get result in hash array format. | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =head2 get_XML | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | get result in XML | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | =head2 get_JSON | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | get result in JSON | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =head2 error | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | get error message | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =head2 tv_interval | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | get tv_interval. SEE L | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =head2 SEE ALSO | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | L | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | L | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | L | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | L | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | L | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | L | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | L | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | =head1 AUTHOR | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | Tomohiro Teranishi | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =cut | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  |  |