Annotation of HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm, Revision 1.6
1.1 andrew 1: package Net::OpenAMD;
2:
1.6 ! andrew 3: # $AFresh1: OpenAMD.pm,v 1.5 2010/06/24 22:57:42 andrew Exp $
1.1 andrew 4:
5: use warnings;
6: use strict;
7: use Carp;
8:
9: use version; our $VERSION = qv('0.0.1');
10:
1.2 andrew 11: my $BASE_URL = 'https://api.hope.net/api/';
1.1 andrew 12:
1.2 andrew 13: use Class::Std::Utils;
1.1 andrew 14:
1.2 andrew 15: use LWP::UserAgent;
1.6 ! andrew 16: use URI;
1.2 andrew 17: use Net::OAuth;
18: use JSON::Any;
1.1 andrew 19:
1.2 andrew 20: {
1.1 andrew 21:
1.6 ! andrew 22: my @attr_refs = \( my %base_url_of, my %ua_of, my %auth_of, );
1.2 andrew 23:
24: sub new {
25: my ( $class, $options ) = @_;
26: my $self = bless anon_scalar(), $class;
27: my $ident = ident($self);
28:
1.6 ! andrew 29: $options //= {};
! 30:
! 31: croak 'Options should be a hashref' if ref $options ne 'HASH';
! 32:
! 33: $base_url_of{$ident} = $options->{base_url} || $BASE_URL;
! 34: $ua_of{$ident} = $options->{ua} || LWP::UserAgent->new();
! 35:
! 36: # XXX Authenticate
! 37:
1.2 andrew 38: return $self;
39: }
40:
1.6 ! andrew 41: sub _get {
! 42: my ( $self, $action, $query ) = @_;
! 43: my $ident = ident($self);
! 44:
! 45: my $uri = URI->new( $base_url_of{$ident} . '/' . $action );
! 46: $uri->query($query);
! 47:
! 48: my $response = $ua_of{$ident}->get($uri);
! 49:
! 50: if ( !$response->is_success ) {
! 51: croak $response->status_line;
! 52: }
! 53:
! 54: return JSON::Any->jsonToObj( $response->decoded_content );
! 55: }
1.2 andrew 56:
57: sub location { my $self = shift; return $self->_get( 'location', @_ ) }
58: sub speakers { my $self = shift; return $self->_get( 'speakers', @_ ) }
59: sub talks { my $self = shift; return $self->_get( 'talks', @_ ) }
60: sub interests { my $self = shift; return $self->_get( 'interests', @_ ) }
61: sub users { my $self = shift; return $self->_get( 'users', @_ ) }
62: sub stats { croak 'Unused feature' }
1.6 ! andrew 63:
! 64: sub DESTROY {
! 65: my ($self) = @_;
! 66: my $ident = ident $self;
! 67:
! 68: foreach my $attr_ref (@attr_refs) {
! 69: delete $attr_ref->{$ident};
! 70: }
! 71:
! 72: return;
! 73: }
! 74:
1.2 andrew 75: }
76:
77: 1; # Magic true value required at end of module
1.1 andrew 78: __END__
79:
80: =head1 NAME
81:
1.2 andrew 82: Net::OpenAMD - Perl interface to the OpenAMD API
1.1 andrew 83:
84:
85: =head1 VERSION
86:
87: This document describes Net::OpenAMD version 0.0.1
88:
89:
90: =head1 SYNOPSIS
91:
92: use Net::OpenAMD;
93:
94: =for author to fill in:
95: Brief code example(s) here showing commonest usage(s).
96: This section will be as far as many users bother reading
97: so make it as educational and exeplary as possible.
98:
99:
100: =head1 DESCRIPTION
101:
1.2 andrew 102: This module is to make it easy to grab information from the OpenAMD project at
103: The Next Hope.
1.4 andrew 104:
105: http://wiki.hope.net/Attendee_Meta-Data
1.1 andrew 106:
1.2 andrew 107: http://amd.hope.net/
1.3 andrew 108:
109: http://amd.hope.net/2010/05/openamd-api-released-v1-1-1/
1.5 andrew 110:
111: http://travisgoodspeed.blogspot.com/2010/06/hacking-next-hope-badge.html
1.1 andrew 112:
113: =head1 INTERFACE
114:
115: =for author to fill in:
116: Write a separate section listing the public components of the modules
117: interface. These normally consist of either subroutines that may be
118: exported, or methods that may be called on objects belonging to the
119: classes provided by the module.
120:
121:
122: =head1 DIAGNOSTICS
123:
124: =for author to fill in:
125: List every single error and warning message that the module can
126: generate (even the ones that will "never happen"), with a full
127: explanation of each problem, one or more likely causes, and any
128: suggested remedies.
129:
130: =over
131:
132: =item C<< Error message here, perhaps with %s placeholders >>
133:
134: [Description of error here]
135:
136: =item C<< Another error message here >>
137:
138: [Description of error here]
139:
140: [Et cetera, et cetera]
141:
142: =back
143:
144:
145: =head1 CONFIGURATION AND ENVIRONMENT
146:
147: =for author to fill in:
148: A full explanation of any configuration system(s) used by the
149: module, including the names and locations of any configuration
150: files, and the meaning of any environment variables or properties
151: that can be set. These descriptions must also include details of any
152: configuration language used.
153:
154: Net::OpenAMD requires no configuration files or environment variables.
155:
156:
157: =head1 DEPENDENCIES
158:
1.2 andrew 159: =over
160:
161: =item LWP::UserAgent
162:
163: =item Net::OAuth
1.1 andrew 164:
1.2 andrew 165: =item JSON::Any
1.1 andrew 166:
1.2 andrew 167: =back
1.1 andrew 168:
169: =head1 INCOMPATIBILITIES
170:
171: =for author to fill in:
172: A list of any modules that this module cannot be used in conjunction
173: with. This may be due to name conflicts in the interface, or
174: competition for system or program resources, or due to internal
175: limitations of Perl (for example, many modules that use source code
176: filters are mutually incompatible).
177:
178: None reported.
179:
180:
181: =head1 BUGS AND LIMITATIONS
182:
183: =for author to fill in:
184: A list of known problems with the module, together with some
185: indication Whether they are likely to be fixed in an upcoming
186: release. Also a list of restrictions on the features the module
187: does provide: data types that cannot be handled, performance issues
188: and the circumstances in which they may arise, practical
189: limitations on the size of data sets, special cases that are not
190: (yet) handled, etc.
191:
192: No bugs have been reported.
193:
194: Please report any bugs or feature requests to
195: C<bug-net-openamd@rt.cpan.org>, or through the web interface at
196: L<http://rt.cpan.org>.
197:
198:
199: =head1 AUTHOR
200:
201: Andrew Fresh C<< <andrew@cpan.org> >>
202:
203:
204: =head1 LICENSE AND COPYRIGHT
205:
206: Copyright (c) 2010, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
207:
208: This module is free software; you can redistribute it and/or
209: modify it under the same terms as Perl itself. See L<perlartistic>.
210:
211:
212: =head1 DISCLAIMER OF WARRANTY
213:
214: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
215: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
216: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
217: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
218: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
219: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
220: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
221: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
222: NECESSARY SERVICING, REPAIR, OR CORRECTION.
223:
224: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
225: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
226: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
227: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
228: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
229: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
230: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
231: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
232: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
233: SUCH DAMAGES.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>