line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
6
|
|
|
6
|
|
319960
|
use strict; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
156
|
|
2
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
292
|
|
3
|
|
|
|
|
|
|
package WebService::SendGrid::Newsletter; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: Perl interface to SendGrid Newsletter API |
6
|
|
|
|
|
|
|
our $VERSION = '0.02'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
4600
|
use HTTP::Request::Common; |
|
6
|
|
|
|
|
171353
|
|
|
6
|
|
|
|
|
470
|
|
9
|
6
|
|
|
6
|
|
6329
|
use JSON; |
|
6
|
|
|
|
|
76666
|
|
|
6
|
|
|
|
|
28
|
|
10
|
6
|
|
|
6
|
|
7326
|
use HTTP::Tiny; |
|
6
|
|
|
|
|
317383
|
|
|
6
|
|
|
|
|
240
|
|
11
|
|
|
|
|
|
|
|
12
|
6
|
|
|
6
|
|
3872
|
use WebService::SendGrid::Newsletter::Lists; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
165
|
|
13
|
6
|
|
|
6
|
|
3295
|
use WebService::SendGrid::Newsletter::Recipients; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
149
|
|
14
|
6
|
|
|
6
|
|
3265
|
use WebService::SendGrid::Newsletter::Schedule; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
153
|
|
15
|
6
|
|
|
6
|
|
3417
|
use WebService::SendGrid::Newsletter::Identity; |
|
6
|
|
|
|
|
88
|
|
|
6
|
|
|
|
|
154
|
|
16
|
6
|
|
|
6
|
|
3410
|
use WebService::SendGrid::Newsletter::Categories; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
159
|
|
17
|
6
|
|
|
6
|
|
33
|
use parent 'WebService::SendGrid::Newsletter::Base'; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
24
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
7
|
|
|
7
|
1
|
9058
|
my ($class, %args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
17
|
my $self = {}; |
24
|
7
|
|
|
|
|
16
|
bless($self, $class); |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
77
|
$self->_check_required_args([ qw( api_user api_key ) ], %args); |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
|
|
39
|
$self->{api_user} = $args{api_user}; |
29
|
6
|
|
|
|
|
16
|
$self->{api_key} = $args{api_key}; |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
|
|
53
|
$self->{ua} = HTTP::Tiny->new; |
32
|
6
|
|
50
|
|
|
670
|
$self->{ua}->agent(__PACKAGE__ . '/' . |
33
|
|
|
|
|
|
|
($__PACKAGE__::VERSION || 0) . ' (Perl)'); |
34
|
|
|
|
|
|
|
|
35
|
6
|
|
|
|
|
51
|
$self->{json_options} = $args{json_options}; |
36
|
|
|
|
|
|
|
|
37
|
6
|
|
|
|
|
16
|
$self->{last_response} = undef; |
38
|
6
|
|
|
|
|
15
|
$self->{last_response_code} = undef; |
39
|
|
|
|
|
|
|
|
40
|
6
|
50
|
|
|
|
32
|
if (exists $args{identity}) { |
41
|
0
|
|
|
|
|
0
|
$self->{identity} = $args{identity}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
|
|
24
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Sends a request to SendGrid Newsletter API |
48
|
|
|
|
|
|
|
sub _send_request { |
49
|
34
|
|
|
34
|
|
123
|
my ($self, $path, %args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
34
|
|
|
|
|
151
|
my $params = { api_user => $self->{api_user}, api_key => $self->{api_key}, %args }; |
52
|
|
|
|
|
|
|
|
53
|
34
|
|
|
|
|
89
|
my $url = 'https://api.sendgrid.com/api/newsletter/' . $path . '.json'; |
54
|
|
|
|
|
|
|
|
55
|
34
|
|
|
|
|
130
|
my $response = $self->{ua}->post_form($url, $params); |
56
|
|
|
|
|
|
|
|
57
|
34
|
|
|
|
|
204497
|
$self->{last_response_code} = $response->{status}; |
58
|
34
|
|
|
|
|
307
|
$self->{last_response} = decode_json $response->{content}; |
59
|
|
|
|
|
|
|
|
60
|
32
|
|
|
|
|
300
|
return $response->{success}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub get { |
65
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
$self->_check_required_args([ qw( name ) ], %args); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
if ($self->_send_request('get', %args)) { |
70
|
0
|
|
|
|
|
0
|
return $self->{last_response}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
0
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add { |
79
|
3
|
|
|
3
|
1
|
33
|
my ($self, %args) = @_; |
80
|
|
|
|
|
|
|
|
81
|
3
|
50
|
|
|
|
15
|
if (!exists $args{identity}) { |
82
|
0
|
|
|
|
|
0
|
$args{identity} = $self->{identity}; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
24
|
$self->_check_required_args([ qw( identity name subject text html ) ], |
86
|
|
|
|
|
|
|
%args); |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
|
|
24
|
return $self->_send_request('add', %args); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub edit { |
93
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
$self->_check_required_args([ qw( name newname identity subject text |
96
|
|
|
|
|
|
|
html ) ], %args); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
return $self->_send_request('edit', %args); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub list { |
103
|
0
|
|
|
0
|
1
|
0
|
my ($self, %args) = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
0
|
if ($self->_send_request('list', %args)) { |
106
|
0
|
|
|
|
|
0
|
return $self->{last_response}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
else { |
109
|
0
|
|
|
|
|
0
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub delete { |
115
|
1
|
|
|
1
|
1
|
1555
|
my ($self, %args) = @_; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
6
|
$self->_check_required_args([ qw( name ) ], %args); |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
|
|
5
|
return $self->_send_request('delete', %args); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub lists { |
124
|
15
|
|
|
15
|
1
|
9787
|
my ($self) = @_; |
125
|
|
|
|
|
|
|
|
126
|
15
|
100
|
|
|
|
49
|
if (!defined $self->{lists}) { |
127
|
3
|
|
|
|
|
26
|
$self->{lists} = WebService::SendGrid::Newsletter::Lists->new( |
128
|
|
|
|
|
|
|
sgn => $self |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
15
|
|
|
|
|
86
|
return $self->{lists}; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub recipients { |
137
|
7
|
|
|
7
|
1
|
5047
|
my ($self) = @_; |
138
|
|
|
|
|
|
|
|
139
|
7
|
100
|
|
|
|
24
|
if (!defined $self->{recipients}) { |
140
|
|
|
|
|
|
|
$self->{recipients} = |
141
|
2
|
|
|
|
|
21
|
WebService::SendGrid::Newsletter::Recipients->new(sgn => $self); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
7
|
|
|
|
|
65
|
return $self->{recipients}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub schedule { |
149
|
7
|
|
|
7
|
1
|
6806
|
my ($self) = @_; |
150
|
|
|
|
|
|
|
|
151
|
7
|
100
|
|
|
|
23
|
if (!defined $self->{schedule}) { |
152
|
|
|
|
|
|
|
$self->{schedule} = |
153
|
1
|
|
|
|
|
10
|
WebService::SendGrid::Newsletter::Schedule->new(sgn => $self); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
7
|
|
|
|
|
39
|
return $self->{schedule}; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub identity { |
161
|
9
|
|
|
9
|
1
|
9280
|
my ($self) = @_; |
162
|
|
|
|
|
|
|
|
163
|
9
|
100
|
|
|
|
28
|
if (!defined $self->{identity}) { |
164
|
|
|
|
|
|
|
$self->{identity} = |
165
|
1
|
|
|
|
|
9
|
WebService::SendGrid::Newsletter::Identity->new(sgn => $self); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
9
|
|
|
|
|
57
|
return $self->{identity}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub categories { |
173
|
7
|
|
|
7
|
1
|
7344
|
my ($self) = @_; |
174
|
|
|
|
|
|
|
|
175
|
7
|
100
|
|
|
|
25
|
if (!defined $self->{categories}) { |
176
|
|
|
|
|
|
|
$self->{categories} = |
177
|
1
|
|
|
|
|
10
|
WebService::SendGrid::Newsletter::Categories->new(sgn => $self); |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
7
|
|
|
|
|
42
|
return $self->{categories}; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub last_response_code { |
185
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $self->{last_response_code}; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub last_response { |
192
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
return $self->{last_response}; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
__END__ |