$self->util->methods... or not
has _json => (
is => 'rw'
, isa => 'JSON::XS'
, lazy => 1
, required => 1
, default => sub {
require JSON::XS;
return JSON::XS->new->utf8->ascii->relaxed;
}
ent', tied => 1 );
}
# Leave it up to the API implementation to encode the hash/array ref into JSON / Form data / XML / etc.
$req->content( $args{content} ) if defined $args{content};
$req->metho
ncode {
my ( $self, %args ) = @_;
my ( $data );
for ( $args{type} ) {
when ( 'json' ) {
$data = $self->_json->encode( $args{data} );
}
when ( 'xml' ) {
$data = $self->_xml->write( $arg
$self->ua->request( $req );
if ( $res->code == 200 ) {
my $data = $self->_decode( type => 'json', data => $res->content );
$data->{expires_at} = time + $data->{expires_in};
$self->merge_c
$req->content ) {
my $json = $self->_encode( type => 'json', data => $data );
$req->content( $json );
$req->headers->header( 'Content-Type' => 'application/json; charset=utf-8' );
#
Uncomment this to view generated JSON content.
# $self->debug( $json );
}
}
, m_scheme => $scheme
, m_host => $host
, m_path_match => qr/^\Q$path\E/
);
# Add response wrapper.
$self
( $res, $ua, $h ) = @_;
if ( my $data = $res->content ) {
$data = $self->_decode( type => 'json', data => $data );
$res->content( $data );
}
}
, m_scheme => $scheme
, m_host => $ho