package WWW::JSON;
use 5.008005;
use strict;
use warnings;
our $VERSION = "1.02";
use LWP::UserAgent;
use Moo;
use Try::Tiny;
use URI;
use WWW::JSON::Response;
use Safe::Isa;
use JSON::XS;
use HTTP::
ormat $_[0]"
unless ( $_[0] eq 'serialized' || $_[0] eq 'JSON' );
}
);
has json =>
( is => 'ro', default => sub { JSON::XS->new->utf8->allow_nonref } );
has content_type => ( is => 'r
0] ) eq 'CODE';
}
);
has ua_options => ( is => 'lazy', default => sub { +{} } );
with 'WWW::JSON::Role::Authentication';
my %METHOD_DISPATCH = (
GET => \&HTTP::Request::Common::GET,
P
package WWW::JSON::Role::Authentication::OAuth1;
use Moo::Role;
use Net::OAuth;
use URI;
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
requires 'authentication';
requires 'ua';
s
_OAuth1 {
my ( $self, $auth, $req) = @_;
my $q = URI->new;
# FIXME if we're sending a JSON payload we need to decode instead of this
$q->query($req->content);
my $request = Net::OA
package WWW::JSON::Role::Authentication::Basic;
use Moo::Role;
use MIME::Base64;
requires 'authentication';
requires 'ua';
sub _validate_Basic {
my ( $self, $auth ) = @_;
for (qw/username pa
package WWW::JSON::Role::Authentication;
use Moo::Role;
has authentication => (
is => 'rw',
lazy => 1,
clearer => 1,
default => sub { +{} },
isa => sub {
return if
$self->$orig(@_);
};
with qw/WWW::JSON::Role::Authentication::Basic
WWW::JSON::Role::Authentication::OAuth1
WWW::JSON::Role::Authentication::OAuth2
WWW::JSON::Role::Authentication::Header
/;
package WWW::JSON::Role::Authentication::OAuth2;
use Moo::Role;
use Safe::Isa;
requires 'authentication';
requires 'ua';
sub _validate_OAuth2 {
my ( $self, $auth ) = @_;
die "Must pass a Net:
package WWW::JSON::Role::Authentication::Header;
use Moo::Role;
requires 'authentication';
requires 'ua';
sub _validate_Header {
my ( $self, $auth ) = @_;
die "Required header string missing
package WWW::JSON::Response;
use strict;
use warnings;
use Moo;
use JSON::XS;
use Try::Tiny;
has http_response => (
is => 'ro',
required => 1,
handles => {
status_line => '
rl => 'base',
content => 'decoded_content',
},
);
has json => ( is => 'lazy', default => sub { JSON::XS->new } );
has response => ( is => 'lazy', builder => '_build_
return unless ($self->http_response->decoded_content);
my $decoded = try {
$self->json->decode( $self->http_response->decoded_content );
}
catch {
$self->_set_error("$_