WWW::Stickam::API - Perl implementation of Stickam API


WWW-Stickam-API documentation Contained in the WWW-Stickam-API distribution.

Index


Code Index:

NAME

Top

WWW::Stickam::API - Perl implementation of Stickam API

SYNOPSYS

Top

 my $api = WWW::Stickam::API->new();
 if( $api->call('User/Profile' , { user_name => 'stickam' } ) ) {
    print Dumper $api->get();
    print $api->get_XML();
    print $api->get_JSON();
 }
 else {
    print $api->error ;
 }

DESCRIPTION

Top

Perl implementation of Stickam API. See http://labs.stickam.jp/api/

METHOD

Top

new

call

This method call stickam API , take API name and parameters. Return true for success , false for fail.

get

get result in hash array format.

get_XML

get result in XML

get_JSON

get result in JSON

error

get error message

tv_interval

get tv_interval. SEE Time::HiRes

SEE ALSO

WWW::Stickam::API::User::Audio

WWW::Stickam::API::User::Image

WWW::Stickam::API::User::Profile

WWW::Stickam::API::User::Video

WWW::Stickam::API::Media::Information

WWW::Stickam::API::Search::Media

WWW::Stickam::API::Search::User

AUTHOR

Top

Tomohiro Teranishi <tomohiro.teranishi@gmail.com>


WWW-Stickam-API documentation Contained in the WWW-Stickam-API distribution.

package WWW::Stickam::API;

use strict;
use warnings;
use base qw/Class::Accessor::Fast/;
use XML::Simple;
use UNIVERSAL::require;
use JSON::XS ;
use Time::HiRes;

our $VERSION = '0.02';

__PACKAGE__->mk_accessors(qw/data content error tv_interval/);

sub call {
    my ( $s , $pkg , $args ) = @_;
    my $t0 = [ Time::HiRes::gettimeofday() ];
    $pkg =~ s/\//::/g;
    $pkg = 'WWW::Stickam::API::' . $pkg ;
    $pkg->require or die "The API call[$pkg] is not available...[$@]";

    my $api = $pkg->new();

    if( $api->call( $args ) ) {
        $s->{content} = $api->content;
        $s->{tv_interval} = Time::HiRes::tv_interval( $t0 );
        return 1;
    }
    else {
        $s->{error} = $api->error;
        $s->{tv_interval} = Time::HiRes::tv_interval( $t0 );
        return ;
    }
}

sub get {
    my $s = shift;
    return XMLin( $s->{content} );
}

sub get_XML {
    my $s = shift;
    return $s->{content};
}

sub get_JSON {
    my $s = shift;
    my $data = $s->get();
    return JSON::XS->new->utf8->pretty(1)->encode( $data );;
}

1;