t::JSON;
{
$Net::HTTP::Spore::Middleware::Format::JSON::VERSION = '0.05';
}
# ABSTRACT: middleware for JSON format
use JSON;
use Moose;
extends 'Net::HTTP::Spore::Middleware::Format';
has _json_p
isa => 'JSON',
lazy => 1,
default => sub { JSON->new->utf8(1)->allow_nonref },
);
sub encode { $_[0]->_json_parser->encode( $_[1] ); }
sub decode { $_[0]->_json_parser->dec
> 'application/json' ) }
sub content_type { ( 'Content-Type' => 'application/json;' ) }
1;
__END__
=pod
=head1 NAME
Net::HTTP::Spore::Middleware::Format::JSON - middleware for JSON format
=head1
ad1 VERSION
version 0.09
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('api.json');
$client->enable(
'Auth::ApiKey',
api_key => 'apikey',
api_secret
ilename => 'logfile'
)
);
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable( 'LogDispatch', logger => $log );
=head1 AUTHOR
franck cuny <franck@lumb
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('DoNotTrack');
=head1 DESCRIPTION
Add a header B<x-do-not-track> to your
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('Runtime');
my $result = $client->public_timeline;
say "request e
ore->new_from_spec('twitter.json');
$client->enable('Format::JSON');
my $res = $client->public_timeline();
# $res->body contains an hashref build from the JSON returned by the API
=head1
he appropriate format (eg: if payload contains an hashref, and the format is json, the hashref B<MUST> be serialized to JSON).
=head1 METHODS
=over 4
=item serializer_key
name of the extension ser
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable( 'Redirection', max_redirect => 2 );
# or
$client->enable( 'Redir
;
my $response = Net::HTTP::Spore::Response->new(
200, ['Content-Type', 'application/json'], '{"foo":1}';
);
$response->request($request);
=head1 DESCRIPTION
Net::HTTP::Spore::R
hen the body is sets for the first time.
=item content_type
$res->content_type('application/json');
my $ct = $res->content_type;
Gets or sets the content type of the response body
=item co
ype' => 'application/json']);
Gets or sets HTTP response headers.
=item header
my $cl = $res->header('Content-Length');
$res->header('Content-Type' => 'application/json');
Shortcut for C<<
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('UserAgent', useragent => 'Mozilla/5.0 (X11; Linux x86_64; rv:2.0b4) Gecko
=> 'text/plain'], 'ok');
}
};
my $client = Net::HTTP::Spore->new_from_spec('spec.json');
$client->enable('Mock', tests => $mock_server);
my $res = $client->my_rest_method();
s;
use MooseX::Types -declare => [ qw(UriPath Boolean HTTPMethod JSONBoolean) ];
use MooseX::Types::Moose qw(Str Int Defined);
use JSON;
subtype UriPath,
as Str,
where { $_ =~ m!^/! },
me
as Int,
where { $_ eq 1 || $_ eq 0 };
subtype JSONBoolean,
as Defined,
where { JSON::is_bool($_) };
coerce Boolean,
from JSONBoolean,
via { return int($_) ? 1 : 0 },
fro
VERSION
version 0.09
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('Format::Text');
=head1 DESCRIPTION
Net::HTTP::Spore::Middleware::Format
ad1 VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('api.json');
$client->enable(
'Auth::Header',
header_name => 'X-API-Auth',
hea
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('github.json');
$client->enable('Auth::Basic', username => 'xxx', password => 'yyy');
=head1 DESCRIPTION
OPSIS
my $client = Net::HTTP::Spore->new_from_spec( 'google-url-shortener.json' );
$client->enable('Format::JSON');
$client->enable('Auth::OAuth',
oauth_consumer_key => '000000
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('twitter.json');
$client->enable('Format::XML');
=head1 DESCRIPTION
Net::HTTP::Spore::Middleware::Format:
hod;
{
$Net::HTTP::Spore::Meta::Method::VERSION = '0.05';
}
# ABSTRACT: create api method
use JSON;
use Moose;
use Moose::Util::TypeConstraints;
use MooseX::Types::Moose qw/Str Int ArrayRef HashR
=> qw(OPTIONS HEAD GET POST PUT DELETE TRACE);
subtype 'JSON::XS::Boolean' => as 'JSON::XS::Boolean';
subtype 'JSON::PP::Boolean' => as 'JSON::PP::Boolean';
subtype 'Boolean' => as Int =>
oolean'
=> from 'JSON::XS::Boolean'
=> via {
if ( JSON::is_bool($_) && $_ == JSON::true ) {
return 1
}
return 0;
}
=> from 'JSON::PP::Boolean'
=
VERSION
version 0.05
=head1 SYNOPSIS
my $client = Net::HTTP::Spore->new_from_spec('github.json');
$client->enable('Format::YAML');
=head1 DESCRIPTION
Net::HTTP::Spore::Middleware::Format
$Net::HTTP::Spore::VERSION = '0.05';
}
# ABSTRACT: SPORE client
use Moose;
use IO::All;
use JSON;
use Carp;
use Try::Tiny;
use Scalar::Util;
use Net::HTTP::Spore::Core;
# XXX should we let the
bject ) = @_;
my $spec;
try {
$spec = JSON::decode_json($string);
}
catch {
Carp::confess( "unable to parse JSON spec: " . $_ );
};
try {
$opts->{base
m_spec('twitter.json');
# for identica
my $client = Net::HTTP::Spore->new_from_spec('twitter.json', base_url => 'http://identi.ca/com/api');
$client->enable('Format::JSON');
my $tim