APNS-Agent

 view release on metacpan or  search on metacpan

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


    require Getopt::Long;
    require Pod::Usage;
    require Hash::Rename;

    my $p = Getopt::Long::Parser->new(
        config => [qw/posix_default no_ignore_case auto_help pass_through bundling/]
    );
    $p->getoptionsfromarray(\@argv, \my %opt, qw/
        certificate=s
        private-key=s
        disconnect-interval=i
        sandbox!
        debug-port=i
    /) or Pod::Usage::pod2usage();
    Pod::Usage::pod2usage() if !$opt{certificate} || !$opt{'private-key'};

    Hash::Rename::hash_rename(\%opt, code => sub {tr/-/_/});
    (\%opt, \@argv);
}

sub run {
    my $self = shift;
    my %args = @_ == 1 ? %{$_[0]} : @_;
    if (!$args{listen} && !$args{port} && !$ENV{SERVER_STARTER_PORT}) {
        $args{port} = 4905;
    }
    require Plack::Loader;
    Plack::Loader->load(Twiggy => %args)->run($self->to_app);
}

1;
__END__

=encoding utf-8

=head1 NAME

APNS::Agent - agent server for APNS

=head1 SYNOPSIS

    use APNS::Agent;
    my $agent = APNS::Agent->new(
        certificate => '/path/to/certificate',
        private_key => '/path/to/private_key',
    );
    $agent->run;

=head1 DESCRIPTION

APNS::Agent is agent server for APNS. It is also backend class of L<apns-agent>.

This module provides consistent connection to APNS and cares reconnection. It utilizes
L<AnyEvent::APNS> internally.

B<THE SOFTWARE IS ALPHA QUALITY. API MAY CHANGE WITHOUT NOTICE.>

=head1 API PARAMETERS

APNS::Agent launches HTTP Server process which accepts only POST method and
C<application/x-www-form-urlencoded> format parameters.

Acceptable parameters as follows:

=over

=item C<token>

device token by HEX format. (Required)

=item C<payload>

JSON string for push notification. If you only want to send message, alternatively can use
C<alert> parameter.

One of C<payload> and C<alert> must be supplied. Both of C<payload> and C<alert> are specified,
the C<payload> parameter has priority.

=item C<alert>

push notification message.

=back

=head1 SEE ALSO

L<AnyEvent::APNS>

=head1 THANKS

Thank B<@shin1rosei> that many code of this module is taken from
L<https://github.com/shin1rosei/AnyEvent-APNS-Server>.

=head1 LICENSE

Copyright (C) Songmu.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHOR

Songmu E<lt>y.songmu@gmail.comE<gt>

=cut



( run in 0.641 second using v1.01-cache-2.11-cpan-6aa56a78535 )