res->{data};
}
else {
my $data = $res->{data} && $res->{data}->$* ? P->data->from_json( $res->{data} ) : undef;
return res $res->{status}, $data;
}
}
sub _req2 ( $self, $
tent-Type' => 'application/json',
],
data => $data ? P->data->to_json($data) : undef
);
$data = $res->{data} && $res->{data}->$* ? P->data->from_json( $res->{data} ) : undef;
#!/usr/bin/env perl
package main v0.1.0;
use Pcore;
use Pcore::Util::Data qw[from_json to_json];
use Pcore::Util::Text qw[decode_utf8 encode_utf8];
my $cv = P->cv;
AnyEvent::Socket::tcp_server( '1
\n");
last if !$msg;
# decode message, ignore invalid json
eval { $msg = from_json $msg->$*; 1; } or last;
my $cmd = 'CMD_' . ( delete( $msg->[1]->{c
data => encode_utf8( $args->{data} ),
ignore => 0,
}
);
my $json = to_json [
$id,
{ status => $res->{status},
reason => $res->{
ri( {
key => $self->{api_key},
action => 'get',
id => $id,
json => 0,
} );
my $url = P->uri( "$self->{api_host}/res.php?$q", proxy => $self->{proxy} )
blem => 'parameter_absent',
oauth_parameters_absent => 'oauth_consumer_key',
}
=item JSON error output
For example
{
error => { id => '9e9c7bddeff3',
mess
ose;
use Try::Tiny;
use OAuthomatic::Internal::Util qw/parse_http_msg_form parse_http_msg_json/;
use Data::Dump qw(dump);
use namespace::sweep;
extends 'OAuthomatic::Error';
w
e =~ m{^application/(?:x-)?json}x) {
try {
$reply = parse_http_msg_json($response);
};
}
# FIXME: maybe compact JSON level up if it contains ju
s;
use Pcore::Util::Scalar qw [is_plain_arrayref];
use Pcore::Util::Data qw[to_b64 to_uri to_json from_json];
has api_user => ( required => 1 );
has api_key => ( required => 1 );
has free =>
data => to_json $params,
);
if ($res) {
my $data = from_json $res->{data};
$res = res 200, $data;
}
elsif ( $res->{data} ) {
my $data = from_json $res->{data
Pcore::Core::Event::Listener::file;
use Pcore -class, -ansi, -const;
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Scalar qw[is_ref];
use Fcntl qw[:flock];
use IO::File;
use Time::HiRes qw[];
->{data} ) {
# serialize reference
$ev->{text} = is_ref $ev->{data} ? to_json $ev->{data}, readable => 1 : $ev->{data};
# indent
$ev->{text} =~ s/^/$I
_json fill_httpmsg_json parse_http_msg_json);
use HTTP::Request;
use HTTP::Response;
use HTTP::Body;
use URI;
use URI::QueryParam;
use Encode;
use utf8;
use JSON qw/decode_json encode_json from_json
to_json/;
use Try::Tiny;
use Scalar::Util qw(reftype);
use namespace::sweep;
# FIXME: throw on errors
sub fill_httpmsg_form {
my ($http_message, $params) = @_;
my $body_form = URI->new('ht
json {
my $json = shift;
if(reftype($json) =~ /^(?:HASH|ARRAY)$/) {
return encode_json($json); # FIXME rethrow exception as sth better
}
elsif(! ref($json) || reftype($json
package Pcore::App::Controller::API;
use Pcore -role, -const;
use Pcore::Util::Data qw[from_json to_json from_cbor to_cbor];
use Pcore::Util::Scalar qw[is_plain_arrayref];
use Pcore::WebSocket::softv
_TYPE} =~ m[\bapplication/json\b]smi ) {
$msg = eval { from_json $req->{data} };
# content decode error
return 400, q[Error decoding JSON request body] if $@;
cbor $req->{data} };
# content decode error
return 400, q[Error decoding JSON request body] if $@;
$CBOR = 1;
}
# invalid content type
el
e Pcore -class, -ansi, -const;
use Pcore::Util::Text qw[remove_ansi];
use Pcore::Util::Data qw[to_json];
use Pcore::Util::Scalar qw[is_ref];
use Time::HiRes qw[];
with qw[Pcore::Core::Event::Listener
->{data} ) {
# serialize reference
$ev->{text} = is_ref $ev->{data} ? to_json $ev->{data}, readable => 1 : $ev->{data};
# indent
$ev->{text} =~ s/^/$I
# Maybe [Str]
has permissions => (); # Maybe [HashRef]
*TO_JSON = *TO_CBOR = sub ($self) {
return { $self->%{qw[is_authenticated user_id user_name permission
com/api2/moz/$self->{api_key}/$domain]);
return $res if !$res;
my $data = P->data->from_json( $res->{data} );
return res 200, $data;
}
1;
__END__
=pod
=encoding utf8
=head1 NAME
Pco
use Pcore::Util::Scalar qw[is_plain_arrayref];
use Pcore::Util::Data qw[to_cbor from_cbor to_json from_json];
use Pcore::Util::UUID qw[uuid_v1mc_str];
use Pcore::HTTP qw[:TLS_CTX];
use Pcore::WebSocke
();
has api_ver => (); # eg: 'v1', default API version for relative methods
has use_json => ();
has timeout => ();
has connect_timeout => 10;
has tls_ctx => $TLS_CTX_HIG
ken}",
'Content-Type' => $self->{use_json} ? 'application/json' : 'application/cbor',
],
data => $self->{use_json} ? to_json $payload : to_cbor $payload
);
if ( !$
on;
use OAuthomatic::Internal::UsageGuard;
use OAuthomatic::Internal::Util qw/serialize_json parse_http_msg_json/;
use OAuthomatic::ServerDef qw/oauthomatic_predefined_for_name/;
####################
}
sub get_json {
my ($self, $url, $url_args) = @_;
my $r = $self->execute_request(
method => "GET", url => $url, url_args => $url_args);
return parse_http_msg_json($r, 'force'
ent;
}
sub post_json {
my $self = shift;
my $url = shift;
my @args = (method => "POST",
url => $url,
content_type => 'application/json; charset=utf-8');
t;
use Pcore::API::Chrome::Tab;
use Pcore::Util::Scalar qw[weaken];
use Pcore::Util::Data qw[from_json];
use Pcore::API::Proxy;
use Pcore::API::Proxy::Server;
has bin => ();
has listen => '//
ub tabs ( $self ) {
my $res = P->http->get("http://$self->{listen}->{host_port}/json");
my $tabs = from_json $res->{data};
for my $tab ( $tabs->@* ) {
$tab = bless { chrome => $s
{
my $res = P->http->get( "http://$self->{listen}->{host_port}/json/new?" . ( $url // 'about:blank' ) );
my $data = from_json $res->{data};
my $tab = bless { chrome => $self, id => $data
ckage Pcore::API::Facebook;
use Pcore -const, -class, -res;
use Pcore::Util::Data qw[to_uri from_json];
use Pcore::Util::Scalar qw[is_plain_arrayref];
with qw[
Pcore::API::Facebook::User
Pcore::
,
url => $url,
data => $data,
);
my $res_data = $res->{data} ? from_json $res->{data} : undef;
if ($res) {
if ($res_data) {
if ( $res_data->{pagi
nt-Type' => 'application/json',
],
data => $data ? P->data->to_json($data) : undef
);
my $data = $res->{data} && $res->{data}->$* ? P->data->from_json( $res->{data} ) : undef;
x' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'json' => 'application/json',
};
if ( $filename =~ m/\.([^.]+)\z/ ) {
my $extension = lc( $1 );
>set_scandeps("$dist->{share_dir}/pardeps-$self->{SCRIPT_NAME}-@{[$^V->normal]}-$Config{archname}.json");
}
}
return;
}
sub set_scandeps ( $self, $path ) {
$self->{SCANDEPS} = $p
return $self->{main_dist};
}
}
END {
if ( $ENV->{SCANDEPS} ) {
require Cpanel::JSON::XS; ## no critic qw[Modules::ProhibitEvilModules]
my ( $fh, $index );
if (
n]
flock $fh, LOCK_EX or die;
local $/;
my $deps = Cpanel::JSON::XS->new->utf8->decode(<$fh>);
$index->@{ $deps->@* } = ();
}
else {
y $tree = $self->_gather_files;
$self->_generate_build_pl($tree);
$self->_generate_meta_json($tree);
my $path;
if ($keep) {
$path = P->path( "$self->{dist}->{root}/data/.bu
PL();
BUILD_PL
$tree->add_file( 'Build.PL', \$template );
return;
}
sub _generate_meta_json ( $self, $tree ) {
my $meta = {
abstract => 'unknown',
author => [
_string_hash;
# add META.json
$tree->add_file( 'META.json', \CPAN::Meta->create($meta)->as_string );
# P->file->write_text( "$self->{dist}->{root}/META.json", { crlf => 0 }, CPAN::Meta->
Module::Build
'_build/',
];
const our $FILE => [
# general build
qw[META.json META.yml MYMETA.json MYMETA.yml],
# Module::Build
qw[_build_params Build.PL Build Build.bat],