SES/Response.pm

filter: Statementstmt 26.4% 14 / 53 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 22.2% 4 / 18 Podpod 92.3% 12 / 13 totaltotal 28.0% 30 / 107 CC 9 SCAR 21.4
CC
9
Cov
19%
new
30.0
message_id
6.0
result
6.0
CRAP 8.5
« SES.pm ↑ Summary
1 package Net::AWS::SES::Response;
2
3 =head1 NAME
4
5 Net::AWS::SES::Response - Perl class that represents a response from AWS SES
6
7 =head1 SYNPOSIS
8
9 # see Net::AWS::SES
10
11 =head1 DESCRIPTION
12
13 This class is not meant to be used directly, but through L<Net::AWS::SES|Net::AWS::SES>. First you should be familiar with L<Net::AWS::SES|Net::AWS::SES> and only then come back to this class for new information
14
15 =head1 METHODS
16
17 =cut
18
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Carp ('croak');
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
23
24 1 our $VERSION = '0.03';
25
26 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
27 0 my $class = shift;
28 0 my ( $response, $action ) = @_;
29
30 0 ▶ unless ( $response
Branch: 1 branch
BranchTrueFalseTotal
unless ($response and ref $response and $response->isa("HTTP::Response") and $action) 0 0 0
Condition0%0/9
$response and ref $response and $response->isa("HTTP::Response") and $action
!ll&&!rl&&r
000
$response and ref $response and $response->isa("HTTP::Response")
!ll&&!rl&&r
000
$response and ref $response
!ll&&!rl&&r
000
MC/DC0%0/4
$response and ref $response and $response->isa("HTTP::Response") and $action
$response ref $response $response->isa("HTTP::Response") $action
Truth table0%0/5
A and B and C and D
A= $responseB= ref $responseC= $response->isa("HTTP::Response")D= $action
ABCDresult
0XXX0
10XX0
110X0
11100
11111
31 && ref($response)
32 && $response->isa("HTTP::Response")
33 && $action )
34 {
35 0 croak "new(): usage error";
36 }
37 0 my $self = bless { __response => $response, data => {}, action => $action },
38 $class;
39 0 $self->__parse_response;
40 0 return $self;
41 }
42
43 0 ▶sub __parse_response {
Subroutine __parse_response: not called CC=1 SCAR=6.9
44 0 my $self = shift;
45 0 $self->{data} = XMLin(
46 $self->raw_content,
47 GroupTags => {
48 Identities => 'member',
49 DkimTokens => 'member'
50 },
51 KeepRoot => 0,
52 ForceArray => [ 'member', 'DkimAttributes' ]
53 );
54 }
55
56 =head2 message_id()
57
58 Returns a message id for successfully sent e-mails. Only valid for successful requests.
59
60 =cut
61
62 0 ▶sub message_id {
Subroutine message_id: not called CC=2 SCAR=17.9
Pod documented
63 0 my $self = shift;
64 0 my $action = $self->{action};
65 0 ▶ return unless $self->result;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->result 0 0 0
66 0 return $self->result->{'MessageId'};
67 }
68
69 =head2 result()
70
71 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.
72
73 =cut
74
75 0 ▶sub result {
Subroutine result: not called CC=2 SCAR=17.9
Pod documented
76 0 my $self = shift;
77 0 my $action = $self->{action};
78 0 ▶ if ( $self->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_error) 0 0 0
79 0 return $self->{data}; # error response do not have *Result containers
80 }
81 0 return $self->{data}->{ $action . 'Result' };
82 }
83
84 =head2 result_as_json()
85
86 Same as C<result()>, except converts the data into JSON notation
87
88 =cut
89
90 0 ▶sub result_as_json {
Subroutine result_as_json: not called CC=1 SCAR=6.9
Pod documented
91 0 my $self = shift;
92 0 require JSON;
93 0 return JSON::to_json( $self->result, { pretty => 1 } );
94 }
95
96 =head2 raw_content()
97
98 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!
99
100 =cut
101
102 0 ▶sub raw_content {
Subroutine raw_content: not called CC=1 SCAR=6.9
Pod documented
103 0 return $_[0]->{__response}->decoded_content;
104 }
105
106 =head2 is_success()
107
108 =head2 is_error()
109
110 This is the first thing you should check after each request().
111
112 =cut
113
114 0 ▶sub is_success {
Subroutine is_success: not called CC=1 SCAR=6.9
Pod documented
115 0 return $_[0]->{__response}->is_success;
116 }
117
118 0 ▶sub is_error {
Subroutine is_error: not called CC=1 SCAR=6.9
Pod documented
119 0 return $_[0]->{__response}->is_error;
120 }
121
122 =head2 http_code()
123
124 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
125
126 =cut
127
128 0 ▶sub http_code {
Subroutine http_code: not called CC=1 SCAR=6.9
Pod documented
129 0 return $_[0]->{__response}->code;
130 }
131
132 =head2 error_code()
133
134 Returns an error code from AWS SES. Unlik C<http_code()>, this is a short error message, as documented in AWS SES API reference
135
136 =cut
137
138 =head2 error_message()
139
140 Returns more descriptive error message from AWS SES
141
142 =head2 error_type()
143
144 Returns the type of the error. Most of the time in my experience it returns C<Sender>.
145
146 =cut
147
148 0 ▶sub error_code {
Subroutine error_code: not called CC=1 SCAR=6.9
Pod documented
149 0 my $self = shift;
150 0 return $self->{data}->{Error}->{Code};
151 }
152
153 0 ▶sub error_message {
Subroutine error_message: not called CC=1 SCAR=6.9
Pod documented
154 0 my $self = shift;
155 0 return $self->{data}->{Error}->{Message};
156 }
157
158 0 ▶sub error_type {
Subroutine error_type: not called CC=1 SCAR=6.9
Pod documented
159 0 my $self = shift;
160 0 return $self->{data}->{Error}->{Type};
161 }
162
163 =head2 request_id()
164
165 Returns an ID of the request. All response, including the ones resulting in error, contain a RequestId.
166
167 =cut
168
169 0 ▶sub request_id {
Subroutine request_id: not called CC=2 SCAR=17.9
Pod documented
170 0 my $self = shift;
171 0 ▶ return $self->{data}->{RequestId} if $self->{data}->{RequestId};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"data"}{"RequestId"} 0 0 0
172 0 my $action = $self->{action};
173 0 return $self->{data}->{'ResponseMetadata'}->{RequestId};
174 }
175
176 =head2 dkim_attributes()
177
178 The same as
179
180 $response->result->{DkimAttributes}
181
182 Only meaning for get_dkim_attributes() api call
183
184 =cut
185
186 0 ▶sub dkim_attributes {
Subroutine dkim_attributes: not called CC=2 SCAR=17.9
Pod documented
187 0 my $self = shift;
188 0 ▶ if ( my $attributes = $self->result->{DkimAttributes}->[0]->{entry} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $attributes = $self->result->{"DkimAttributes"}[0]{"entry"}) 0 0 0
189 0 return $self->result->{DkimAttributes};
190 }
191 0 return;
192 }
193
194 =head1 SEE ALSO
195
196 L<Net::AWS::SES|Net::AWS::SES>
197
198 =head1 AUTHOR
199
200 Sherzod B. Ruzmetov E<lt>sherzodr@cpan.orgE<gt>
201
202 =head1 COPYRIGHT AND LICENSE
203
204 Copyright (C) 2013 by L<Talibro LLC|https://www.talibro.com>
205
206 This library is free software; you can redistribute it and/or modify
207 it under the same terms as Perl itself, either Perl version 5.14.2 or,
208 at your option, any later version of Perl 5 you may have available.
209
210 =cut
211
212 1 1;
« SES.pm ↑ Summary