=> 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
layouts/ (required)
|----------- main.html (required)
|----- i18n/
|-------- es.json
|-------- he_and_it.coll.json
The C<app.psgi> file is a standard L<PSGI> application that configures and
initi
ews and templates reside. These will
mostly be HTML templates, but can actually be anything, even JSON or XML
or whatever. Views and templates are handled by Leyland's view classes,
and are rendered a
irectory. Once again, this is optional and
purely a suggestion. If used, this directory will hold JSON localization
files for localizing your application with L<Locale::Wolowitz>. See
L<Leyland::Manua
oo = ( bar => 'baz' );
$self->debug( "foo", "bar", "baz", \%foo );
$self->render( json => [] );
}
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee d
method receives the name of a view (or "template" if you will, such
as 'index.html' or 'resource.json'), and a hash-ref of variables to be
available for the template (known as the "context"). Leyland
new; # = MyLeylandApp
=item * Leyland no longer uses L<JSON::Any> as its JSON object. It now uses L<JSON> (which will automatically load L<JSON::XS> if available). The interface should be the same, b
robably should be aware of this change. Note, also, that C<convert_blessed> is now enabled on the JSON object.
=item * Leyland is now L<Moo>-based instead of L<Moose>-based, so it is much lighter tha
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 *
he request mime types, let's
# attempt to serialize the error ourselves if the client accepts
# JSON or XML
foreach (@{$c->wanted_mimes}) {
return $c->_respond(
$exp->code,
{ 'Content-Type'
mime} eq 'text/html' ||
$_->{mime} eq 'application/xhtml+xml' ||
$_->{mime} eq 'application/json' ||
$_->{mime} eq 'application/atom+xml' ||
$_->{mime} eq 'application/xml';
}
# We do n
s look at a pretty complete example:
get '^/posts$' accepts 'text/html|application/json' returns 'application/json' {
my @posts = MyDatabase->load_posts();
return { posts => \@posts };
}
The a
hat
has an empty prefix). It will only accept C<text/html> or C<application/json>
from the client, and will only return JSON. The following HTTP methods
are available:
=over
=item * get: for C<GET>
.
post '^/posts$' returns 'application/json' {
my @posts = $c->forward('GET:/posts');
# do stuff with @posts
}
get '^/posts$' returns 'application/json' is 'internal' {
return MyDatabase->l
e.
This is why I created L<Locale::Wolowitz>, which is a very simple localization
system based on JSON. This is also the reason why, as opposed to logging
and view classes, Leyland only provides C<Loc
TTP request and Leyland response
use Moo;
use namespace::clean;
use Carp;
use Data::Dumper;
use JSON;
use Leyland::Exception;
use Leyland::Logger;
use Module::Load;
use Text::SpanningTable;
use Try:
nvenience. You will use the C<set_user()> method
to set the value of this attribute.
=head2 json
A L<JSON::Any> object for usage by routes as they see fit.
=head2 xml
An L<XML::TreePP> object for
eq 'Leyland::Logger' }
);
has 'json' => (
is => 'ro',
isa => sub { die "json must be a JSON object" unless ref $_[0] && ref $_[0] eq 'JSON' },
default => sub { JSON->new->utf8(0)->convert_blessed
gs;
our $VERSION = '0.06';
use URI;
use URI::QueryParam;
use LWP::UserAgent;
use JSON::XS qw/encode_json decode_json/;
use Encode qw/decode/;
=pod
=encoding UTF-8
=head1 NAME
WebService::Redmi
edMine REST API. Please note that although
RedMine API is designed to support both JSON and XML, this module is B<JSON only>.
=head1 METHODS NAMING AND OTHER CALL CONVENTIONS
All methods are dynamic
f->{protocol}://$auth$self->{host}";
$self->{ua}->default_header('Content-Type' => 'application/json');
if (length $self->{key}) {
$self->{ua}->default_header('X-Redmine-API-Key' => $self->{key
no idea what went wrong",
mimes => {
'text/html' => 'error.html',
'application/json' => 'error.json',
},
});
# or you can create an error that redirects (don't do this unless
# you
TP::Request::Common qw(GET POST);
use URI;
use URI::QueryParam;
use LWP::UserAgent;
use JSON qw(to_json from_json);
use Carp qw(croak);
use Log::Any qw($log);
use Try::Tiny;
has scheme => (is => 'ro
(
q => $query,
format => 'json',
env => 'store://datatables.org/alltableswithkeys',
jsonCompat => 'new',
);
my $uri = URI->new($self->u
$res = $self->ua->request($req);
}
return from_json $res->content
if $res->code =~ /^4/x;
return $res->content ? from_json($res->content)->{query}{results} : 1;
}
sub _log_conte
package Plack::Middleware::JSONParser;
use strict;
use warnings;
use JSON;
use Hash::MultiValue;
use Plack::Request;
our $VERSION = "0.02";
use parent 'Plack::Middleware';
sub call {
my ($self,
m{\Aapplication/json}o) {
my $req = Plack::Request->new( $env );
my $raw_body = $req->raw_body();
return $self->app->($env) unless ($raw_body);
my $json;
{
local $@;
$json = eval { decode_json($raw_body) };
if ($@) {
die $@ if $self->{die_when_failed};
$env->{'plack.middleware.jsonparser.error'} = $@;
the JSON.pm like interface.
=head1 WHY?
I need data dumper library supports JSON::XS/JSON::PP like interface.
I use JSON::XS really hard. Then, I want to use other serialization library with JSON::X
t. Suggestions are returned as a tree
of hash and list references that correspond to the returned JSON data
structure. The most important parameters and result elements are described bellow.
For the f
SPATCH' => sub {
$_[0]->{chrome_logger} = Web::ChromeLogger->new(
json_encoder => $conf->{json_encoder},
);
});
$c->add_trigger('AFTER_DISPATCH' => sub {
$
By default, this plugin is disabled under PLACK_ENV:production environment.
=head2 json_encoder
You can pass C<json_encoder> to L<WEB::ChromeLogger>.
=head1 REPOSITORY
Amon2::Plugin::Web::ChromeL
tmandu> command line client can be used like this:
catmandu import JSON to DBI --data_source SQLite:mydb.sqlite < data.json
=head1 DESCRIPTION
A Catmandu::Store::DBI is a Perl package that can
:ChromeLogger;
use parent 'Plack::Middleware';
use Plack::Util;
use Plack::Util::Accessor qw/
json_encoder
enable_in_production
disabled
/;
our $VERSION = '0.01';
sub prepare_app {
m
sabled ) {
$env->{'psgix.chrome_logger'} = Web::ChromeLogger->new(
json_encoder => $self->json_encoder,
);
}
my $res = $self->app->($env);
$self->response_cb(
d1 METHODS
=over
=item prepare_app
=item call
=back
=head1 MIDDLEWARE OPTIONS
=over
=item json_encoder
pass to L<Web::ChromeLogger>. Who need to set this parameter ?
=item enable_in_producti
:Plugin::Notify::PagerDuty;
use 5.010;
use Mouse::Role;
use LWP::UserAgent;
use URI::Escape;
use JSON;
use Data::Dumper;
# ABSTRACT: Plugin for TheEye to raise alerts in Pager Duty
#
our $VERSION =
required => 1,
default => 'https://events.pagerduty.com/generic/2010-04-15/create_event.json',
);
has 'pd_err' => (
is => 'rw',
isa => 'HashRef',
required => 0,
T');
$req->uri($self->pd_url);
$req->header('Content-Type' => 'application/json');
$req->content( to_json($content) ) if ($content);
my $ua = LWP::UserAgent->new();
my $res = $u
azy => 1,
required => 1,
default => 'https://api.hipchat.com/v1/rooms/message?format=json&auth_token=',
);
has 'hc_err' => (
is => 'rw',
isa => 'HashRef',
requir