=================================================================== RCS file: /cvs/HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm,v retrieving revision 1.9 retrieving revision 1.12 diff -u -r1.9 -r1.12 --- HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm 2010/06/27 04:45:07 1.9 +++ HOPE/Net-OpenAMD/lib/Net/OpenAMD.pm 2010/06/28 21:32:32 1.12 @@ -1,15 +1,14 @@ package Net::OpenAMD; -# $AFresh1: OpenAMD.pm,v 1.8 2010/06/27 03:23:27 andrew Exp $ +# $AFresh1: OpenAMD.pm,v 1.11 2010/06/28 17:49:31 andrew Exp $ +use version; our $VERSION = qv('0.0.1'); +my $BASE_URI = 'https://api.hope.net/api/'; + use warnings; use strict; use Carp; -use version; our $VERSION = qv('0.0.1'); - -my $BASE_URL = 'https://api.hope.net/api/'; - use Scalar::Util qw( refaddr ); *_ident = \&refaddr; @@ -20,18 +19,18 @@ { - 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 { my ( $class, $options ) = @_; my $self = bless do { \my $x }, $class; my $ident = _ident($self); - $options //= {}; + $options ||= {}; 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(); # XXX Authenticate @@ -43,15 +42,12 @@ my ( $self, $action, $query ) = @_; my $ident = _ident($self); - my $uri = URI->new_abs( $action, $base_url_of{$ident} ); + my $uri = URI->new_abs( $action, $base_uri_of{$ident} ); $uri->query($query); my $response = $ua_of{$ident}->get($uri); + croak $response->status_line if !$response->is_success; - if ( !$response->is_success ) { - croak $response->status_line; - } - return JSON::Any->jsonToObj( $response->decoded_content ); } @@ -124,7 +120,7 @@ =over -=item base_url +=item base_uri A URL to the API, currently defaults to https://api.hope.net/api/ @@ -176,7 +172,7 @@ =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 will be decoded and returned.