Mine::Role::KnowsJSON;
use Moose::Role;
use JSON -support_by_pp;
has json => (
isa => 'JSON',
is => 'ro',
lazy_build => 1,
handles => ['decode'],
);
sub _build_json {
my $self =
shift;
# Be as generous as possible to input.
return JSON->new->relaxed->allow_singlequote->allow_barekey->allow_nonref;
}
1;
h my %OUTPUT => (
'json' => q{application/json},
'xml' => q{text/xml},
'php' => q{text/plain},
);
Readonly::Hash my %RESPONSE => (
'version' => {
'json' => q{{
"version":
2:{s:7:"version";s:2:"v1";s:5:"build";s:5:"0.0.1";}}}},
},
'latest_article' => {
'json' => q{{
"latest_article": [
[
{
"id": "156833"
"type": "artic
]></keyword>
</keywords>
</article>
</list>},
},
'latest_video' => {
'json' => q{{
"latest_video": [
[
{
"id": "175327"
;
use utf8;
use LWP;
use LWP::Protocol::https;
use HTML::Entities;
use URI::Escape;
use JSON::XS qw/decode_json/;
use Encode;
our $VERSION = 0.08;
sub new {
my ($class, %args) = @_;
die 'USAGE:
s->is_success;
my $json_str = (split /<!>/, $res->decoded_content)[5];
$json_str =~ s/'/"/gs;
$json_str = Encode::encode('utf-8', $json_str);
my $json = decode_json($json_str);
return 'Inva
lid response' unless defined $json->{all} && ref($json->{all}) eq 'ARRAY';
my @rslt;
for my $item(@{$json->{all}}) {
next unless ref $item eq 'ARRAY' && scalar @{$item} > 7;
my $name = de
if ($args{serialize} eq "JSON") {
require JSON::Any;
JSON::Any->import;
my $json = JSON::Any->new;
$self->{serialize} = sub { $json->objToJson( [@_] ) };
$sel
f->{unserialize} = sub { (@{ $json->jsonToObj(@_) })[0] };
} elsif ($args{serialize} eq "Storable") {
require Storable;
$self->{serialize} = sub { Storable::nfreeze( [@_] )};
Any/Dump> and L<YAML::Any/Load> to serialize and deserialize
data.
=item JSON
Use L<JSON::Any/objToJson> and L<JSON::Any/jsonToObj> to serialize and
deserialize.
=item Storable
Use L<Storable/nfre
se Webservice::InterMine::Path;
use Webservice::InterMine::Model;
my @JSON_FORMATS = (qw/jsonobjects jsonrows jsondatatable json/);
my @SIMPLE_FORMATS = (qw/tsv tab csv count xml/);
=head2 new( $url
'/query/upload',
QUERY_LIST_PATH => '/query/tolist/json',
QUERY_LIST_APPEND_PATH => '/query/append/tolist/json',
MODEL_PATH => '/model',
TEMPLATES_PAT
ate/upload',
TEMPLATE_LIST_PATH => '/template/tolist/json',
TEMPLATE_LIST_APPEND_PATH => '/template/append/tolist/json',
VERSION_PATH => '/version',
RELEASE_PAT
;
require Set::Object;
use constant {
LIST_APPEND_PATH => '/lists/append/json',
RENAME_PATH => '/lists/rename/json',
LISTABLE => 'Webservice::InterMine::Role::Listable',
LIST => 'Webs
ot . ENRICHMENT_PATH);
my $iterator = $self->service->get_results_iterator($uri, \%form, [], "json", "perl", []);
return $iterator;
}
=head2 to_query
Return a L<Webservice::InterMine::Query>
s
qw(HTTP_OK HTTP_BAD_REQUEST HTTP_UNAUTHORIZED HTTP_FORBIDDEN HTTP_INTERNAL_SERVER_ERROR);
use JSON;
use LWP::UserAgent;
use Log::Log4perl qw(:easy get_logger);
use Moose qw/around has with/;
use M
ERR{'INTERNAL_SERVER'},
);
}
elsif ( $response->code > HTTP_OK ) {
my $json = JSON->new;
if ( $response->code == HTTP_BAD_REQUEST ) {
## no critic qw(Requir
NOSOpenBadRequestException->throw(
## use critic
'error' => $json->decode( $response->decoded_content ),
);
}
elsif ( $response->code =
ice::InterMine::Role::KnowsJSON';
use LWP::UserAgent;
use Webservice::InterMine::Types qw/UserAgent/;
use constant REGISTRY => 'http://www.intermine.org/registry/mines.json';
has ua => (
is => '
Listables
ListOperable ListOfListOperables
RowParser
RowFormat
JsonFormat
RequestFormat
TSVFormat
File
NotAllLowerCase
Date
'jsonobjects', 'jsonrows', 'jsondatatable', 'count', 'json'];
enum JsonFormat, ['perl', 'inflate', 'instantiate'];
enum RequestFormat, ['tab', 'csv', 'count', 'jsonobjects', 'jsonrows', 'xml', 'jsond
atatable', 'json'];
subtype TSVFormat, as Str, where {/^tsv$/i};
class_type ResultIterator, {class => 'Webservice::InterMine::ResultIterator'};
coerce RowFormat, from NotAllLowerCase, via { lc($_) }
le opened for writing.
=item * as => $format
Possible values: (tsv|csv|arrayrefs|hashrefs|jsonobjects|jsonrows|count)
The format to print results in. The default is C<tsv>
=item * size => $size
T
m * json => $json_processor
Possible values: (inflate|instantiate|perl)
What to do with JSON results. The results can be returned as inflated objects,
full instantiated Moose objects, a raw json str
my $self = shift;
my $constraints = shift;
my $results_args = shift || {as => 'jsonobjects', json => 'instantiate'};
if (ref $constraints eq 'HASH') {
while (my ($path, $con) =
expressions or strings will cause exceptions to be thrown.
=head2 results([as => $format], [json => $jsonhandler])
Gets the results for this query in a variety of formats. (see
L<Webservice::InterM
item * jsonobjects
By default returns an arrayref of native perl data structures (hashrefs) which
correspond to the data format of InterMine jsonobjects
(L<http://www.intermine.org/wiki/JSONObjectF
ormat>).
Optionally it can return the jsonobjects processed as:
=over 8
=item * raw: the raw text string
=item * inflate: inflated objects using autoload
The inflated objects allow method access
terating over rows of results.
The formats that are supported by the possible values service
are jsonobjects (the default), and count formats. However, for accessing
counts, and even values, it is pr
my $format = shift || 'jsonobjects';
my $service = $self->{service};
my $uri = $service->root . $service->POSSIBLE_VALUES_PATH;
require JSON;
my $json = JSON->new;
my $params =
{
path => $self->{path},
typeConstraints => $json->encode($self->{subtypes}),
};
my $iter = $service->get_results_iterator(
$uri, $params, [], $format, 'perl', []);
5.008001;
use JSON ();
use Furl::HTTP;
use MIME::Base64;
use ArangoDB::ConnectOptions;
use ArangoDB::ServerException;
use Class::Accessor::Lite ( ro => [qw/options/] );
my $JSON = JSON->new->utf8;
my ( $self, $path, $data, $raw, $additional_headers ) = @_;
if( !$raw ){
$data = $JSON->encode( defined $data ? $data : {} );
}
my $headers = $self->_build_headers($data, $addi
my ( $self, $path, $data, $raw, $additional_headers ) = @_;
if( !$raw ){
$data = $JSON->encode( defined $data ? $data : {} );
}
my $headers = $self->_build_headers($data, $addi
Go APIs
use Moo;
use LWP::UserAgent;
use HTTP::Request;
use WWW::DuckDuckGo::ZeroClickInfo;
use JSON;
use URI;
use URI::QueryParam;
our $VERSION ||= '0.0development';
has _duckduckgo_api_url => (
;
my %params = %{$self->params};
$uri->query_param( q => $query );
$uri->query_param( o => 'json' );
$uri->query_param( kp => -1 ) if $self->safeoff;
$uri->query_param( no_redirect => 1 );
_by_response {
my ( $self, $response ) = @_;
if ($response->is_success) {
my $result = decode_json($response->content);
return $self->_zeroclickinfo_class->by($result);
} else {
die __PACKAGE
package ArangoDB::Collection;
use strict;
use warnings;
use utf8;
use 5.008001;
use JSON ();
use Carp qw(croak);
use Scalar::Util qw(weaken);
use Class::Accessor::Lite ( ro => [qw/id status/], );
use
goDB::ClientException;
use overload
q{""} => sub { shift->id },
fallback => 1;
my $JSON = JSON->new->utf8;
=pod
=head1 NAME
ArangoDB::Collection - An ArangoDB collection
=head1 DESCRIP
ut
sub wait_for_sync {
my $self = shift;
if ( @_ > 0 ) {
my $val = $_[0] ? JSON::true : JSON::false;
my $res = $self->_put_to_this( 'properties', { waitForSync => $val } );
'script[src="foo.js"]@src' => 'http://prod-server/foo.js',
'//script[2]' => 'var = ' . JSON::to_json($var_to_js),
});
__DATA__
<html>
<script type="text/javascript" src="foo.js"></scrip
ge ArangoDB::Statement;
use strict;
use warnings;
use utf8;
use 5.008001;
use Carp qw(croak);
use JSON ();
use Scalar::Util qw(weaken);
use ArangoDB::Cursor;
use ArangoDB::BindVars;
use ArangoDB::Cons
;
my $data = {
query => $self->{query},
count => $options->{do_count} ? JSON::true : JSON::false,
};
if ( $self->{bind_vars}->count > 0 ) {
$data->{bindVars} = $se
package Forex;
use JSON::XS;
use DateTime;
use LWP::UserAgent;
our $LASTERROR = undef;
$VERSION = '1.2';
=pod
=head1 NAME
Forex - Historic Foreign Exchange Rates from Open Exchange Rates
=hea
e->is_success )
{ $self->{ 'CONTENT' } = decode_json $response->decoded_content; $LASTERROR = undef; }
else
{ $self->{ 'ERROR'} = decode_json $response->decoded_content;
$LASTERROR = 1; }
->{'API_HOOK' },
'historical' ,
$request_day->ymd('-') . '.json' );
$self->{'REQUEST_URL'} .= '?app_id=' . $self->{'APP_ID'}
. "&base=" . $se
el free to setup your C<$driver>
this way:
package My::Workers::One;
use Moose;
use JSON::XS;
extends 'Gearman::Driver::Worker::Base';
# this method will be registered with gear
ode_json {
my ( $self, $result ) = @_;
return JSON::XS::encode_json($result);
}
sub decode_json {
my ( $self, $workload ) = @_;
return JSON::XS::decode_json($w
_method_by_name($method)->body,
decode => 'decode_json',
encode => 'encode_json',
name => $method,
},