version 1.1.1.1, 2010/06/24 22:45:25 |
version 1.7, 2010/06/27 04:11:22 |
|
|
package Net::OpenAMD; |
package Net::OpenAMD; |
|
|
# $RedRiver$ |
# $AFresh1: OpenAMD.pm,v 1.6 2010/06/27 00:52:33 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, ); |
__END__ |
|
|
|
|
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__ |
=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 |
|
|
|
|
use Net::OpenAMD; |
use Net::OpenAMD; |
|
|
=for author to fill in: |
my $amd = Net::OpenAMD->new(); |
Brief code example(s) here showing commonest usage(s). |
|
This section will be as far as many users bother reading |
my $location = $amd->location({ area => 'Engressia' }); |
so make it as educational and exeplary as possible. |
|
|
|
|
|
=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: |
=head2 new |
Write a separate section listing the public components of the modules |
|
interface. These normally consist of either subroutines that may be |
|
exported, or methods that may be called on objects belonging to the |
|
classes provided by the module. |
|
|
|
|
Create a new object for accessing the OpenAMD API. |
|
|
=head1 DIAGNOSTICS |
my $amd = Net::OpenAMD->new( $options ); |
|
|
=for author to fill in: |
$options is a hashref with configuration options. |
List every single error and warning message that the module can |
|
generate (even the ones that will "never happen"), with a full |
|
explanation of each problem, one or more likely causes, and any |
|
suggested remedies. |
|
|
|
|
Current options are |
|
|
=over |
=over |
|
|
=item C<< Error message here, perhaps with %s placeholders >> |
=item base_url |
|
|
[Description of error here] |
A URL to the API, currently defaults to https://api.hope.net/api |
|
|
=item C<< Another error message here >> |
=item ua |
|
|
[Description of error here] |
Should be a pre-configured LWP::UserAgent or similar that returns a |
|
HTTP::Response object when its get method is called with a URI. |
|
|
[Et cetera, et cetera] |
=back |
|
|
|
=head2 get |
|
|
|
This is the main method, although probably never used. It has better/easier |
|
ways to access the different actions of the API. |
|
|
|
my $data = $amd->get( $action, $params ); |
|
|
|
$params are anything that are supported by URI->query, they will get passed |
|
on the request. |
|
|
|
Here $data is a the JSON returned by the API converted to Perl reference. |
|
|
|
Helper methods you can call as $amd->method($params) are: |
|
|
|
=over |
|
|
|
=item interests |
|
|
|
=item location |
|
|
|
=item new |
|
|
|
=item speakers |
|
|
|
=item stats |
|
|
|
=item talks |
|
|
|
=item users |
|
|
=back |
=back |
|
|
|
Unless specified, there is nothing different about any of the helper methods |
|
than just calling get($action) instead. Depending on API changes, this may |
|
not always be the case. |
|
|
|
=head1 DIAGNOSTICS |
|
|
|
All methods should croak when an error occours. |
|
If the remote API returns a successful response that contains valid JSON, that |
|
will be decoded and returned. |
|
|
=head1 CONFIGURATION AND ENVIRONMENT |
=head1 CONFIGURATION AND ENVIRONMENT |
|
|
=for author to fill in: |
|
A full explanation of any configuration system(s) used by the |
|
module, including the names and locations of any configuration |
|
files, and the meaning of any environment variables or properties |
|
that can be set. These descriptions must also include details of any |
|
configuration language used. |
|
|
|
Net::OpenAMD requires no configuration files or environment variables. |
Net::OpenAMD requires no configuration files or environment variables. |
|
|
|
Net::OpenAMD uses LWP::UserAgent for requests and environment for that is |
|
not cleared. |
|
|
=head1 DEPENDENCIES |
=head1 DEPENDENCIES |
|
|
=for author to fill in: |
=head3 L<LWP::UserAgent> |
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. |
=head3 L<URI> |
|
|
|
=head3 L<Net::OAuth> |
|
|
=head1 INCOMPATIBILITIES |
=head3 L<JSON::Any> |
|
|
=for author to fill in: |
|
A list of any modules that this module cannot be used in conjunction |
|
with. This may be due to name conflicts in the interface, or |
|
competition for system or program resources, or due to internal |
|
limitations of Perl (for example, many modules that use source code |
|
filters are mutually incompatible). |
|
|
|
|
=head1 INCOMPATIBILITIES |
|
|
None reported. |
None reported. |
|
|
|
|
=head1 BUGS AND LIMITATIONS |
=head1 BUGS AND LIMITATIONS |
|
|
=for author to fill in: |
|
A list of known problems with the module, together with some |
|
indication Whether they are likely to be fixed in an upcoming |
|
release. Also a list of restrictions on the features the module |
|
does provide: data types that cannot be handled, performance issues |
|
and the circumstances in which they may arise, practical |
|
limitations on the size of data sets, special cases that are not |
|
(yet) handled, etc. |
|
|
|
No bugs have been reported. |
No bugs have been reported. |
|
|
|
=over |
|
|
|
=item Currently it does not support the OAuth that is required to log into the |
|
API and get information. |
|
|
|
=back |
|
|
Please report any bugs or feature requests to |
Please report any bugs or feature requests to |
C<bug-net-openamd@rt.cpan.org>, or through the web interface at |
C<bug-net-openamd@rt.cpan.org>, or through the web interface at |