line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
437
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
package WebService::SendGrid3; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
10378
|
use Moo; |
|
1
|
|
|
|
|
21958
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
with 'WebService::Client'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.10'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Client library for SendGrid API v3 |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
2848
|
use MIME::Base64; |
|
1
|
|
|
|
|
947
|
|
|
1
|
|
|
|
|
576
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has username => ( is => 'ro', required => 1 ); |
15
|
|
|
|
|
|
|
has password => ( is => 'ro', required => 1 ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has '+base_url' => ( default => 'https://api.sendgrid.com/v3' ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
20
|
1
|
|
|
1
|
1
|
2951
|
my ($self) = @_; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
my $u = $self->username(); |
23
|
1
|
|
|
|
|
4
|
my $p = $self->password(); |
24
|
1
|
|
|
|
|
16
|
my $base64_encoded_auth = encode_base64("$u:$p"); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
6
|
$self->ua->default_header(Authorization => "Basic " . $base64_encoded_auth); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
## CATEGORIES |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub get_categories { |
32
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
33
|
0
|
|
0
|
|
|
0
|
return $self->get("/categories/", $args{query} || {}); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
## SETTINGS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_enforced_tls { |
39
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
40
|
0
|
|
0
|
|
|
0
|
return $self->get("/user/settings/enforced_tls", $args{query} || {}); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
## STATS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_stats_global { |
47
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
48
|
0
|
|
0
|
|
|
0
|
return $self->get("/stats", $args{query} || {}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_stats_category { |
52
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
0
|
if (defined($args{query}{categories})) { |
55
|
0
|
|
|
|
|
0
|
$args{query}{categories} = $self->_serialise_for_get( |
56
|
|
|
|
|
|
|
'categories', |
57
|
|
|
|
|
|
|
$args{query}{categories} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
0
|
|
|
0
|
return $self->get("/categories/stats", $args{query} || {}); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get_stats_category_sums { |
65
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
0
|
|
|
0
|
return $self->get("/categories/stats/sums", $args{query} || {}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_stats_subusers { |
71
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
1
|
|
9998
|
use Data::Dumper; |
|
1
|
|
|
|
|
7082
|
|
|
1
|
|
|
|
|
692
|
|
74
|
0
|
|
|
|
|
0
|
print Dumper \%args; |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
if (defined($args{query}{subusers})) { |
77
|
0
|
|
|
|
|
0
|
$args{query}{subusers} = $self->_serialise_for_get( |
78
|
|
|
|
|
|
|
'subusers', |
79
|
|
|
|
|
|
|
$args{query}{subusers} |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
0
|
|
|
0
|
return $self->get("/subusers/stats", $args{query} || {}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub get_stats_subusers_sums { |
87
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
0
|
|
|
0
|
return $self->get("/subusers/stats/sums", $args{query} || {}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get_stats_geo { |
93
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
0
|
|
|
0
|
return $self->get("/geo/stats", $args{query} || {}); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub get_stats_devices { |
99
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
0
|
|
|
0
|
return $self->get("/devices/stats", $args{query} || {}); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub get_stats_clients { |
105
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
0
|
|
|
0
|
return $self->get("/clients/stats", $args{query} || {}); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub get_stats_for_client { |
111
|
0
|
|
|
0
|
1
|
0
|
my ($self, $type, %args) = @_; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
0
|
|
|
0
|
return $self->get("/clients/$type/stats", $args{query} || {}); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub get_stats_esp { |
117
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
0
|
if (defined($args{query}{esps})) { |
120
|
0
|
|
|
|
|
0
|
$args{query}{esps} = $self->_serialise_for_get( |
121
|
|
|
|
|
|
|
'esps', |
122
|
|
|
|
|
|
|
$args{query}{esps} |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
0
|
|
|
0
|
return $self->get("/esp/stats", $args{query} || {}); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub get_stats_browsers { |
130
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
0
|
if (defined($args{query}{browsers})) { |
133
|
0
|
|
|
|
|
0
|
$args{query}{browsers} = $self->_serialise_for_get( |
134
|
|
|
|
|
|
|
'browsers', |
135
|
|
|
|
|
|
|
$args{query}{browsers} |
136
|
|
|
|
|
|
|
); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
0
|
|
|
0
|
return $self->get("/browsers/stats", $args{query} || {}); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub get_stats_parse { |
143
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
0
|
|
|
0
|
return $self->get("/parse/stats", $args{query} || {}); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
## PRIVATE |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub _serialise_for_get { |
151
|
1
|
|
|
1
|
|
3122
|
my ($self, $name, $ra) = @_; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# We need to serialise arrays into query strings due to a limitation |
154
|
|
|
|
|
|
|
# in WebService::Client - HACK |
155
|
1
|
|
|
|
|
3
|
my $first = shift @$ra; |
156
|
1
|
|
|
|
|
3
|
my @rest = map { "&$name=$_" } @$ra; |
|
2
|
|
|
|
|
6
|
|
157
|
1
|
|
|
|
|
7
|
return $first . join('', @rest); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |