ed to provide methods for
encrypting messages and/or converting them into various target formats
(JSON, HTML, Morse code, etc.).
For details, see </Localization in depth> and <App::CELL::Message>.
ay of transactions for that time span. Each transaction is a hash of data.
=cut
use Moose;
use JSON;
use REST::Client;
#use Data::Dump qw(dump); # used in some commented out debug statements
#use S
'Content-Type' => 'application/json; charset=UTF-8',
'Accept' => 'application/json; charset=UTF-8',
VERSION => 2,
>password,
};
# my $jdata = encode_json($data);
my $jdata=JSON->new->canonical->encode($data);
my $client = REST::Client->n
#!/home/ben/software/install/bin/perl
use Z;
use Test::More;
use MetaCPAN::Client;
use JSON::Create 'create_json';
use Perl::Build::Pod qw!$mod_re see_also!;
# Read the file in & extract the section
v} = $fav->total ();
push @modules, \%info;
}
};
if ($@) {
print "error: $@";
}
my $mtext = create_json (\@modules, sort => 1, indent => 1);
write_text ("$Bin/see-also-info.json", $mtext);
ckage REST::Client;
use strict;
no strict 'refs';
use warnings;
no warnings 'redefine';
use JSON;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $datapath;
our $fdebug=0; # set to 1 prints som
$self,
\@_,
JSON->new->canonical->encode(
{ content=>decode_json($self->responseContent) ,
e_json($headers);
#print "headers#1=$headers\n";
my $jheaders=JSON->new->canonical->encode($headers);
# print "After POST url=$url jdata=$jdata jheaders=$jheaders, content=\n". encode_json(
se Data::Dumper;
use HTTP::Request::Common qw( GET PUT POST DELETE );
use JSON;
use Params::Validate qw( :all );
use Test::JSON;
use Test::More;
use Try::Tiny;
use Web::MREST;
=head1 NAME
App::Doc
ad2 status_from_json
L<App::Dochazka::REST> is designed to return status objects in the HTTP
response body. These, of course, are sent in JSON format. This simple routine
takes a JSON string and bles
FIXME: There may be some encoding issues here!
=cut
sub status_from_json {
my ( $json ) = @_;
bless from_json( $json ), 'App::CELL::Status';
}
=head2 req
Assemble and process a HTTP req
012;
use strict;
use warnings;
use App::CELL qw( $CELL $log $meta $site );
use Data::Dumper;
use JSON;
use Params::Validate qw( :all );
use Try::Tiny;
=head1 NAME
App::Dochazka::REST::Model::Sha
ze_date
canonicalize_ts
canonicalize_tsrange
cud
cud_generic
decode_schedule_json
get_history
load
load_multiple
noof
priv_by_eid
schedule_by_eid
ule_json
Given JSON string representation of the schedule, return corresponding HASHREF.
=cut
sub decode_schedule_json {
my ( $json_str ) = @_;
return unless $json_str;
return JSON->ne
od: POST
URI: http://myapp.example.com/
Header: Accept: application/json
Body: {
"command" : "employee.insert",
"
}
Example HTTP response:
Status code: 200 OK
Content-Type: application/json
Body: {
"status" : {
"level" : "ERROR
t step, which Richardson calls "Many URIs, one HTTP method", involves
moving some part of the XML/JSON body into the URI. Though this step might seem
insignificant, calling it "revolutionary" would be
ta::Dumper;
use File::HomeDir;
use HTTP::Request;
use JSON;
use Log::Any::Adapter;
use Params::Validate qw( :all );
use Plack::Test;
use Test::JSON;
use Test::More;
use Try::Tiny;
use Web::Machine;
us
ameters were loaded' );
is_deeply( [ $site->MREST_SUPPORTED_CONTENT_TYPES ], [ [ 'application/json' ] ],
'configuration parameters loaded?' );
# set debug mode
$log->debug_mode( $
=head2 status_from_json
L<Web::MREST> is designed to return status objects in the HTTP response entity.
Before inclusion in the response, the status object is converted to JSON. This
routine goes t
tus;
use Data::Dumper;
use JSON;
use Params::Validate qw( :all );
use Plack::Session;
use Try::Tiny;
use Web::MREST::InitRouter qw( $router );
use Web::MREST::Util qw( $JSON );
# methods/attributes n
$declared_status->payload->{'permanent'} = $pt ? JSON::true : JSON::false;
} else {
$declared_status->payload->{'permanent'} = JSON::true;
}
} else {
#
e undef
permanent => ( $ARGS{'permanent'} )
? JSON::true
: JSON::false,
},
);
}
# add standard properties to the p
;
use App::CELL qw( $log );
use File::Spec;
use JSON;
use Params::Validate qw( :all );
use Pod::Simple::HTML;
use Pod::Simple::Text;
our $JSON = JSON->new->allow_nonref->convert_blessed->utf8->pret
rts:
=over
=item C<$JSON> (singleton)
=item C<pod_to_html> (function)
=item C<pod_to_text> (function)
=back
=cut
use Exporter qw( import );
our @EXPORT_OK = qw(
$JSON
pod_to_html
p
site );
use Data::Dumper;
use Try::Tiny;
use Web::Machine::FSM::States;
use Web::MREST::Util qw( $JSON );
use parent 'Web::MREST::Resource';
=head1 NAME
Web::MREST::Entity - Methods for dealing
ing format:
[
{ 'text/html' => 'method_for_html' },
{ 'application/json' => 'method_for_json' },
{ 'other/mime' => 'method_for_other_mime' },
]
As you can see, this i
{ 'application/json' => 'mrest_generate_response_json' },
];
}
=head2 mrest_generate_response_html
Normally, clients will communicate with the server via
'_render_response_json', but humans ne
pec was first released with perl 5.00405
use HTTP::Request::Common qw( GET PUT POST DELETE );
use JSON;
use Log::Any::Adapter;
use LWP::UserAgent;
use LWP::Protocol::https;
#print "LWP::UserAgent: ".L
GET => \&GET,
PUT => \&PUT,
POST => \&POST,
DELETE => \&DELETE,
);
my %sh;
our $JSON = JSON->new->allow_nonref->convert_blessed->utf8->pretty;
=head1 FUNCTIONS
=head2 init_cli_cli
>cookie_jar };
=head2 send_req
Send a request to the server, get the response, convert it from JSON, and
return it to caller. Die on unexpected errors.
=cut
sub send_req {
no strict 'refs';
obtained using C<curl>:
curl -v http://localhost:5000/ -X GET -H "Content-Type: application/json"
For more information on using the CLI client, see L<Web::MREST::CLI>.
=head1 DESCRIPTION
MR
value), the handler
is expected to return a C<App::CELL::Status> object. This object (rendered in
JSON) becomes the response entity unless overrided by a declared status (see
C<mrest_declare_status> i
hat is returned, but a JSON
representation of its underlying data structure. From this, the object can
easily be reconstituted on the client side by doing
my $status = $JSON->decode( $response_en
D::BzDmp;
use Lingua::PTD::XzDmp;
use Lingua::PTD::SQLite;
use Lingua::PTD::TSV;
use Lingua::PTD::JSON;
use Lingua::PTD::StarDict;
=encoding UTF-8
=head1 NAME
Lingua::PTD - Module to handle PTD fil
QLite->new($filename) if $filename =~ /\.sqlite$/i;
$self = Lingua::PTD::JSON ->new($filename) if $filename =~ /\.json$/i;
# default
$self = Lingua::PTD::Dumper->new($filename) unless $s
e && $filename;
my $done = undef;
# switch
Lingua::PTD::JSON::_save($self => $filename) and $done = 1 if $type =~ /json/i;
Lingua::PTD::Dumper::_save($self => $filename) and $done = 1
tml = shift @tokens;
my $json = join( ' ', @tokens );
if ( $json ) {
$json = '"' . $json . '"' unless $json =~ m/^".*"$/;
if ( $
die send_req( $method, 'docu/pod', $json );
} elsif ( $pod_html =~ m/^htm/i ) {
die send_req( $method, 'docu/html', $json );
} elsif ( $
pod_html =~ m/^tex/i ) {
die send_req( $method, 'docu/text', $json );
}
} else {
print "You should specify a resource\n
asypost::Request::VERSION = '0.23';
use Moo;
use Carp qw(croak);
use HTTP::Tiny;
use JSON::MaybeXS qw(decode_json);
has 'user_agent' => (
is => 'ro',
default => sub { HTTP::Tiny->new( a
: "FATAL: " . $self->endpoint . $operation . " returned '$err'";
}
return decode_json $http_response->{content};
}
sub get {
my ($self, $endpoint) = @_;
$endpoint = $self->_
oint );
return lc $http_response->{headers}->{'content-type'} =~ m|^\Qapplication/json\E|
? decode_json $http_response->{content}
: $http_response->{content};
}
sub _build_url {
ructions for reporting bugs in Web::MREST',
documentation => <<'EOH',
=pod
Returns a JSON structure containing instructions for reporting bugs.
EOH
},
# configinfo
qeuest for one of
these subresources, including the resource name in the request
entity as a bare JSON string (i.e. in double quotes).
EOH
},
# docu/pod
'docu/pod' =>
handler => {
POST => 'handler_echo',
},
cli => 'echo [$JSON]',
description => 'Echo the request body',
documentation => <<'EOH',
=pod
package Finance::IG::REST::Client;
use JSON;
use Digest::MD5 qw(md5 md5_hex md5_base64);
my $datapath;
my $content;
use vars '$AUTOLOAD';
my $fdebug=0; # print debug infor relating to files etc.
ction
=cut
sub POST{
my ($self,$url,$jdata,$headers)=@_;
local $"=', ';
my $jheaders=JSON->new->canonical->encode($headers);
if ($jdata)
{
$jdata=~s/("identifier":)("[^"]+")/$1
mocked response header.
=cut
sub responseHeader
{
my ($self,$header)=@_;
my $c=decode_json($content);
my $headers=$c->{headers};
return $headers->{$header};
}
=head2 CST
Dummy
ed content types (major portions only!)
set( 'MREST_SUPPORTED_CONTENT_TYPES', [
'application/json',
] );
# MREST_CACHE_ENABLED
# set to 0 to include response headers telling clients not to c
rk>)
=item * L<reset> (recycles an existing object by setting it to desired state)
=item * L<TO_JSON> (returns 'unblessed' version of an Activity object)
=item * L<compare> (compare two objects)
=