APNS-Agent

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

# =========================================================================
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
# DO NOT EDIT DIRECTLY.
# =========================================================================

use 5.008_001;

use strict;
use warnings;
use utf8;

use Module::Build;
use File::Basename;
use File::Spec;
use CPAN::Meta;
use CPAN::Meta::Prereqs;

my %args = (
    license              => 'perl',
    dynamic_config       => 0,

lib/APNS/Agent.pm  view on Meta::CPAN

package APNS::Agent;
use 5.010;
use strict;
use warnings;

our $VERSION = "0.06";

use AnyEvent::APNS;
use Cache::LRU;
use Encode qw/decode_utf8/;
use JSON::XS;
use Log::Minimal;
use Plack::Request;
use Router::Boom::Method;

use Class::Accessor::Lite::Lazy 0.03 (
    new => 1,
    ro => [qw/
        certificate
        private_key

lib/APNS/Agent.pm  view on Meta::CPAN

    };
}

sub _do_main {
    my ($self, $req) = @_;

    my $token = $req->param('token') or return [400, [], ['Bad Request']];

    my $payload;
    if (my $payload_json = $req->param('payload') ) {
        state $json_driver = JSON::XS->new->utf8;
        local $@;
        $payload = eval { $json_driver->decode($payload_json) };
        return [400, [], ['BAD REQUEST']] if $@;
    }
    elsif (my $alert = $req->param('alert')) {
        $payload = +{
            alert => decode_utf8($alert),
        };
    }
    return [400, [], ['BAD REQUEST']] unless $payload;

    my @payloads = map {[$_, $payload]} split /,/, $token;
    push @{$self->_queue}, @payloads;

    infof "event:payload queued\ttoken:%s", $token;
    if ($self->__apns->connected) {
        $self->_sending;

t/01_basic.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;
use Test::More 0.98;
use Test::TCP;
use Plack::Test;
use HTTP::Request::Common;

use AnyEvent;
use AnyEvent::Socket;

use JSON::XS;
use APNS::Agent;



( run in 1.402 second using v1.01-cache-2.11-cpan-49f99fa48dc )