croak);
use URI::Escape;
use Digest::MD5 qw(md5_hex);
use Socket;
use WWW::Curl::Easy;
use JSON qw(decode_json);
our $VERSION = '0.02';
sub new {
my $class = shift;
my $self = bless({}, $cla
. uri_escape($value));
}
}
# add default params
push(@request_params, "f=json");
my ($http_code, $buffer) = $self->_query_api(join("&", @request_params));
#
my $decoded_json = decode_json($buffer);
if(not defined $decoded_json->{'success'}) {
warn "unable to read json";
return 1;
} elsif($decoded_json->{'success'} == 0) {
, namespace => decamelize( ref $app ) .':'. $app->mode
, serializer => { serializer => 'JSON::XS', compress => 1 }
};
$app->attr( __chi => sub {
return new CHI ( %{ $opts->{
ace => decamelize( ref $self ) .':'. $self->mode
, serializer => { serializer => 'JSON::XS', compress => 1 }
}
} );
}
then
package App::Example;
use M
me_results;
return $res;
}, expires_in => 60 );
return $self->render( json => { res1 => $res1, res3 => $res3, also_res1 => $also_res1, res2 => $res2 } );
}
See L<CHI>
ackage WWW::Jawbone::Up::User;
use 5.010;
use strict;
use warnings;
use base 'WWW::Jawbone::Up::JSON';
__PACKAGE__->add_accessors(
qw(first last name short_name), {
friend => 'user_is_friend'
se;
use JSON::Any;
use Method::Signatures;
use Carp;
use Moose::Util::TypeConstraints;
# ABSTRACT: Raw, low-level access to Exobrain packets
our $VERSION = '1.08'; # VERSION
my $json = JSON::Any->
s[0];
my (undef, $namespace, $source) = split(/_/, $frames->[0]);
my $metadata = $json->decode( $frames->[1] );
return $class->$orig(
namespace => $namespace,
es},
summary => $frames->[2],
data => $json->decode( $frames->[3] ),
raw => $json->decode( $frames->[4] ),
nosend => 1,
);
}
age WWW::Jawbone::Up::Workout;
use 5.010;
use strict;
use warnings;
use base 'WWW::Jawbone::Up::JSON';
__PACKAGE__->add_accessors(qw(title), { complete => 'is_complete' });
__PACKAGE__->add_time_a
package Exobrain::JSONify;
use Moose::Role;
use Storable qw(dclone);
use Data::Structure::Util qw(unbless);
# Basic role that allows converting self object into JSON.
# Really we should use MooseX::S
sub TO_JSON {
my ($self) = @_;
return unbless dclone $self; # Yuck!
}
1;
__END__
=pod
=head1 NAME
Exobrain::JSONify
=head1 VERSION
version 1.08
=for Pod::Coverage TO_JSON
=head1
Constraints;
use Carp;
use ZMQ::Constants qw(ZMQ_SNDMORE);
use ZMQ;
use JSON::Any;
use Data::Dumper;
use Exobrain::Types qw(JSON);
# ABSTRACT: Top-level role for all exobrain messages
our $VERSION =
# data.
requires qw(summary);
# TODO: We should use JSON::XS, because we need specialised features
# for handling objects.
my $json = JSON::Any->new( convert_blessed => 1 );
# We define a du
s;
push(@frames, join("_", "EXOBRAIN", $self->namespace, $self->source));
push(@frames, $json->encode( {
timestamp => $self->timestamp,
roles => $self->roles,
# TO
d2Inao::Builder;
use utf8;
use strict;
use warnings;
use Class::Accessor::Fast qw/antlers/;
use JSON;
use Path::Tiny;
has dispatch_table => ( is => 'rw' );
has before_filter_config => ( is => 'rw
ult};
}
sub load_filter_config {
my ($self, $path) = @_;
my $json = path($path)->slurp;
my $config = decode_json $json;
for (qw/before_filter after_filter/) {
if ($config->{$_
%full_args );
# Make our call, and decode the resulting JSON.
$self->mech->get("$base/$path?$arguments");
return $self->json->decode( $self->mech->content );
}
1;
__END__
=pod
=hea
nings;
use JSON::Any;
# ABSTRACT: Type system for Exobrain
our $VERSION = '1.08'; # VERSION
my $json = JSON::Any->new( allow_blessed => 1 );
use MooseX::Types -declare => [qw(
JSON
POI
HashRef
Ref
Str
Num
Int
);
subtype JSON,
as Str,
where { $json->decode($_) }
;
coerce JSON,
from Ref,
via { $json->encode($_) }
;
subtype SmsStr,
as Str,
wh
:Google::Plus::UserInfo;
use Moo;
use MooX::late;
use LWP::UserAgent;
use JSON qw|decode_json|;
use Carp::Assert;
use URI;
has access_token => (
is => 'ro
esponse );
if( $response->is_success ){
my $json = decode_json( $response->content );
return $json;
}
return {};
}
sub is_success {
tically available for you here
$c->template('stuff.html');
}
post '^/$' returns 'application/json' {
# do stuff
}
1;
=head1 DESCRIPTION
This module is meant to be used by <Leyland controll
se 5.008_001;
our $VERSION = '0.05';
eval $VERSION;
use HTTP::Request;
use URI;
use JSON qw(encode_json decode_json);
use LWP::UserAgent;
require Carp;
sub new {
my ($class, $api_key, @args) = @
if ($data) {
$method = 'POST';
$data = encode_json $data;
push @fields, 'Content-Type' => 'application/json';
}
my $request = HTTP::Request->new(
$method =
($http_response->status_line)
unless $http_response->is_success;
my $response = decode_json($http_response->decoded_content);
if (my $error = $response->{error}) {
my $messages
use base qw(Template::Plugin);
use Template::Plugin;
use Template::Plugin::React::RESimple;
use JSON;
use Encode;
sub from_file {
my ($fname) = @_;
my $out = '';
open my $fh, '<:encodi
tes => $templates
}, $class;
}
sub render {
my ($self, $name, $data) = @_;
my $json = to_json($data // {}, {utf8 => 1});
my $built = from_file $self->{templates};
my $res = $sel
$self->{prelude};
var React = global.React;
$built;
return React.renderComponentToString($name($json));
})();
|);
if($res) {
return Encode::decode("utf8", $self->{ctx}->output());
ces to representations in the format your client
wants to receive, like JSON and XML. It will also automatically deserialize
JSON/XML requests coming from the client to Perl data-structures.
=item *
kage OAuth2::Google::Plus;
use Moo;
use MooX::late;
use Carp::Assert;
use JSON qw|decode_json|;
use LWP::UserAgent;
use URI;
sub ENDPOINT_URL {
return 'https://ac
onse( $response );
if( $response->is_success ){
my $json = decode_json( $response->content );
return $json->{access_token};
}
return;
}
}
1;
n catches the exception and properly serializes it to a format
the client supports, such as HTML, JSON or XML (or plain text when the client
does not support any of these formats). If the request was
turned to the browser. If the
request was initiated from a JSON client, such as with an AJAX request, then
the error will be returned in JSON format.
=head1 PRETTIFYING EXCEPTIONS
By default, when r
hash-ref passed to C<< $c->exception() >>, you can, for example, add a template
for C<application/json> requests if you see fit.
In the future, I plan to have Leyland make it easier to globally set t
the
clients are web browsers, but also RSS/Atom when your clients are
feed readers and maybe even JSON if your platform has some cool AJAX admin
interface to it.
=head1 DATA SERIALIZATION
Before we
ormat
such as XML or JSON. The reverse process is called deserialization.
Leyland takes care of both processes by itself. If you have resources for
which you wish to generate JSON/XML representations
'applications/json'> for example, see L<Leyland::Manual::Controllers/"ROUTES">
for more information), and just return the data structure as-is from the
route. If the client accepts JSON/XML, Leyland
ai::Open::DiagnosticTools::VERSION = '0.02';
use strict;
use warnings;
use v5.10;
use Moose;
use JSON;
#XXX create a useful scheme for REST methods
use constant {
TOOLS_URI => '/diagnostic-tool
(sprintf('HTTP response code for dig() call is %s', $self->response->code()));
$data = decode_json($self->response->content());
given($self->response->code()) {
when($_ == 200) {
(sprintf('HTTP response code for mtr() call is %s', $self->response->code()));
$data = decode_json($self->response->content());
given($self->response->code()) {
when($_ == 200) {
=> eval {
return 0 if HAVE_HTTP_TINY; # unnecessary
require LWP::UserAgent; 1;
};
use JSON::PP;
use constant ENDPOINT_URL => 'https://api.pushover.net';
use constant HTTP_TIMEOUT => 1
my $res = $self->_http_get( ENDPOINT_URL . '/1/sounds.json?token=' . $self->{token} );
if ( $res->{success} ) {
my $data = $self->_json_parser->decode($res->{content});
my @sounds
Sounds API is failed.";
}
}
# JSON Parser accessor
sub _json_parser {
my $self = shift;
$self->{json_parser} ||= JSON::PP->new();
return $self->{json_parser};
}
# Browser accessor
su