ons for PONAPI::Server
package PONAPI::Exception;
use Moose;
use Moose::Util qw/find_meta/;
use JSON::MaybeXS;
sub throw {
my $class_or_obj = shift;
die ( blessed $class_or_obj ? $class_or_obj
is => 'ro',
isa => 'Bool',
);
has json_api_version => (
is => 'ro',
isa => 'Str',
default => sub { '1.0' },
writer => '_set_json_api_version'
);
# Picked from Throwabl
has occured, please check server logs";
}
return $status, [], +{
jsonapi => { version => $self->json_api_version },
errors => [ { detail => $detail, status => $status } ],
il');
return $c->app->core->get_user({email => $email});
}
sub _unauthorized {
shift->render(json => E('Need to log in first.'), status => 401);
}
1;
=encoding utf8
=head1 NAME
Convos::Plugin
->file('server.yml')->slurp );
}
sub read_config {
my $self = shift;
$self->_set_server_json_api_version;
$self->_set_server_sorting;
$self->_set_server_send_header;
$self->_set
f->_set_server_respond_to_updates_status;
$self->{'ponapi.mediatype'} = 'application/vnd.api+json';
return %{$self};
}
sub _set_server_respond_to_updates_status {
my $self = shift;
gured";
}
sub _set_server_json_api_version {
my $self = shift;
my $spec_version = $self->config->{server}{spec_version}
// die "[PONAPI Server] server JSON API version configuration
# ABSTRACT: PONAPI - Perl implementation of {JSON:API} (http://jsonapi.org/) v1.0
package PONAPI::Server;
use strict;
use warnings;
our $VERSION = '0.003003';
use Plack::Request;
use Plack::Respons
e;
use HTTP::Headers::ActionPack;
use Module::Runtime ();
use JSON::MaybeXS;
use URI::Escape qw( uri_unescape );
use PONAPI::Server::ConfigReader;
use PONAPI::Names qw( check_name );
use parent 'Pla
_TYPE => +{ __error__ => +[ 415, "{JSON:API} No {json:api} Media-Type (Content-Type / Accept)" ] },
ERR_MISSING_CONTENT_TYPE => +{ __error__ => +[ 415, "{JSON:API} Missing Content-Type header" ]
ection);
return $connection;
};
sub get {
my ($self, $args, $cb) = @_;
my $res = $self->TO_JSON;
Mojo::IOLoop->delay(
sub {
my ($delay) = @_;
return $delay->pass unless $args
$_[0]->{password} = $_[0]->_bcrypt($_[1]);
$_[0];
}
sub uri { Mojo::Path->new(sprintf '%s/user.json', $_[0]->email) }
sub validate_password {
my ($self, $plain) = @_;
return 0 unless $self->p
sub TO_JSON {
my ($self, $persist) = @_;
$self->{registered} ||= Mojo::Date->new->to_datetime;
my $json = {map { ($_, $self->{$_} // '') } qw(email password registered)};
delete $json->{passw
(undef)
=item * L<JPL::Class> (undef)
=item * L<JPL::Compile> (undef)
=item * L<JSON::PP> (2.27200)
=item * L<JSON::PP::Boolean> (undef)
=item * L<List::Util> (1.25)
=item * L<List::Util::PP> (1
rized;
my $json = $self->req->json;
my $url = $self->_validate_url($json->{url})
or return $self->render(openapi => E('Missing "host" in URL'), status => 400);
my $name = $json->{name} || $
onnection = $user->connection({
name => $name,
on_connect_commands => $json->{on_connect_commands} || [],
protocol => $url->scheme,
});
$connection-
my $user = $self->backend->user or return $self->unauthorized;
my $json = $self->req->json;
my $state = $json->{wanted_state} || '';
my $connection;
eval {
$connection = $user->g
(undef)
=item * L<JPL::Class> (undef)
=item * L<JPL::Compile> (undef)
=item * L<JSON::PP> (2.27200)
=item * L<JSON::PP::Boolean> (undef)
=item * L<List::Util> (1.27)
=item * L<List::Util::PP> (u
shift->openapi->valid_input or return;
$self->delay(
sub { $self->auth->login($self->req->json, shift->begin) },
sub {
my ($delay, $err, $user) = @_;
return $self->render(opena
ift->openapi->valid_input or return;
$self->delay(
sub { $self->auth->register($self->req->json, shift->begin) },
sub {
my ($delay, $err, $user) = @_;
return $self->render(opena
id_input or return;
my $json = $self->req->json;
my $user = $self->backend->user or return $self->unauthorized;
# TODO: Add support for changing email
unless (%$json) {
return $self->ren
(undef)
=item * L<JPL::Class> (undef)
=item * L<JPL::Compile> (undef)
=item * L<JSON::PP> (undef)
=item * L<JSON::PP::Boolean> (undef)
=item * L<List::Util> (1.22)
=item * L<List::Util::PP> (1.
odel::Envoy::Storage::Redis;
our $VERSION = '0.1.3';
use Moose;
use MooseX::ClassAttribute;
use JSON::XS;
extends 'Model::Envoy::Storage';
=head1 Model::Envoy::Storage::Redis
A storage plugin for
$model_class->build( decode_json( $result ) );
}
return undef;
}
sub save {
my ( $self ) = @_;
$self->redis->set( 'id:' . $self->model->id => encode_json( $self->model->dump ) );
:Events;
use Mojo::Base 'Mojolicious::Controller';
use Convos::Util qw(DEBUG E);
use Mojo::JSON 'encode_json';
use Mojo::Util;
use constant INACTIVE_TIMEOUT => $ENV{CONVOS_INACTIVE_TIMEOUT} || 30;
me)->to_datetime;
warn "[Convos::Controller::Events] >>> @{[encode_json $data]}\n" if DEBUG == 2;
$self->send({json => {%$data, ts => $ts, event => $event}});
}
);
$self->inactivi
sh\n" if DEBUG == 2;
$backend->unsubscribe("user:$uid" => $cb);
}
);
$self->on(
json => sub {
my ($self, $data) = @_;
my $method = sprintf '_event_%s', $data->{method} ||
sage => $message // ''});
return $self;
}
sub uri { Mojo::Path->new(sprintf '%s/%s/connection.json', $_[0]->user->email, $_[0]->id) }
sub wanted_state {
my ($self, $state, $cb) = @_;
return $
}
sub TO_JSON {
my ($self, $persist) = @_;
my $url = $self->url;
my %json = map { ($_, $self->$_) } qw(name protocol wanted_state);
$json{connection_id} = $self->id;
$json{on_connec
n_connect_commands;
$json{url} = $url->to_unsafe_string;
if (!$persist and $url->query->param('forced')) {
my $password = $url->password // '';
$json{url} =~ s!:$password\
ON
version 0.003003
=head1 DESCRIPTION
The origin of the name PONAPI (pronounced: Po-Na-Pi) is JSONAPI.
We jokingly decided to replace the JavaScript reference (JS) with a Perl one (P).
This docum
y PSGI-compatible utility
to run the application:
plackup -p 5000 myapp.psgi
Any L<{json:api}|http://jsonapi.org/> compliant client can then access your application:
$ perl -MPONAPI::Client
ion/vnd.api+json" 'http://0:5000/people/88
That'll give you the default options, with the default repository; for a real
world scenario, you'll have to get your hands dirty.
Because {json:api} exten
Mojo::Path->new(sprintf '%s.json', Mojo::Util::decamelize($1));
};
sub add_backend_helpers {
my ($self, $app) = @_;
my $prefix = $self->uri->[0];
$prefix =~ s!\.json$!!;
$app->log->debug("Ad
',
isa => 'Str',
required => 1,
);
has json => (
is => 'ro',
isa => JSON::MaybeXS::JSON(),
default => sub { JSON::MaybeXS->new->allow_nonref->utf8->canonical },
);
sitory;
$ponapi_parameters->{version} = $self->version;
$ponapi_parameters->{json} = $self->json;
local $@;
my @ret;
eval {
@ret = $action_class->new($ponapi_para
=> [
{ ... }, ...
],
);
=head1 DESCRIPTION
Data Access Object for the JSON API. This sits in between a server
and a L<repository|"PONAPI::Repository">.
All public DAO met
s::Controller::Dialog;
use Mojo::Base 'Mojolicious::Controller';
use Convos::Util 'E';
use Mojo::JSON qw(false true);
sub last_read {
my $self = shift->openapi->valid_input or return;
my $d
package Convos::Plugin::Auth;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::JSON qw(false true);
use Mojo::Util;
sub register {
my ($self, $app, $config) = @_;
$self->{invite_code} = $config-
er" ],
[ "p|port=i", "Specify a port for the server (default=5000)" ],
[ "j|json", "JSON-only output" ],
);
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
$sel
opt->{q};
}
$self->{only_json} = !!( $opt->{json} || $opt->{j} );
$self->usage_error("JSON-only works just in Query mode")
if $self->{only_json} and !exists $opt->{q};
}
sub exe
CLI::RunQuery;
PONAPI::CLI::RunQuery::run( $self->{port}, $self->{query_string}, $self->{only_json} );
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
PONAPI::CLI::Command::demo - ponapi demo
package Convos::Util;
use Mojo::Base 'Exporter';
use JSON::Validator::Error;
use Mojo::File;
use Mojo::Util 'monkey_patch';
use constant DEBUG => $ENV{CONVOS_DEBUG} || 0;
our @EXPORT_OK = qw(DEBUG E
E {
my ($msg, $path) = @_;
$msg =~ s! at \S+.*!!s;
$msg =~ s!:.*!.!s;
return {errors => [JSON::Validator::Error->new($path, $msg)]};
}
sub has_many {
my $class = caller;
my ($accessor, $