version 1.11, 2010/06/28 18:49:31 |
version 1.13, 2010/06/30 06:30:17 |
|
|
package Net::OpenAMD; |
package Net::OpenAMD; |
|
|
# $AFresh1: OpenAMD.pm,v 1.10 2010/06/27 03:59:32 andrew Exp $ |
# $AFresh1: OpenAMD.pm,v 1.12 2010/06/28 20:32:32 andrew Exp $ |
|
|
|
use version; our $VERSION = qv('0.0.2'); |
|
my $BASE_URI = 'https://api.hope.net/api/'; |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
use Carp; |
use Carp; |
|
|
use version; our $VERSION = qv('0.0.1'); |
|
|
|
my $BASE_URI = 'https://api.hope.net/api/'; |
|
|
|
use Scalar::Util qw( refaddr ); |
use Scalar::Util qw( refaddr ); |
*_ident = \&refaddr; |
*_ident = \&refaddr; |
|
|
use LWP::UserAgent; |
use LWP::UserAgent; |
use URI; |
use URI; |
use Net::OAuth; |
use Net::OAuth; |
use JSON::Any; |
use JSON qw/ from_json /; |
|
|
{ |
{ |
|
|
|
|
my $self = bless do { \my $x }, $class; |
my $self = bless do { \my $x }, $class; |
my $ident = _ident($self); |
my $ident = _ident($self); |
|
|
$options //= {}; |
$options ||= {}; |
|
|
croak 'Options should be a hashref' if ref $options ne 'HASH'; |
croak 'Options should be a hashref' if ref $options ne 'HASH'; |
|
|
|
|
$uri->query($query); |
$uri->query($query); |
|
|
my $response = $ua_of{$ident}->get($uri); |
my $response = $ua_of{$ident}->get($uri); |
|
croak $response->status_line if !$response->is_success; |
|
|
if ( !$response->is_success ) { |
my @data = map { from_json($_) } split /\r?\n/xms, |
croak $response->status_line; |
$response->decoded_content; |
} |
|
|
|
return JSON::Any->jsonToObj( $response->decoded_content ); |
return @data == 1 ? $data[0] : \@data; |
} |
} |
|
|
sub location { return shift->get( 'location', @_ ) } |
sub location { return shift->get( 'location', @_ ) } |
|
|
|
|
1; # Magic true value required at end of module |
1; # Magic true value required at end of module |
__END__ |
__END__ |
|
|
=head1 NAME |
=head1 NAME |
|
|
Net::OpenAMD - Perl interface to the OpenAMD API |
Net::OpenAMD - Perl interface to the OpenAMD API |