line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Azure::NotificationHubs; |
2
|
5
|
|
|
5
|
|
203069
|
use 5.008001; |
|
5
|
|
|
|
|
41
|
|
3
|
5
|
|
|
5
|
|
17
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
66
|
|
4
|
5
|
|
|
5
|
|
18
|
use warnings; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
113
|
|
5
|
5
|
|
|
5
|
|
1683
|
use Net::Azure::Authorization::SAS; |
|
5
|
|
|
|
|
55071
|
|
|
5
|
|
|
|
|
118
|
|
6
|
5
|
|
|
5
|
|
1612
|
use Net::Azure::NotificationHubs::Request; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
149
|
|
7
|
5
|
|
|
5
|
|
22
|
use JSON; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
15
|
|
8
|
5
|
|
|
5
|
|
2756
|
use HTTP::Tiny; |
|
5
|
|
|
|
|
174133
|
|
|
5
|
|
|
|
|
147
|
|
9
|
5
|
|
|
5
|
|
29
|
use URI; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
72
|
|
10
|
5
|
|
|
5
|
|
20
|
use Carp; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
196
|
|
11
|
5
|
|
|
5
|
|
22
|
use String::CamelCase qw/camelize wordsplit/; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
201
|
|
12
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
13
|
5
|
|
|
|
|
45
|
new => 0, |
14
|
|
|
|
|
|
|
ro => [qw[ |
15
|
|
|
|
|
|
|
agent |
16
|
|
|
|
|
|
|
serializer |
17
|
|
|
|
|
|
|
api_version |
18
|
|
|
|
|
|
|
authorizer |
19
|
|
|
|
|
|
|
apns_expiry |
20
|
|
|
|
|
|
|
hub_name |
21
|
|
|
|
|
|
|
]], |
22
|
5
|
|
|
5
|
|
69
|
); |
|
5
|
|
|
|
|
7
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our $VERSION = "0.06"; |
25
|
|
|
|
|
|
|
our $DEFAULT_API_VERSION = "2015-04"; |
26
|
|
|
|
|
|
|
our $DEFAULT_TIMEOUT = 60; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
9
|
|
|
9
|
1
|
14209
|
my ($class, %param) = @_; |
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
79
|
$param{agent} = HTTP::Tiny->new(agent => sprintf('%s/%s', $class, $VERSION)); |
32
|
9
|
|
|
|
|
626
|
$param{serializer} = JSON->new->utf8(1); |
33
|
9
|
|
100
|
|
|
53
|
$param{api_version} ||= $DEFAULT_API_VERSION; |
34
|
|
|
|
|
|
|
|
35
|
9
|
100
|
|
|
|
21
|
if (!defined $param{authorizer}) { |
36
|
8
|
|
|
|
|
12
|
$param{authorizer} = eval { |
37
|
8
|
|
|
|
|
60
|
Net::Azure::Authorization::SAS->new(connection_string => $param{connection_string}); |
38
|
|
|
|
|
|
|
}; |
39
|
8
|
100
|
|
|
|
1406
|
if ($@) { |
40
|
1
|
|
|
|
|
5
|
croak $@; |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
53
|
bless {%param}, $class; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _uri { |
48
|
8
|
|
|
8
|
|
8709
|
my ($self, $path, %params) = @_; |
49
|
8
|
|
100
|
|
|
25
|
$path ||= '/'; |
50
|
8
|
|
|
|
|
27
|
my $uri = URI->new($self->authorizer->endpoint); |
51
|
8
|
|
|
|
|
14339
|
$uri->scheme('https'); |
52
|
8
|
|
|
|
|
8730
|
$uri->path($path); |
53
|
8
|
|
|
|
|
239
|
$uri->query_form(%params); |
54
|
8
|
|
|
|
|
412
|
$uri; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _req { |
58
|
8
|
|
|
8
|
|
10260
|
my ($self, $path, $payload, %params) = @_; |
59
|
8
|
100
|
|
|
|
36
|
croak 'path is reuired' if !defined $path; |
60
|
7
|
100
|
|
|
|
18
|
croak 'payload is required' if !defined $payload; |
61
|
6
|
100
|
|
|
|
22
|
croak 'payload is not hashref' if ref($payload) ne 'HASH'; |
62
|
5
|
|
100
|
|
|
41
|
$params{api_version} ||= $self->api_version; |
63
|
5
|
|
|
|
|
39
|
my $uri = $self->_uri($path, %params); |
64
|
5
|
|
|
|
|
14
|
my $auth = $self->authorizer->token($uri->as_string); |
65
|
5
|
|
|
|
|
1051
|
my $data = $self->serializer->encode($payload); |
66
|
5
|
|
|
|
|
82
|
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
|
|
|
|
|
257
|
$req->agent($self->agent); |
75
|
5
|
|
|
|
|
58
|
$req; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub send { |
79
|
2
|
|
|
2
|
1
|
5043
|
my ($self, $payload, %param) = @_; |
80
|
2
|
|
|
|
|
8
|
my $path = sprintf "/%s/messages/", $self->hub_name; |
81
|
2
|
|
|
|
|
19
|
my $req = $self->_req($path, $payload); |
82
|
2
|
|
|
|
|
6
|
for my $key (keys %param) { |
83
|
3
|
50
|
|
|
|
7
|
next if !defined $param{$key}; |
84
|
3
|
|
|
|
|
9
|
my $header_name = join('-', 'ServiceBusNotification', wordsplit(camelize($key))); |
85
|
3
|
|
|
|
|
61
|
$req->header($header_name => $param{$key}); |
86
|
|
|
|
|
|
|
} |
87
|
2
|
100
|
|
|
|
6
|
if ($param{format} eq 'apple') { |
88
|
1
|
|
|
|
|
5
|
$req->header('ServiceBusNotification-Apns-Expiry' => $self->apns_expiry); |
89
|
|
|
|
|
|
|
} |
90
|
2
|
|
|
|
|
5
|
$req; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |