version 1.1, 2010/06/24 22:45:25 |
version 1.6, 2010/06/27 01:52:33 |
|
|
package Net::OpenAMD; |
package Net::OpenAMD; |
|
|
# $RedRiver$ |
# $AFresh1: OpenAMD.pm,v 1.5 2010/06/24 22:57:42 andrew Exp $ |
|
|
use warnings; |
use warnings; |
use strict; |
use strict; |
|
|
|
|
use version; our $VERSION = qv('0.0.1'); |
use version; our $VERSION = qv('0.0.1'); |
|
|
# Other recommended modules (uncomment to use): |
my $BASE_URL = 'https://api.hope.net/api/'; |
# use IO::Prompt; |
|
# use Perl6::Export; |
|
# use Perl6::Slurp; |
|
# use Perl6::Say; |
|
|
|
|
use Class::Std::Utils; |
|
|
# Module implementation here |
use LWP::UserAgent; |
|
use URI; |
|
use Net::OAuth; |
|
use JSON::Any; |
|
|
|
{ |
|
|
1; # Magic true value required at end of module |
my @attr_refs = \( my %base_url_of, my %ua_of, my %auth_of, ); |
|
|
|
sub new { |
|
my ( $class, $options ) = @_; |
|
my $self = bless anon_scalar(), $class; |
|
my $ident = ident($self); |
|
|
|
$options //= {}; |
|
|
|
croak 'Options should be a hashref' if ref $options ne 'HASH'; |
|
|
|
$base_url_of{$ident} = $options->{base_url} || $BASE_URL; |
|
$ua_of{$ident} = $options->{ua} || LWP::UserAgent->new(); |
|
|
|
# XXX Authenticate |
|
|
|
return $self; |
|
} |
|
|
|
sub _get { |
|
my ( $self, $action, $query ) = @_; |
|
my $ident = ident($self); |
|
|
|
my $uri = URI->new( $base_url_of{$ident} . '/' . $action ); |
|
$uri->query($query); |
|
|
|
my $response = $ua_of{$ident}->get($uri); |
|
|
|
if ( !$response->is_success ) { |
|
croak $response->status_line; |
|
} |
|
|
|
return JSON::Any->jsonToObj( $response->decoded_content ); |
|
} |
|
|
|
sub location { my $self = shift; return $self->_get( 'location', @_ ) } |
|
sub speakers { my $self = shift; return $self->_get( 'speakers', @_ ) } |
|
sub talks { my $self = shift; return $self->_get( 'talks', @_ ) } |
|
sub interests { my $self = shift; return $self->_get( 'interests', @_ ) } |
|
sub users { my $self = shift; return $self->_get( 'users', @_ ) } |
|
sub stats { croak 'Unused feature' } |
|
|
|
sub DESTROY { |
|
my ($self) = @_; |
|
my $ident = ident $self; |
|
|
|
foreach my $attr_ref (@attr_refs) { |
|
delete $attr_ref->{$ident}; |
|
} |
|
|
|
return; |
|
} |
|
|
|
} |
|
|
|
1; # Magic true value required at end of module |
__END__ |
__END__ |
|
|
=head1 NAME |
=head1 NAME |
|
|
Net::OpenAMD - [One line description of module's purpose here] |
Net::OpenAMD - Perl interface to the OpenAMD API |
|
|
|
|
=head1 VERSION |
=head1 VERSION |
|
|
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
=for author to fill in: |
This module is to make it easy to grab information from the OpenAMD project at |
Write a full description of the module and its features here. |
The Next Hope. |
Use subsections (=head2, =head3) as appropriate. |
|
|
|
|
http://wiki.hope.net/Attendee_Meta-Data |
|
|
|
http://amd.hope.net/ |
|
|
|
http://amd.hope.net/2010/05/openamd-api-released-v1-1-1/ |
|
|
|
http://travisgoodspeed.blogspot.com/2010/06/hacking-next-hope-badge.html |
|
|
=head1 INTERFACE |
=head1 INTERFACE |
|
|
=for author to fill in: |
=for author to fill in: |
|
|
|
|
=head1 DEPENDENCIES |
=head1 DEPENDENCIES |
|
|
=for author to fill in: |
=over |
A list of all the other modules that this module relies upon, |
|
including any restrictions on versions, and an indication whether |
|
the module is part of the standard Perl distribution, part of the |
|
module's distribution, or must be installed separately. ] |
|
|
|
None. |
=item LWP::UserAgent |
|
|
|
=item Net::OAuth |
|
|
|
=item JSON::Any |
|
|
|
=back |
|
|
=head1 INCOMPATIBILITIES |
=head1 INCOMPATIBILITIES |
|
|