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

Diff for /HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm between version 1.8 and 1.11

version 1.8, 2010/06/27 04:23:27 version 1.11, 2010/06/28 18:49:31
Line 1 
Line 1 
 package Net::OpenAMD;  package Net::OpenAMD;
   
 # $AFresh1: OpenAMD.pm,v 1.7 2010/06/27 03:11:22 andrew Exp $  # $AFresh1: OpenAMD.pm,v 1.10 2010/06/27 03:59:32 andrew Exp $
   
 use warnings;  use warnings;
 use strict;  use strict;
Line 8 
Line 8 
   
 use version; our $VERSION = qv('0.0.1');  use version; our $VERSION = qv('0.0.1');
   
 my $BASE_URL = 'https://api.hope.net/api/';  my $BASE_URI = 'https://api.hope.net/api/';
   
 use Scalar::Util qw( refaddr );  use Scalar::Util qw( refaddr );
 *_ident = \&refaddr;  *_ident = \&refaddr;
Line 20 
Line 20 
   
 {  {
   
     my @attr_refs = \( my %base_url_of, my %ua_of, my %auth_of, );      my @attr_refs = \( my %base_uri_of, my %ua_of, my %auth_of, );
   
     sub new {      sub new {
         my ( $class, $options ) = @_;          my ( $class, $options ) = @_;
Line 31 
Line 31 
   
         croak 'Options should be a hashref' if ref $options ne 'HASH';          croak 'Options should be a hashref' if ref $options ne 'HASH';
   
         $base_url_of{$ident} = $options->{base_url} || $BASE_URL;          $base_uri_of{$ident} = $options->{base_uri} || $BASE_URI;
         $ua_of{$ident}       = $options->{ua}       || LWP::UserAgent->new();          $ua_of{$ident}       = $options->{ua}       || LWP::UserAgent->new();
   
         # XXX Authenticate          # XXX Authenticate
Line 43 
Line 43 
         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_uri_of{$ident} );
         $uri->query($query);          $uri->query($query);
   
         my $response = $ua_of{$ident}->get($uri);          my $response = $ua_of{$ident}->get($uri);
Line 55 
Line 55 
         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) = @_;
Line 77 
Line 77 
   
 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
Line 124 
Line 123 
   
 =over  =over
   
 =item base_url  =item base_uri
   
 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
   
 Should be a pre-configured LWP::UserAgent or similar that returns a  Should be a pre-configured LWP::UserAgent or similar that returns a
Line 173 
Line 175 
   
 =head1 DIAGNOSTICS  =head1 DIAGNOSTICS
   
 All methods should croak when an error occours.  All methods should croak when an error occurs.
 If the remote API returns a successful response that contains valid JSON, that  If the remote API returns a successful response that contains valid JSON, that
 will be decoded and returned.  will be decoded and returned.
   

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.11

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>