############################################### #$Id: 70_PushNotifier.pm 2014-11-14 10:00:00 xusader # # download client-app http://pushnotifier.de/apps/ # create account http://pushnotifier.de/login/ # get apiToken from http://gidix.de/setings/api/ and add a new app # # Define example: # define yourname PushNotifier apiToken appname user password deviceID # # notify example: # define LampON notify Lamp:on set yourDefineName message Your message! # package main; use LWP::UserAgent; sub PushNotifier_Initialize($) { my ($hash) = @_; $hash->{DefFn} = "PushNotifier_Define"; $hash->{SetFn} = "PushNotifier_Set"; } ##################################### sub PushNotifier_Define($$) { my ($hash, $def) = @_; my @args = split("[ \t]+", $def); my ($name, $type, $apiToken, $app, $user, $passwd, $deviceID) = @args; $hash->{STATE} = 'Initialized'; if(defined($apiToken) && defined($app)&& defined($user)&& defined($passwd)&& defined($deviceID)) { $hash->{apiToken} = $apiToken; $hash->{app} = $app; $hash->{user} = $user; $hash->{passwd} = $passwd; $hash->{deviceID} = $deviceID; my %getAppToken = ( 'apiToken' => $apiToken, 'username' => $user, 'password' => $passwd); my $responseAT = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/login", \%getAppToken); my $strg_chkAT = $responseAT->as_string; $strg_chkAT =~ m{"appToken":"([\w]+)}; my $appToken = $1; $hash->{appToken} = $appToken; #my $name = $hash->{NAME}; #Log3 $name, 2, $appToken; my %getDevices = ( 'apiToken' => $apiToken, 'appToken' => $appToken); my $responseID = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/getDevices", \%getDevices); my $strg_chkID = $responseID->as_string; $strg_chkID =~ m/":([\d].*)/; my $devices = $1; $hash->{devices} = $devices; return undef; } } ##################################### sub PushNotifier_Set($@) { my ($hash, $name, $cmd, @a) = @_; my %sets = ('message' => 1); if(!defined($sets{$cmd})) { return "Unknown argument $cmd, choose one of " . join(" ", sort keys %sets); } return PushNotifier_Send_Message($hash, @a); } ##################################### sub PushNotifier_Send_Message { my $hash = shift; my $msg = join(" ", @_); my $apiToken = $hash->{apiToken}; my $app = $hash->{app}; my $user = $hash->{user}; my $passwd = $hash->{passwd}; my $appToken = $hash->{appToken}; my $deviceID = $hash->{deviceID}; my %settings = ( 'apiToken' => $apiToken, 'appToken' => $appToken, 'app' => $app, 'deviceID' => $deviceID, 'type' => 'MESSAGE', 'content' => "$msg" ); my $response = LWP::UserAgent->new()->post("http://a.pushnotifier.de/1/sendToDevice", \%settings); my $error_chk = $response->as_string; if($error_chk =~ m/"status":"ok"/) { return "OK"; } else { return $error_chk; } } 1; ############################################################################### =pod =begin html

PushNotifier

=end html =begin html_DE

PushNotifier

=end html_DE =cut