[BACK]Return to OpenAMD.pm CVS log [TXT][DIR] Up to [local] / HOPE / Net-OpenAMD / lib / Net

File: [local] / HOPE / Net-OpenAMD / lib / Net / OpenAMD.pm (download)

Revision 1.6, Sun Jun 27 00:52:33 2010 UTC (14 years ago) by andrew
Branch: MAIN
Changes since 1.5: +39 -3 lines

now my tests pass! except for the OAuth, it should actually pretty much be done. Next up, documentation!

package Net::OpenAMD;

# $AFresh1: OpenAMD.pm,v 1.6 2010/06/27 00:52:33 andrew Exp $

use warnings;
use strict;
use Carp;

use version; our $VERSION = qv('0.0.1');

my $BASE_URL = 'https://api.hope.net/api/';

use Class::Std::Utils;

use LWP::UserAgent;
use URI;
use Net::OAuth;
use JSON::Any;

{

    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__

=head1 NAME

Net::OpenAMD - Perl interface to the OpenAMD API


=head1 VERSION

This document describes Net::OpenAMD version 0.0.1


=head1 SYNOPSIS

    use Net::OpenAMD;

=for author to fill in:
    Brief code example(s) here showing commonest usage(s).
    This section will be as far as many users bother reading
    so make it as educational and exeplary as possible.
  
  
=head1 DESCRIPTION

This module is to make it easy to grab information from the OpenAMD project at
The Next Hope.

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 

=for author to fill in:
    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.


=head1 DIAGNOSTICS

=for author to fill in:
    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.

=over

=item C<< Error message here, perhaps with %s placeholders >>

[Description of error here]

=item C<< Another error message here >>

[Description of error here]

[Et cetera, et cetera]

=back


=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.


=head1 DEPENDENCIES

=over

=item LWP::UserAgent

=item Net::OAuth

=item JSON::Any

=back

=head1 INCOMPATIBILITIES

=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).

None reported.


=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.

Please report any bugs or feature requests to
C<bug-net-openamd@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.


=head1 AUTHOR

Andrew Fresh  C<< <andrew@cpan.org> >>


=head1 LICENSE AND COPYRIGHT

Copyright (c) 2010, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.


=head1 DISCLAIMER OF WARRANTY

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.