version 1.7, 2010/06/27 04:11:22 |
version 1.9, 2010/06/27 04:45:07 |
|
|
package Net::OpenAMD; |
package Net::OpenAMD; |
|
|
# $AFresh1: OpenAMD.pm,v 1.6 2010/06/27 00:52:33 andrew Exp $ |
# $AFresh1: OpenAMD.pm,v 1.8 2010/06/27 03:23:27 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
|
|
my $BASE_URL = 'https://api.hope.net/api/'; |
my $BASE_URL = 'https://api.hope.net/api/'; |
|
|
use Class::Std::Utils; |
use Scalar::Util qw( refaddr ); |
|
*_ident = \&refaddr; |
|
|
use LWP::UserAgent; |
use LWP::UserAgent; |
use URI; |
use URI; |
|
|
|
|
sub new { |
sub new { |
my ( $class, $options ) = @_; |
my ( $class, $options ) = @_; |
my $self = bless anon_scalar(), $class; |
my $self = bless do { \my $x }, $class; |
my $ident = ident($self); |
my $ident = _ident($self); |
|
|
$options //= {}; |
$options //= {}; |
|
|
|
|
|
|
sub get { |
sub get { |
my ( $self, $action, $query ) = @_; |
my ( $self, $action, $query ) = @_; |
my $ident = ident($self); |
my $ident = _ident($self); |
|
|
my $uri = URI->new( $base_url_of{$ident} . '/' . $action ); |
my $uri = URI->new_abs( $action, $base_url_of{$ident} ); |
$uri->query($query); |
$uri->query($query); |
|
|
my $response = $ua_of{$ident}->get($uri); |
my $response = $ua_of{$ident}->get($uri); |
|
|
return JSON::Any->jsonToObj( $response->decoded_content ); |
return JSON::Any->jsonToObj( $response->decoded_content ); |
} |
} |
|
|
sub location { my $self = shift; return $self->get( 'location', @_ ) } |
sub location { return shift->get( 'location', @_ ) } |
sub speakers { my $self = shift; return $self->get( 'speakers', @_ ) } |
sub speakers { return shift->get( 'speakers', @_ ) } |
sub talks { my $self = shift; return $self->get( 'talks', @_ ) } |
sub talks { return shift->get( 'talks', @_ ) } |
sub interests { my $self = shift; return $self->get( 'interests', @_ ) } |
sub interests { return shift->get( 'interests', @_ ) } |
sub users { my $self = shift; return $self->get( 'users', @_ ) } |
sub users { return shift->get( 'users', @_ ) } |
sub stats { croak 'Unused feature' } |
sub stats { croak 'Unused feature' } |
|
|
sub DESTROY { |
sub DESTROY { |
my ($self) = @_; |
my ($self) = @_; |
my $ident = ident $self; |
my $ident = _ident $self; |
|
|
foreach my $attr_ref (@attr_refs) { |
foreach my $attr_ref (@attr_refs) { |
delete $attr_ref->{$ident}; |
delete $attr_ref->{$ident}; |
|
|
|
|
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 |
|
|
|
|
=item base_url |
=item base_url |
|
|
A URL to the API, currently defaults to https://api.hope.net/api |
A URL to the API, currently defaults to https://api.hope.net/api/ |
|
|
|
Most likely it should end with a / to make URI happy, so notice that if you |
|
having 404 errors you don't expect. |
|
|
=item ua |
=item ua |
|
|