DAPNET-API
view release on metacpan or search on metacpan
lib/DAPNET/API.pm view on Meta::CPAN
if ($ret) {
print('HTTP Error response: '.$ret."\n");
} else {
print("Message sent\n");
}
=head1 DESCRIPTION
Implementation of the DAPNET REST API in Perl.
=head1 AUTHOR
Simon (G7RZU) <simon@gb7fr.org.uk>
=cut
use vars qw($VERSION);
#Define version
$VERSION = '0.9';
=head1 METHODS
This section describes the methods that are implemented and their use.
=head2 new
Instantiates new object. Pass a hash reference with options as follows
my($dapnetobj) = DAPNET::API->new({
DAPNET_USERNAME => '<username>',
DAPNET_PW => '<password>',
CALLSIGN => '<your callsign>'
DEBUG => [0|1]
});
returns an object if sucessful or false if not sucessful
=cut
sub new {
my($class) = shift;
my($self) = shift;
if (!exists($self->{DAPNET_USERNAME}) || !exists($self->{DAPNET_PW}) || !exists($self->{CALLSIGN})) {
return(0);
}
bless($self,$class);
$self->{_CALL_LEN} = length($self->{CALLSIGN});
return($self);
};
sub _build_request {
my($self) = shift;
my($json) = shift;
my($type) = shift;
my($username) = $self->{DAPNET_USERNAME};
my($pw) = $self->{DAPNET_PW};
my($uri) = 'http://www.hampager.de:8080/'.$type;
print("Building HTTP request\n") if($self->{DEBUG});
my($req) = HTTP::Request->new(
POST => $uri
);
$req->header( 'Content-Type' => 'application/json',
'Authorization'=>'Basic ' . encode_base64($username.':'.$pw)
);
$req->content( $json );
return($req);
};
sub _json_individual_call {
my($self) = shift;
my($text,$to,$txgroup,$emergency) = @_;
my($jsonobj) = JSON->new;
print("Building JSON for individual call\n") if($self->{DEBUG});
my $json = $jsonobj->encode ({
'text' => $text,
'callSignNames' => [$to],
'transmitterGroupNames' => [$txgroup],
'emergency' => $emergency
});
print("JSON:\n\n$json\n") if($self->{DEBUG});
return($json);
};
sub _json_rubric_content {
my($self) = shift;
my($text,$rubric,$number) = @_;
print("Building JSON for rubric\n") if($self->{DEBUG});
my($jsonobj) = JSON->new;
my $json = $jsonobj->encode ({
'text' => $text,
'rubricName'=> $rubric,
'number' => $number
});
print("JSON:\n\n$json\n")if($self->{DEBUG});
return($json);
};
=head2 json_response
Returns a hash ref to the last JSON response or undef if there is none
$jsonhashref = $jsonobj->json_response;
=cut
sub json_response {
my($self) = shift;
print("Return JSON response\n") if($self->{DEBUG});
return($self->{_JSONRESPONSEREF});
};
=head2 send_individual_call
Send a call to a single callsign
$ret = $dapnetobj->send_individual_call(<text>,<destination callsign>,<transmitter group name>,<emergency boolean>));
( run in 0.433 second using v1.01-cache-2.11-cpan-ceb78f64989 )