version 1.16, 2010/07/09 23:04:21 |
version 1.18, 2010/07/13 01:14:21 |
|
|
package Net::OpenAMD; |
package Net::OpenAMD; |
|
|
# $AFresh1: OpenAMD.pm,v 1.15 2010/06/30 19:02:48 andrew Exp $ |
# $AFresh1: OpenAMD.pm,v 1.17 2010/07/13 00:13:22 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
use LWP::UserAgent; |
use LWP::UserAgent; |
use URI; |
use URI; |
use Net::OAuth; |
use Net::OAuth; |
use JSON qw/ from_json /; |
use JSON; |
|
|
{ |
{ |
|
|
my @attr_refs |
my @attr_refs = \( |
= \( my %base_uri_of, my %ua_of, my %auth_of, my %actions_of ); |
my %base_uri_of, |
|
my %ua_of, my %auth_of, my %actions_of, |
|
my %json_of, |
|
); |
|
|
sub new { |
sub new { |
my ( $class, $options ) = @_; |
my ( $class, $options ) = @_; |
|
|
|
|
$base_uri_of{$ident} = $options->{base_uri} || $BASE_URI; |
$base_uri_of{$ident} = $options->{base_uri} || $BASE_URI; |
$ua_of{$ident} = $options->{ua} || LWP::UserAgent->new(); |
$ua_of{$ident} = $options->{ua} || LWP::UserAgent->new(); |
|
$json_of{$ident} = $options->{json} || JSON->new(); |
$actions_of{$ident} = $options->{actions} |
$actions_of{$ident} = $options->{actions} |
|| [qw( location speakers talks interests users )]; |
|| [qw( location speakers talks interests users )]; |
|
|
|
|
my ( $self, $action, $query ) = @_; |
my ( $self, $action, $query ) = @_; |
my $ident = _ident($self); |
my $ident = _ident($self); |
|
|
my $uri = URI->new_abs( $action, $base_uri_of{$ident} ); |
my $uri = URI->new_abs( $action . '/', $base_uri_of{$ident} ); |
$uri->query($query); |
$uri->query_form($query); |
|
|
my $response = $ua_of{$ident}->get($uri); |
my $response = $ua_of{$ident}->get($uri); |
croak $response->status_line if !$response->is_success; |
croak $response->status_line if !$response->is_success; |
|
|
my @data = map { from_json($_) } split /\r?\n/xms, |
my $data; |
$response->decoded_content; |
eval { |
|
$data = $json_of{$ident}->decode( $response->decoded_content ); |
|
}; |
|
croak "Invalid JSON from [$uri]" if $@; |
|
|
return @data == 1 ? $data[0] : \@data; |
return $data; |
} |
} |
|
|
sub stats { croak 'Unused feature' } |
sub stats { croak 'Unused feature' } |
|
|
|
|
=head1 VERSION |
=head1 VERSION |
|
|
This document describes Net::OpenAMD version 0.0.1 |
This document describes Net::OpenAMD version 0.0.3 |
|
|
|
|
=head1 SYNOPSIS |
=head1 SYNOPSIS |