« lib/WebService/Whistle/Pet/Tracker/API.pm
↑ Summary
script/perl-WebService-Whistle-Pet-Tracker-API-mqtt.pl »
| 1 | #!/usr/local/bin/perl | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use File::Basename qw{basename}; | ||
| 5 | use Getopt::Std qw{getopts}; | ||
| 6 | use JSON::XS qw{}; | ||
| 7 | use WebService::Whistle::Pet::Tracker::API qw{}; | ||
| 8 | |||
| 9 | my $basename = basename($0); | ||
| 10 | my $syntax = "$basename -e WHISTLE_EMAIL -p WHISTLE_PASSWORD device [device [...]]\n"; | ||
| 11 | my $opt = {}; | ||
| 12 | |||
| 13 | getopts('e:p:', $opt); | ||
| 14 | |||
| 15 | my $email = $opt->{'e'} || $ENV{'WHISTLE_EMAIL'} or die($syntax); | ||
| 16 | my $password = $opt->{'p'} || $ENV{'WHISTLE_PASSWORD'} or die($syntax); | ||
| 17 | die($syntax) unless @ARGV; | ||
| 18 | |||
| 19 | my $ws = WebService::Whistle::Pet::Tracker::API->new(email=>$email, password=>$password); | ||
| 20 | my $json = JSON::XS->new->pretty; | ||
| 21 | |||
| 22 | foreach my $argv (@ARGV) { | ||
| 23 | my $device = $ws->device($argv); | ||
| 24 | print $json->encode($device); | ||
| 25 | } | ||
| 26 | |||
| 27 | __END__ |