| 1 | package Net::Azure::NotificationHubs; | ||||||||||||||||||||
| 2 | 5 | ▶ | use 5.008001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 5 | ▶ | use Net::Azure::Authorization::SAS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 5 | ▶ | use Net::Azure::NotificationHubs::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 5 | ▶ | use JSON; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 5 | ▶ | use HTTP::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 5 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 5 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 5 | ▶ | use String::CamelCase qw/camelize wordsplit/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | use Class::Accessor::Lite ( | ||||||||||||||||||||
| 13 | 5 | new => 0, | |||||||||||||||||||
| 14 | ro => [qw[ | ||||||||||||||||||||
| 15 | agent | ||||||||||||||||||||
| 16 | serializer | ||||||||||||||||||||
| 17 | api_version | ||||||||||||||||||||
| 18 | authorizer | ||||||||||||||||||||
| 19 | apns_expiry | ||||||||||||||||||||
| 20 | hub_name | ||||||||||||||||||||
| 21 | ]], | ||||||||||||||||||||
| 22 | 5 | ▶ | ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 5 | our $VERSION = "0.07"; | |||||||||||||||||||
| 25 | 5 | our $DEFAULT_API_VERSION = "2015-04"; | |||||||||||||||||||
| 26 | 5 | our $DEFAULT_TIMEOUT = 60; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub new { | ||||||||||||||||||||
| 29 | 9 | ▶ | my ($class, %param) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 9 | $param{agent} = HTTP::Tiny->new(agent => sprintf('%s/%s', $class, $VERSION)); | |||||||||||||||||||
| 32 | 9 | $param{serializer} = JSON->new->utf8(1); | |||||||||||||||||||
| 33 | 9 | ▶ | $param{api_version} ||= $DEFAULT_API_VERSION; | ||||||||||||||||||
|
Condition100%3/3
$param{"api_version"} ||= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
MC/DC100%2/2
$param{"api_version"} ||= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
$param{"api_version"}
$Net::Azure::NotificationHubs::DEFAULT_API_VERSION
Truth table100%3/3
A ||= B
A= $param{"api_version"}B= $Net::Azure::NotificationHubs::DEFAULT_API_VERSION
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 9 | ▶ | if (!defined $param{authorizer}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 8 | $param{authorizer} = eval { | |||||||||||||||||||
| 37 | 8 | Net::Azure::Authorization::SAS->new(connection_string => $param{connection_string}); | |||||||||||||||||||
| 38 | }; | ||||||||||||||||||||
| 39 | 8 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 1 | croak $@; | |||||||||||||||||||
| 41 | }; | ||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 8 | bless {%param}, $class; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub _uri { | ||||||||||||||||||||
| 48 | 8 | ▶ | my ($self, $path, %params) = @_; | ||||||||||||||||||
|
Subroutine
_uri: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 49 | 8 | ▶ | $path ||= '/'; | ||||||||||||||||||
|
Condition100%2/2
$path ||= "/"
MC/DC100%1/1
$path ||= "/"
$path
Truth table100%2/2
A
A= $path
| |||||||||||||||||||||
| 50 | 8 | my $uri = URI->new($self->authorizer->endpoint); | |||||||||||||||||||
| 51 | 8 | $uri->scheme('https'); | |||||||||||||||||||
| 52 | 8 | $uri->path($path); | |||||||||||||||||||
| 53 | 8 | $uri->query_form(%params); | |||||||||||||||||||
| 54 | 8 | $uri; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | sub _req { | ||||||||||||||||||||
| 58 | 8 | ▶ | my ($self, $path, $payload, %params) = @_; | ||||||||||||||||||
|
Subroutine
_req: called CC=5 SCAR=16.1
| |||||||||||||||||||||
| 59 | 8 | ▶ | croak 'path is reuired' if !defined $path; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 7 | ▶ | croak 'payload is required' if !defined $payload; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 6 | ▶ | croak 'payload is not hashref' if ref($payload) ne 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 5 | ▶ | $params{api_version} ||= $self->api_version; | ||||||||||||||||||
|
Condition100%3/3
$params{"api_version"} ||= $self->api_version
MC/DC100%2/2
$params{"api_version"} ||= $self->api_version
$params{"api_version"}
$self->api_version
Truth table100%3/3
A ||= B
A= $params{"api_version"}B= $self->api_version
| |||||||||||||||||||||
| 63 | 5 | my $uri = $self->_uri($path, %params); | |||||||||||||||||||
| 64 | 5 | my $auth = $self->authorizer->token($uri->as_string); | |||||||||||||||||||
| 65 | 5 | my $data = $self->serializer->encode($payload); | |||||||||||||||||||
| 66 | 5 | my $req = Net::Azure::NotificationHubs::Request->new( | |||||||||||||||||||
| 67 | POST => $uri->as_string, | ||||||||||||||||||||
| 68 | { | ||||||||||||||||||||
| 69 | 'Authorization' => $auth, | ||||||||||||||||||||
| 70 | 'Content-Type' => 'application/atom+xml;charset=utf-8', | ||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||
| 72 | $data, | ||||||||||||||||||||
| 73 | ); | ||||||||||||||||||||
| 74 | 5 | $req->agent($self->agent); | |||||||||||||||||||
| 75 | 5 | $req; | |||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | sub send { | ||||||||||||||||||||
| 79 | 2 | ▶ | my ($self, $payload, %param) = @_; | ||||||||||||||||||
|
Subroutine
send: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 80 | 2 | my $path = sprintf "/%s/messages/", $self->hub_name; | |||||||||||||||||||
| 81 | 2 | my $req = $self->_req($path, $payload); | |||||||||||||||||||
| 82 | 2 | for my $key (keys %param) { | |||||||||||||||||||
| 83 | 3 | ▶ | next if !defined $param{$key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 3 | my $header_name = join('-', 'ServiceBusNotification', wordsplit(camelize($key))); | |||||||||||||||||||
| 85 | 3 | $req->header($header_name => $param{$key}); | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | 2 | ▶ | if ($param{format} eq 'apple') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 88 | 1 | $req->header('ServiceBusNotification-Apns-Expiry' => $self->apns_expiry); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | 2 | $req; | |||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 5 | 1; | |||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||