[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.12 and 1.19

version 1.12, 2010/06/28 21:32:32 version 1.19, 2010/07/14 06:21:23
Line 1 
Line 1 
 package Net::OpenAMD;  package Net::OpenAMD;
   
 # $AFresh1: OpenAMD.pm,v 1.11 2010/06/28 17:49:31 andrew Exp $  # $AFresh1: OpenAMD.pm,v 1.18 2010/07/13 00:14:21 andrew Exp $
   
 use version; our $VERSION = qv('0.0.1');  
 my $BASE_URI = 'https://api.hope.net/api/';  
   
 use warnings;  use warnings;
 use strict;  use strict;
 use Carp;  use Carp;
   
   use version; our $VERSION = qv('0.1.0');
   my $BASE_URI = 'https://api.hope.net/api/';
   
 use Scalar::Util qw( refaddr );  use Scalar::Util qw( refaddr );
 *_ident = \&refaddr;  *_ident = \&refaddr;
   
 use LWP::UserAgent;  use LWP::UserAgent;
 use URI;  use URI;
 use Net::OAuth;  use Net::OAuth;
 use JSON::Any;  use JSON;
   
 {  {
   
     my @attr_refs = \( my %base_uri_of, my %ua_of, my %auth_of, );      my @attr_refs = \(
           my %base_uri_of,
           my %ua_of, my %auth_of, my %actions_of,
           my %json_of,
       );
   
     sub new {      sub new {
         my ( $class, $options ) = @_;          my ( $class, $options ) = @_;
Line 32 
Line 36 
   
         $base_uri_of{$ident} = $options->{base_uri} || $BASE_URI;          $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();
           $json_of{$ident}     = $options->{json}     || JSON->new();
           $actions_of{$ident}  = $options->{actions}
               || [qw( location speakers talks interests users )];
   
           foreach my $action ( @{ $actions_of{$ident} } ) {
               ## no critic
               no strict 'refs';
               *{$action} = sub { shift->get( $action, @_ ) };
           }
   
         # XXX Authenticate          # XXX Authenticate
   
         return $self;          return $self;
Line 42 
Line 55 
         my ( $self, $action, $query ) = @_;          my ( $self, $action, $query ) = @_;
         my $ident = _ident($self);          my $ident = _ident($self);
   
         my $uri = URI->new_abs( $action, $base_uri_of{$ident} );          my $uri = URI->new_abs( $action . '/', $base_uri_of{$ident} );
         $uri->query($query);          $uri->query_form($query);
   
         my $response = $ua_of{$ident}->get($uri);          my $response = $ua_of{$ident}->get($uri);
         croak $response->status_line if !$response->is_success;          croak $response->status_line if !$response->is_success;
   
         return JSON::Any->jsonToObj( $response->decoded_content );          my $data;
           eval {
               $data = $json_of{$ident}->decode( $response->decoded_content );
           };
           croak "Invalid JSON from [$uri]" if $@;
   
           return $data;
     }      }
   
     sub location  { return shift->get( 'location',  @_ ) }      sub stats { croak 'Unused feature' }
     sub speakers  { return shift->get( 'speakers',  @_ ) }  
     sub talks     { return shift->get( 'talks',     @_ ) }  
     sub interests { return shift->get( 'interests', @_ ) }  
     sub users     { return shift->get( 'users',     @_ ) }  
     sub stats     { croak 'Unused feature' }  
   
     sub DESTROY {      sub DESTROY {
         my ($self) = @_;          my ($self) = @_;
Line 81 
Line 95 
   
 =head1 VERSION  =head1 VERSION
   
 This document describes Net::OpenAMD version 0.0.1  This document describes Net::OpenAMD version 0.0.3
   
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
Line 125 
Line 139 
 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  Most likely it should end with a / to make URI happy, so notice that if you
 having 404 errors you don't expect.  are having 404 errors you don't expect.
   
 =item ua  =item ua
   
Line 166 
Line 180 
   
 =back  =back
   
 Unless specified, there is nothing different about any of the helper methods  Unless specified, there is nothing different about any of the action methods
 than just calling get($action) instead.  Depending on API changes, this may  than just calling get($action) instead.  Depending on API changes, this may
 not always be the case.  not always be the case.
   

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.19

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