gcmd (842B)
1 #!/usr/bin/perl 2 use strict; 3 use warnings; 4 5 use LWP::UserAgent; 6 use Getopt::Std; 7 use JSON::PP; 8 9 my $api_key = "API key goes here"; 10 my $agent = "Shlist Pushd/0 "; 11 12 my %args; 13 getopt("j:d:", \%args); 14 15 unless ($args{j} && $args{d}) { 16 print "usage: ./$0 -j <json> -d <device>\n"; 17 exit 1; 18 } 19 20 my %data = ( 21 to => "$args{d}", 22 data => { 23 message => "test test 1 2 3" 24 }, 25 notification => { 26 title => "the shlist is alive", 27 text => "move along" 28 } 29 ); 30 my $json_text = encode_json(\%data); 31 32 my $ua = LWP::UserAgent->new; 33 $ua->agent($agent); 34 35 my $req = HTTP::Request->new(POST => 'https://android.googleapis.com/gcm/send'); 36 $req->authorization("key=$api_key"); 37 $req->content_type('application/json'); 38 $req->content($json_text); 39 40 my $res = $ua->request($req); 41 42 if ($res->is_success) { 43 print $res->content; 44 } 45 else { 46 print $res->status_line, "\n"; 47 }