diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-07-16 16:10:41 +0200 |
| commit | e97449eaa8bd3a408763057f9ca2253d93e2a3d0 (patch) | |
| tree | 4fd0dc6ed899efe361e314adfc913b9aa6b0a1a4 | |
| parent | check if auth_method is declared (diff) | |
| download | net-http-api-e97449eaa8bd3a408763057f9ca2253d93e2a3d0.tar.gz | |
rename from mx::net::api to net::http::api
| -rw-r--r-- | lib/MooseX/Net/API/Meta/Class.pm | 16 | ||||
| -rw-r--r-- | lib/Net/HTTP/API.pm (renamed from lib/MooseX/Net/API.pm) | 28 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Error.pm (renamed from lib/MooseX/Net/API/Error.pm) | 6 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Meta/Class.pm | 16 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Meta/Method.pm (renamed from lib/MooseX/Net/API/Meta/Method.pm) | 21 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Meta/Method/APIDeclare.pm (renamed from lib/MooseX/Net/API/Meta/Method/APIDeclare.pm) | 6 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Meta/Method/APIMethod.pm (renamed from lib/MooseX/Net/API/Meta/Method/APIMethod.pm) | 12 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Parser.pm (renamed from lib/MooseX/Net/API/Parser.pm) | 4 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Parser/JSON.pm (renamed from lib/MooseX/Net/API/Parser/JSON.pm) | 4 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Parser/XML.pm (renamed from lib/MooseX/Net/API/Parser/XML.pm) | 4 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Parser/YAML.pm (renamed from lib/MooseX/Net/API/Parser/YAML.pm) | 4 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Role/Authentication.pm (renamed from lib/MooseX/Net/API/Role/Authentication.pm) | 2 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Role/Format.pm (renamed from lib/MooseX/Net/API/Role/Format.pm) | 2 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Role/Request.pm (renamed from lib/MooseX/Net/API/Role/Request.pm) | 8 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Role/Serialization.pm (renamed from lib/MooseX/Net/API/Role/Serialization.pm) | 10 | ||||
| -rw-r--r-- | lib/Net/HTTP/API/Role/UserAgent.pm (renamed from lib/MooseX/Net/API/Role/UserAgent.pm) | 4 |
16 files changed, 74 insertions, 73 deletions
diff --git a/lib/MooseX/Net/API/Meta/Class.pm b/lib/MooseX/Net/API/Meta/Class.pm deleted file mode 100644 index ad1b709..0000000 --- a/lib/MooseX/Net/API/Meta/Class.pm +++ /dev/null @@ -1,16 +0,0 @@ -package MooseX::Net::API::Meta::Class; - -# ABSTRACT: metaclass for all API client - -use Moose::Role; - -with qw/ - MooseX::Net::API::Meta::Method::APIMethod - MooseX::Net::API::Meta::Method::APIDeclare - /; - -1; - -=head1 SYNOPSIS - -=head1 DESCRIPTION diff --git a/lib/MooseX/Net/API.pm b/lib/Net/HTTP/API.pm index d801eb9..92908bb 100644 --- a/lib/MooseX/Net/API.pm +++ b/lib/Net/HTTP/API.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API; +package Net::HTTP::API; # ABSTRACT: Easily create client for net API @@ -32,18 +32,18 @@ sub init_meta { my $meta = Moose::Util::MetaRole::apply_metaroles( for_class => $for, - metaclass_roles => ['MooseX::Net::API::Meta::Class'], + metaclass_roles => ['Net::HTTP::API::Meta::Class'], ); Moose::Util::MetaRole::apply_base_class_roles( for => $for, roles => [ qw/ - MooseX::Net::API::Role::UserAgent - MooseX::Net::API::Role::Format - MooseX::Net::API::Role::Authentication - MooseX::Net::API::Role::Serialization - MooseX::Net::API::Role::Request + Net::HTTP::API::Role::UserAgent + Net::HTTP::API::Role::Format + Net::HTTP::API::Role::Authentication + Net::HTTP::API::Role::Serialization + Net::HTTP::API::Role::Request / ], ); @@ -56,7 +56,7 @@ sub init_meta { =head1 SYNOPSIS package My::Net::API; - use MooseX::Net::API; + use Net::HTTP::API; # we declare an API, the base_url is http://exemple.com/api # the format is json and it will be append to the query @@ -105,7 +105,7 @@ sub init_meta { =head1 DESCRIPTION -MooseX::Net::API is a module to help to easily create a client for a web API. +Net::HTTP::API is a module to help to easily create a client for a web API. This module is heavily inspired by what L<Net::Twitter> does. @@ -115,15 +115,15 @@ The following roles are added to your class: =over 4 -=item B<MooseX::Net::API::Role::UserAgent> +=item B<Net::HTTP::API::Role::UserAgent> -=item B<MooseX::Net::API::Role::Format> +=item B<Net::HTTP::API::Role::Format> -=item B<MooseX::Net::API::Role::Authentication> +=item B<Net::HTTP::API::Role::Authentication> -=item B<MooseX::Net::API::Role::Serialization> +=item B<Net::HTTP::API::Role::Serialization> -=item B<MooseX::Net::API::Role::Request> +=item B<Net::HTTP::API::Role::Request> =back diff --git a/lib/MooseX/Net/API/Error.pm b/lib/Net/HTTP/API/Error.pm index 0bb760a..43157b5 100644 --- a/lib/MooseX/Net/API/Error.pm +++ b/lib/Net/HTTP/API/Error.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API::Error; +package Net::HTTP::API::Error; # ABSTRACT: Throw error @@ -34,10 +34,10 @@ sub error { =head1 SYNOPSIS - MooseX::Net::API::Error->new(reason => "'useragent' is required"); + Net::HTTP::API::Error->new(reason => "'useragent' is required"); or - MooseX::Net::API::Error->new() + Net::HTTP::API::Error->new() =head1 DESCRIPTION diff --git a/lib/Net/HTTP/API/Meta/Class.pm b/lib/Net/HTTP/API/Meta/Class.pm new file mode 100644 index 0000000..8bc8c7b --- /dev/null +++ b/lib/Net/HTTP/API/Meta/Class.pm @@ -0,0 +1,16 @@ +package Net::HTTP::API::Meta::Class; + +# ABSTRACT: metaclass for all API client + +use Moose::Role; + +with qw/ + Net::HTTP::API::Meta::Method::APIMethod + Net::HTTP::API::Meta::Method::APIDeclare + /; + +1; + +=head1 SYNOPSIS + +=head1 DESCRIPTION diff --git a/lib/MooseX/Net/API/Meta/Method.pm b/lib/Net/HTTP/API/Meta/Method.pm index 8879e04..adda12c 100644 --- a/lib/MooseX/Net/API/Meta/Method.pm +++ b/lib/Net/HTTP/API/Meta/Method.pm @@ -1,9 +1,9 @@ -package MooseX::Net::API::Meta::Method; +package Net::HTTP::API::Meta::Method; # ABSTRACT: create api method use Moose; -use MooseX::Net::API::Error; +use Net::HTTP::API::Error; use Moose::Util::TypeConstraints; use MooseX::Types::Moose qw/Str Int ArrayRef/; @@ -86,13 +86,13 @@ before wrap => sub { my ($class, %args) = @_; if (!$args{params} && $args{required}) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "You can't require a param that have not been declared"); } if ( $args{required} ) { foreach my $required ( @{ $args{required} } ) { - die MooseX::Net::API::Error->new( reason => + die Net::HTTP::API::Error->new( reason => "$required is required but is not declared in params" ) if ( !grep { $_ eq $required } @{ $args{params} }, @{$args{params_in_url}} ); } @@ -122,7 +122,7 @@ sub wrap { if ($method->has_expected && !$method->find_expected_code(sub {/$code/})) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "unexpected code", http_error => $result ); @@ -139,7 +139,7 @@ sub wrap { } } - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( http_error => $result, reason => $result->message, ); @@ -167,7 +167,7 @@ sub _check_params_before_run { if ( !$self->find_request_parameter(sub {/$arg/}) && !$self->find_request_url_parameters(sub {/$arg/})) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "'$arg' is not declared as a param"); } } @@ -179,7 +179,7 @@ sub _check_required_before_run { # check if all our params declared as required are present foreach my $required ($self->required) { if (!grep { $required eq $_ } keys %$args) { - die MooseX::Net::API::Error->new(reason => + die Net::HTTP::API::Error->new(reason => "'$required' is declared as required, but is not present"); } } @@ -198,10 +198,10 @@ sub _build_path { $path =~ s/(?:\$|:)$match/$value/; } if ($max_iter > $i) { - $path =~ s/(?:\/((?:\$|\:).*))?$//; + $path =~ s/\/(?:(\$|\:).*)?$//; } } - $path =~ s/(?:\/((?:\$|\:).*))?$//; + $path =~ s/\/(?:(\$|\:).*)?$//; return $path; } @@ -227,3 +227,4 @@ sub _build_uri { =head1 SYNOPSIS =head1 DESCRIPTION + diff --git a/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm b/lib/Net/HTTP/API/Meta/Method/APIDeclare.pm index 0de38df..8718eaa 100644 --- a/lib/MooseX/Net/API/Meta/Method/APIDeclare.pm +++ b/lib/Net/HTTP/API/Meta/Method/APIDeclare.pm @@ -1,9 +1,9 @@ -package MooseX::Net::API::Meta::Method::APIDeclare; +package Net::HTTP::API::Meta::Method::APIDeclare; # ABSTRACT: declare API use Moose::Role; -use MooseX::Net::API::Error; +use Net::HTTP::API::Error; my @accepted_options = qw/ api_base_url @@ -31,7 +31,7 @@ sub add_net_api_declare { my ($meta, $name, %options) = @_; if ($options{useragent}) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "'useragent' must be a CODE ref") unless ref $options{useragent} eq 'CODE'; $meta->set_api_option(useragent => delete $options{useragent}); diff --git a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm b/lib/Net/HTTP/API/Meta/Method/APIMethod.pm index 0ddcacd..8303770 100644 --- a/lib/MooseX/Net/API/Meta/Method/APIMethod.pm +++ b/lib/Net/HTTP/API/Meta/Method/APIMethod.pm @@ -1,10 +1,10 @@ -package MooseX::Net::API::Meta::Method::APIMethod; +package Net::HTTP::API::Meta::Method::APIMethod; # ABSTRACT: declare API method use Moose::Role; -use MooseX::Net::API::Error; -use MooseX::Net::API::Meta::Method; +use Net::HTTP::API::Error; +use Net::HTTP::API::Meta::Method; use MooseX::Types::Moose qw/Str ArrayRef/; has local_net_api_methods => ( @@ -44,7 +44,7 @@ sub remove_net_api_method { before add_net_api_method => sub { my ($meta, $name) = @_; if ($meta->_find_net_api_method_by_name(sub {/^$name$/})) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "method '$name' is already declared in " . $meta->name); } }; @@ -58,7 +58,7 @@ sub add_net_api_method { $meta->add_method( $name, - MooseX::Net::API::Meta::Method->wrap( + Net::HTTP::API::Meta::Method->wrap( name => $name, package_name => $meta->name, body => $code, @@ -74,7 +74,7 @@ after add_net_api_method => sub { $name, sub { my $self = shift; - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "'api_base_url' have not been defined") unless $self->api_base_url; } diff --git a/lib/MooseX/Net/API/Parser.pm b/lib/Net/HTTP/API/Parser.pm index c56a026..b77095b 100644 --- a/lib/MooseX/Net/API/Parser.pm +++ b/lib/Net/HTTP/API/Parser.pm @@ -1,6 +1,6 @@ -package MooseX::Net::API::Parser; +package Net::HTTP::API::Parser; -# ABSTRACT: base class for all MooseX::Net::API::Parser +# ABSTRACT: base class for all Net::HTTP::API::Parser use Moose; diff --git a/lib/MooseX/Net/API/Parser/JSON.pm b/lib/Net/HTTP/API/Parser/JSON.pm index 58cc95a..be8b30e 100644 --- a/lib/MooseX/Net/API/Parser/JSON.pm +++ b/lib/Net/HTTP/API/Parser/JSON.pm @@ -1,10 +1,10 @@ -package MooseX::Net::API::Parser::JSON; +package Net::HTTP::API::Parser::JSON; # ABSTRACT: Parse JSON use JSON; use Moose; -extends 'MooseX::Net::API::Parser'; +extends 'Net::HTTP::API::Parser'; sub encode { my ($self, $content) = @_; diff --git a/lib/MooseX/Net/API/Parser/XML.pm b/lib/Net/HTTP/API/Parser/XML.pm index 305d4b4..aaedfcd 100644 --- a/lib/MooseX/Net/API/Parser/XML.pm +++ b/lib/Net/HTTP/API/Parser/XML.pm @@ -1,10 +1,10 @@ -package MooseX::Net::API::Parser::XML; +package Net::HTTP::API::Parser::XML; # ABSTRACT: Parse XML result use XML::Simple; use Moose; -extends 'MooseX::Net::API::Parser'; +extends 'Net::HTTP::API::Parser'; has _xml_parser => ( is => 'rw', diff --git a/lib/MooseX/Net/API/Parser/YAML.pm b/lib/Net/HTTP/API/Parser/YAML.pm index 82e6da2..f18593a 100644 --- a/lib/MooseX/Net/API/Parser/YAML.pm +++ b/lib/Net/HTTP/API/Parser/YAML.pm @@ -1,10 +1,10 @@ -package MooseX::Net::API::Parser::YAML; +package Net::HTTP::API::Parser::YAML; # ABSTRACT: Parse YAML use YAML::Syck; use Moose; -extends 'MooseX::Net::API::Parser'; +extends 'Net::HTTP::API::Parser'; sub encode { my ($self, $content) = @_; diff --git a/lib/MooseX/Net/API/Role/Authentication.pm b/lib/Net/HTTP/API/Role/Authentication.pm index 06b7e69..27728c3 100644 --- a/lib/MooseX/Net/API/Role/Authentication.pm +++ b/lib/Net/HTTP/API/Role/Authentication.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API::Role::Authentication; +package Net::HTTP::API::Role::Authentication; # ABSTRACT: Add authentication informations to request header diff --git a/lib/MooseX/Net/API/Role/Format.pm b/lib/Net/HTTP/API/Role/Format.pm index 5c37a47..1d8c10f 100644 --- a/lib/MooseX/Net/API/Role/Format.pm +++ b/lib/Net/HTTP/API/Role/Format.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API::Role::Format; +package Net::HTTP::API::Role::Format; # ABSTRACT: Set appropriate format to request header diff --git a/lib/MooseX/Net/API/Role/Request.pm b/lib/Net/HTTP/API/Role/Request.pm index 13221d3..c972b77 100644 --- a/lib/MooseX/Net/API/Role/Request.pm +++ b/lib/Net/HTTP/API/Role/Request.pm @@ -1,10 +1,10 @@ -package MooseX::Net::API::Role::Request; +package Net::HTTP::API::Role::Request; # ABSTRACT: make HTTP request use Moose::Role; use HTTP::Request; -use MooseX::Net::API::Error; +use Net::HTTP::API::Error; use MooseX::Types::URI qw(Uri); has api_base_url => ( @@ -16,7 +16,7 @@ has api_base_url => ( my $self = shift; my $api_base_url = $self->meta->get_api_option('api_base_url'); if (!$api_base_url) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "'api_base_url' have not been defined"); } $api_base_url; @@ -44,7 +44,7 @@ sub http_request { $request->content($content); } else { - die MooseX::Net::API::Error->new(reason => "$method is not defined"); + die Net::HTTP::API::Error->new(reason => "$method is not defined"); } $request->header( diff --git a/lib/MooseX/Net/API/Role/Serialization.pm b/lib/Net/HTTP/API/Role/Serialization.pm index 92c0248..37d2603 100644 --- a/lib/MooseX/Net/API/Role/Serialization.pm +++ b/lib/Net/HTTP/API/Role/Serialization.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API::Role::Serialization; +package Net::HTTP::API::Role::Serialization; # ABSTRACT: do (de)serialization @@ -6,12 +6,12 @@ use 5.010; use Try::Tiny; use Moose::Role; -use MooseX::Net::API::Error; +use Net::HTTP::API::Error; has serializers => ( traits => ['Hash'], is => 'rw', - isa => 'HashRef[MooseX::Net::API::Parser]', + isa => 'HashRef[Net::HTTP::API::Parser]', default => sub { {} }, auto_deref => 1, handles => { @@ -34,7 +34,7 @@ sub get_content { $content = $self->deserialize($result->content, \@deserialize_order); if (!$content) { - die MooseX::Net::API::Error->new( + die Net::HTTP::API::Error->new( reason => "can't deserialize content", http_error => $result, ); @@ -67,7 +67,7 @@ sub serialize { sub _load_serializer { my $self = shift; my $format = shift || $self->api_format; - my $parser = "MooseX::Net::API::Parser::" . uc($format); + my $parser = "Net::HTTP::API::Parser::" . uc($format); if (Class::MOP::load_class($parser)) { my $o = $parser->new; $self->_add_serializer($format => $o); diff --git a/lib/MooseX/Net/API/Role/UserAgent.pm b/lib/Net/HTTP/API/Role/UserAgent.pm index 3cb9714..84f618d 100644 --- a/lib/MooseX/Net/API/Role/UserAgent.pm +++ b/lib/Net/HTTP/API/Role/UserAgent.pm @@ -1,4 +1,4 @@ -package MooseX::Net::API::Role::UserAgent; +package Net::HTTP::API::Role::UserAgent; # ABSTRACT: create UserAgent @@ -15,7 +15,7 @@ has api_useragent => ( return $ua->() if $ua; $ua = LWP::UserAgent->new(); $ua->agent( - "MooseX::Net::API " . $MooseX::Net::API::VERSION . " (Perl)"); + "Net::HTTP::API " . $Net::HTTP::API::VERSION . " (Perl)"); $ua->env_proxy; return $ua; } |
