Amazon/SES/Response.pm

filter: Statementstmt 67.6% 117 / 173 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 73.4% 36 / 49 Podpod n/a totaltotal 54.0% 153 / 283 CC 30 SCAR 15.0
CC
30
Cov
50%
result
10.8
dkim_attributes
10.8
message_id
10.3
CRAP 4.5
« Amazon/SES.pm ↑ Summary Email/Sender/Transport/SES.pm »
1 2 ▶use Moops;
Subroutine __ANON__: called CC=1 SCAR=0.0
2
3 =head1 NAME
4
5 Amazon::SES::Response - Perl class that represents a response from AWS SES
6
7 =head1 SYNPOSIS
8
9 # see Amazon::SES
10
11 =head1 DESCRIPTION
12
13 This class is not meant to be used directly, but through L<Amazon::SES|Amazon::SES>. First you should be familiar with L<Amazon::SES|Amazon::SES> and only then come back to this class for new information
14
15 =head1 METHODS
16
17 =cut
18 2
19 2 ▶class Amazon::SES::Response :ro {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=1.1
20
21 2 ▶ use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
23
24 2 has 'response' => (is => 'ro');
25 2 has 'action' => (is => 'ro');
26 2 has 'data' => (is => 'rw');
27
28 0 ▶ method BUILD {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine BUILD: not called CC=2 SCAR=9.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
29 0 $self->data(XMLin(
30 $self->raw_content,
31 GroupTags => {
32 Identities => 'member',
33 DkimTokens => 'member'
34 },
35 KeepRoot => 0,
36 ForceArray => [ 'member', 'DkimAttributes' ]
37 ));
38 };
39
40 =head2 result()
41
42 Returns parsed contents of the response. This is usually the contents of C<*Result> element. Exception is the error response, in which case it returns the ontents of C<Error> element.
43
44 =cut
45
46 0 ▶ method result() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine result: not called CC=4 SCAR=23.7
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
47 0 ▶ if ($self->is_error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_error) 0 0 0
48 0 return $self->data; # error response do not have *Result containers
49 }
50 0 return $self->data->{ $self->action . 'Result' };
51 };
52
53 =head2 message_id()
54
55 Returns a message id for successfully sent e-mails. Only valid for successful requests.
56
57 =cut
58
59 0 ▶ method message_id() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine message_id: not called CC=4 SCAR=23.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
60 0 ▶ return unless $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result 0 0 0
61 0 return $self->result->{'MessageId'};
62 };
63
64 =head2 result_as_json()
65
66 Same as C<result()>, except converts the data into JSON notation
67
68 =cut
69
70 0 ▶ method result_as_json() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine result_as_json: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
71 0 return JSON::XS->new->allow_nonref->encode([$self->result]);
72 };
73
74 =head2 raw_content()
75
76 This is the raw (unparsed) by decoded HTTP content as returned from the AWS SES. Usually you do not need it. If you think you need it just knock yourself out!
77
78 =cut
79
80 0 ▶ method raw_content() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine raw_content: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
81 0 return $self->response->decoded_content;
82 };
83
84 =head2 is_success()
85
86 =head2 is_error()
87
88 This is the first thing you should check after each request().
89
90 =cut
91
92 0 ▶ method is_success() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine is_success: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
93 0 return $self->response->is_success;
94 };
95
96 0 ▶ method is_error() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine is_error: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
97 0 return $self->response->is_error;
98 };
99
100
101 =head2 http_code()
102
103 Since all the api request/response happens using HTTP Query actions, this code returns the HTTP response code. For all successfull response it returns C<200>, errors usually return C<400>. This is here just in case
104
105 =cut
106
107 0 ▶ method http_code() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine http_code: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
108 0 return $self->response->code;
109 };
110
111 =head2 error_code()
112
113 Returns an error code from AWS SES. Unlik C<http_code()>, this is a short error message, as documented in AWS SES API reference
114
115 =cut
116
117 0 ▶ method error_code() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine error_code: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
118 0 return $self->data->{Error}->{Code};
119 };
120
121 =head2 error_message()
122
123 Returns more descriptive error message from AWS SES
124
125 =cut
126
127 0 ▶ method error_message() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine error_message: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
128 0 return $self->data->{Error}->{Message};
129 };
130
131 =head2 error_type()
132
133 Returns the type of the error. Most of the time in my experience it returns C<Sender>.
134
135 =cut
136
137 0 ▶ method error_type() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine error_type: not called CC=3 SCAR=17.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
138 0 return $self->data->{Error}->{Type};
139 };
140
141 =head2 request_id()
142
143 Returns an ID of the request. All response, including the ones resulting in error, contain a RequestId.
144
145 =cut
146
147
148 0 ▶ method request_id() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine request_id: not called CC=4 SCAR=23.3
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
149 0 ▶ return $self->data->{RequestId} // $self->data->{'ResponseMetadata'}->{RequestId};
Condition0%0/3
$self->data->{"RequestId"} // $self->data->{"ResponseMetadata"}{"RequestId"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->data->{"RequestId"} // $self->data->{"ResponseMetadata"}{"RequestId"}
$self->data->{"RequestId"} $self->data->{"ResponseMetadata"}{"RequestId"}
Truth table0%0/3
A // B
A= $self->data->{"RequestId"}B= $self->data->{"ResponseMetadata"}{"RequestId"}
ABresult
1X1
011
000
150 }
151
152 =head2 dkim_attributes()
153
154 The same as
155
156 $response->result->{DkimAttributes}
157
158 Only meaning for get_dkim_attributes() api call
159
160 =cut
161
162
163 0 ▶ method dkim_attributes() {
Subroutine BEGIN: called CC=1 SCAR=2.3
Subroutine dkim_attributes: not called CC=4 SCAR=23.7
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
if @_ != 0 0 0 0
164 0 ▶ if ( my $attributes = $self->result->{DkimAttributes}->[0]->{entry} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attributes = $self->result->{"DkimAttributes"}[0]{"entry"}) 0 0 0
165 0 return $self->result->{DkimAttributes};
166 }
167 0 return;
168 }
169
170 }
171
172 =head1 SEE ALSO
173
174 L<Amazon::SES|Amazon::SES>
175
176 =head1 AUTHOR
177
178 Rusty Conover <rusty@luckydinosaur.com>
179
180 Sherzod B. Ruzmetov E<lt>sherzodr@cpan.orgE<gt>
181
182 =head1 COPYRIGHT AND LICENSE
183
184 Copyright (C) 2014 by Lucky Dinosaur, LLC http://www.luckydinosaur.com
185
186 Portions Copyright (C) 2013 by L<Talibro LLC|https://www.talibro.com>
187
188 This library is free software; you can redistribute it and/or modify
189 it under the same terms as Perl itself, either Perl version 5.14.2 or,
190 at your option, any later version of Perl 5 you may have available.
191
192 =cut
193
194 2 1;
« Amazon/SES.pm ↑ Summary Email/Sender/Transport/SES.pm »