NAME

WWW::Google::Cloud::Messaging - Google Cloud Messaging (GCM) Client Library

SYNOPSIS

use WWW::Google::Cloud::Messaging;

my $api_key = 'Your API Key';
my $gcm = WWW::Google::Cloud::Messaging->new(api_key => $api_key);

my $res = $gcm->send({
    registration_ids => [ $reg_id, ... ],
    collapse_key     => $collapse_key,
    data             => {
      message => 'blah blah blah',
    },
});

die $res->error unless $res->is_success;

my $results = $res->results;
while (my $result = $results->next) {
    my $reg_id = $result->target_reg_id;
    if ($result->is_success) {
        say sprintf 'message_id: %s, reg_id: %s',
            $result->message_id, $reg_id;
    }
    else {
        warn sprintf 'error: %s, reg_id: %s',
            $result->error, $reg_id;
    }

    if ($result->has_canonical_id) {
        say sprintf 'reg_id %s is old! refreshed reg_id is %s',
            $reg_id, $result->registration_id;'
    }
}

DESCRIPTION

WWW::Google::Cloud::Messaging is Google Cloud Messaging (GCM) Client Library.

Currently support JSON API only.

SEE ALSO http://developer.android.com/guide/google/gcm/gcm.html#send-msg.

METHODS

new(%args)

Create a WWW::Google::Cloud::Messaging instance.

my $gcm = WWW::Google::Cloud::Messaging->new(api_key => $api_key);

Supported options are:

api_key : Str

Required. Sets your API key.

For information obtaining API key, please check http://developer.android.com/guide/google/gcm/gs.html#access-key.

api_url : Str

Optional. Default values is $WWW::Google::Cloud::Messaging::API_URL.

ua : LWP::UserAgent

Optional. Sets custom LWP::UserAgent instance.

send(\%payload)

Send message to GCM. Returned WWW::Google::Cloud::Messaging::Response instance.

my $res = $gcm->send({
    registration_ids => [ $reg_id ], # must be arrayref
    collapse_key     => '...',
    data             => {
        message   => 'xxxx',
        score     => 12345,
        is_update => JSON::true,
    },
});

For more information, SEE ALSO http://developer.android.com/guide/google/gcm/gcm.html#send-msg.

AUTHOR

xaicron <xaicron@cpan.org>

COPYRIGHT

Copyright 2012 - xaicron

LICENSE

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

SEE ALSO

WWW::Google::Cloud::Messaging::Response