summaryrefslogtreecommitdiff
path: root/lib/Net/HTTP
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-10-12 17:18:25 +0200
committerfranck cuny <franck@lumberjaph.net>2010-10-12 17:18:25 +0200
commit85a634ef2e68115636e8a17becbc6a968cab0eae (patch)
tree830bd34674ce8a15bfb6621c89a39a36f0bb2883 /lib/Net/HTTP
parentadd enable_if feature + tests (diff)
downloadnet-http-spore-85a634ef2e68115636e8a17becbc6a968cab0eae.tar.gz
update POD
Diffstat (limited to 'lib/Net/HTTP')
-rw-r--r--lib/Net/HTTP/Spore.pm22
-rw-r--r--lib/Net/HTTP/Spore/Meta.pm2
-rw-r--r--lib/Net/HTTP/Spore/Meta/Method.pm29
-rw-r--r--lib/Net/HTTP/Spore/Middleware.pm2
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Auth.pm6
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Format.pm4
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Format/Auto.pm44
-rw-r--r--lib/Net/HTTP/Spore/Response.pm1
8 files changed, 102 insertions, 8 deletions
diff --git a/lib/Net/HTTP/Spore.pm b/lib/Net/HTTP/Spore.pm
index b510fa0..23d5bc5 100644
--- a/lib/Net/HTTP/Spore.pm
+++ b/lib/Net/HTTP/Spore.pm
@@ -100,20 +100,36 @@ sub _add_methods {
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
- $client->enable('Auth::OAuth');
$client->enable('Format::JSON');
+ $client->enable('Auth::OAuth');
my $timeline = $client->public_timeline(format => 'json');
my $tweets = $timeline->body;
+
foreach my $tweet (@$tweets) {
- print $tweet->{user}->{screen_name}. " says ".$tweet->{text}."\n";
- }
+ print $tweet->{user}->{screen_name}. " says ".$tweet->{text}."\n";
}
my $friends_timeline = $client->friends_timeline(format => 'json');
=head1 DESCRIPTION
+This module is an implementation of the SPORE specification. To use this client, you need to use or to write a SPORE specification of an API. Some specifications are available L<http://github.com/SPORE/api-description>.
+
+=head2 CLIENT CREATION
+
+First you need to create a client. This can be done using two methods, B<new_from_spec> and B<new_from_string>. The client will read the specification file to create a appropriate methods to interact with the API.
+
+=head2 MIDDLEWARES
+
+It's possible to activate some middlewares to extend the usage of the client. If you're using an API that discuss in JSON, you can enable the middleware L<Net::HTTP::Spore::Middleware::JSON>.
+
+ $client->enable('Format::JSON');
+
+or only on some path
+
+ $client->enable_if(sub{$_->[0]->path =~ m!/path/to/json/stuff!}, 'Format::JSON');
+
=head2 METHODS
=over 4
diff --git a/lib/Net/HTTP/Spore/Meta.pm b/lib/Net/HTTP/Spore/Meta.pm
index 4cbd05e..ec773b6 100644
--- a/lib/Net/HTTP/Spore/Meta.pm
+++ b/lib/Net/HTTP/Spore/Meta.pm
@@ -1,5 +1,7 @@
package Net::HTTP::Spore::Meta;
+# ABSTRACT: Meta class for all SPORE object
+
use Moose;
use Moose::Exporter;
use Moose::Util::MetaRole;
diff --git a/lib/Net/HTTP/Spore/Meta/Method.pm b/lib/Net/HTTP/Spore/Meta/Method.pm
index 3494350..3567497 100644
--- a/lib/Net/HTTP/Spore/Meta/Method.pm
+++ b/lib/Net/HTTP/Spore/Meta/Method.pm
@@ -163,5 +163,34 @@ sub wrap {
=head1 SYNOPSIS
+ my $spore_method = Net::HTTP::Spore::Meta::Method->wrap(
+ 'user_timeline',
+ method => 'GET',
+ path => '/user/:name'
+ );
+
=head1 DESCRIPTION
+=head1 METHODS
+
+=over 4
+
+=item B<path>
+
+=item B<method>
+
+=item B<description>
+
+=item B<authentication>
+
+=item B<base_url>
+
+=item B<format>
+
+=item B<expected>
+
+=item B<params>
+
+=item B<documentation>
+
+=back
diff --git a/lib/Net/HTTP/Spore/Middleware.pm b/lib/Net/HTTP/Spore/Middleware.pm
index 6d284b5..2855a72 100644
--- a/lib/Net/HTTP/Spore/Middleware.pm
+++ b/lib/Net/HTTP/Spore/Middleware.pm
@@ -1,5 +1,7 @@
package Net::HTTP::Spore::Middleware;
+# ABSTRACT: middlewares base class
+
use strict;
use warnings;
diff --git a/lib/Net/HTTP/Spore/Middleware/Auth.pm b/lib/Net/HTTP/Spore/Middleware/Auth.pm
index 619215c..0d422a5 100644
--- a/lib/Net/HTTP/Spore/Middleware/Auth.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Auth.pm
@@ -1,5 +1,7 @@
package Net::HTTP::Spore::Middleware::Auth;
+# ABSTRACT: base class for Authentication middlewares
+
use Moose;
extends 'Net::HTTP::Spore::Middleware';
@@ -8,3 +10,7 @@ sub should_authenticate { $_[1]->env->{'spore.authentication'} }
sub call { die "should be implemented" }
1;
+
+=head1 DESCRIPTION
+
+Authentication middleware should extends this base class and implement the B<call> method
diff --git a/lib/Net/HTTP/Spore/Middleware/Format.pm b/lib/Net/HTTP/Spore/Middleware/Format.pm
index 559c1e5..2741295 100644
--- a/lib/Net/HTTP/Spore/Middleware/Format.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Format.pm
@@ -83,6 +83,8 @@ If the environment contains a B<payload> (under the name 'spore.payload'), it sh
=head1 METHODS
+=over 4
+
=item serializer_key
name of the extension serializer should check to be sure to not encode a payload already encoded, or set the headers that have already been defined
@@ -116,3 +118,5 @@ this method returns 1 if serialization have not already been done
this method returns 1 if deserialization have not already been done
=item call
+
+=back
diff --git a/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm b/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
index fd66b8c..0bc1eb0 100644
--- a/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
+++ b/lib/Net/HTTP/Spore/Middleware/Format/Auto.pm
@@ -1,17 +1,51 @@
package Net::HTTP::Spore::Middleware::Format::Auto;
use Moose;
+use MooseX::Types::Moose qw/HashRef Object/;
extends 'Net::HTTP::Spore::Middleware::Format';
+use Try::Tiny;
+
+has seriliazer => (
+ is => 'rw',
+ isa => HashRef [Object],
+ lazy => 1,
+ default => sub { {} },
+);
+
sub call {
my ( $self, $req ) = @_;
- $req->env->{'sporex.format'} = 1;
+ my $formats = $req->env->{'spore.format'};
+
+ foreach my $format (@$formats) {
+ my $cls = "Net::HTTP::Spore::Middleware::Format::" . $format;
+ if ( Class::MOP::load($cls) ) {
+ my $s = $cls->new;
+ $self->serializer->{$format} = $s;
+ try {
+ if ( $req->env->{'spore.payload'} ) {
+ $req->env->{'spore.payload'} =
+ $s->encode( $req->env->{'spore.payload'} );
+ $req->header( $s->content_type );
+ }
+ $req->header( $s->accept_type );
+ $req->env->{$self->serializer_key} = 1;
+ };
+ last if $req->env->{$self->serializer_key} == 1;
+ }
+ }
- return $self->response_cb( sub {
- my $res = shift;
- return $res;
- });
+ return $self->response_cb(
+ sub {
+ my $res = shift;
+ return $res;
+ }
+ );
}
1;
+
+=head1 DESCRIPTION
+
+B<NOT WORKING>
diff --git a/lib/Net/HTTP/Spore/Response.pm b/lib/Net/HTTP/Spore/Response.pm
index 4667e08..03ab2e7 100644
--- a/lib/Net/HTTP/Spore/Response.pm
+++ b/lib/Net/HTTP/Spore/Response.pm
@@ -229,3 +229,4 @@ The third and final element is the body
=back
+=back