Catalyst-View-APNS
view release on metacpan or search on metacpan
lib/Catalyst/View/APNS.pm view on Meta::CPAN
package Catalyst::View::APNS;
use strict;
use Net::APNS;
use base qw( Catalyst::View );
use Data::Dumper;
use Carp;
use Catalyst::Exception;
our $VERSION = '0.01';
__PACKAGE__->mk_accessors(qw(apns cv certification private_key passwd));
sub new {
my ( $class, $c, $arguments ) = @_;
my $self = $class->next::method($c);
for my $field ( keys(%$arguments) ) {
next unless $field;
next if $field ne 'apns';
my $subs = $arguments->{$field};
for my $subfield ( keys(%$subs) ) {
lib/Catalyst/View/APNS.pm view on Meta::CPAN
$self->$subfield( $subs->{$subfield} );
}
else {
$c->log->debug( "Invalied parameter " . $subfield );
}
}
}
unless ( $self->certification ) {
croak "Invalied certification";
}
unless ( $self->private_key ) {
croak "Invalied private_key";
}
return $self;
}
sub process {
my ( $self, $c ) = @_;
my $apns = Net::APNS->new;
my $notify = $apns->notify(
{
cert => $self->certification,
key => $self->private_key,
}
);
if ( $self->passwd ) {
$notify->passwd( $self->passwd );
}
$notify->sandbox( $c->stash->{apns}->{sandbox} ) if $c->stash->{apns}->{sandbox};
unless ( $c->stash->{apns}->{device_token} ) {
croak "Invalied device token";
}
$notify->devicetoken( $c->stash->{apns}->{device_token} );
lib/Catalyst/View/APNS.pm view on Meta::CPAN
# lib/MyApp/View/APNS.pm
package MyApp::View::APNS;
use base qw/Catalyst::View::APNS/;
1;
# Configure in lib/MyApp.pm
MyApp->config(
{
apns => {
certification => cert #require to specify
private_key => key #require to specify
}
}
);
sub hello : Local {
my ( $self, $c ) = @_;
$c->stash->{apns} = {
device_token => $device_token,
message => $message,
badge => $badge,
t/lib/TestApp.pm view on Meta::CPAN
use warnings;
use Catalyst;
our $VERSION = '0.01';
use FindBin;
__PACKAGE__->config({
name => 'TestApp',
'View::APNS' => {
apns => {
certification => "/cert.pem",
private_key => "/key.pem",
passwd => "abcdefg",
}
},
});
__PACKAGE__->setup;
sub appname : Global {
my ( $self, $c ) = @_;
$c->stash->{apns} = {
( run in 0.265 second using v1.01-cache-2.11-cpan-4d50c553e7e )