File Coverage

blib/lib/WWW/DNSMadeEasy/Response.pm
Criterion Covered Total %
statement 16 20 80.0
branch 1 6 16.6
condition n/a
subroutine 7 8 87.5
pod 2 6 33.3
total 26 40 65.0


line stmt bran cond sub pod time code
1             package WWW::DNSMadeEasy::Response;
2             our $VERSION = '0.100';
3             our $AUTHORITY = 'cpan:GETTY';
4             # ABSTRACT: DNSMadeEasy Response
5              
6 8     8   55 use Moo;
  8         18  
  8         71  
7 8     8   3901 use JSON;
  8         22  
  8         120  
8              
9             has http_response => (
10             is => 'ro',
11             required => 1,
12             handles => ['is_success', 'content', 'decoded_content', 'status_line', 'code', 'header', 'as_string'],
13             );
14              
15 5     5 0 21 sub data { shift->as_hashref(@_) }
16              
17             sub as_hashref {
18 17     17 1 43 my ($self) = @_;
19 17 50       73 return unless $self->http_response->content; # DELETE return 200 but empty content
20 17         5697 return decode_json($self->http_response->content);
21             }
22              
23             sub error {
24 0     0 1 0 my ($self) = @_;
25 0         0 my $err = $self->data->{error};
26 0 0       0 $err = [$err] unless ref($err) eq 'ARRAY';
27 0 0       0 return wantarray ? @$err : join("\n", @$err);
28             }
29              
30             sub request_id {
31 1     1 0 3 my ( $self ) = @_;
32 1         39 $self->header('x-dnsme-requestId');
33             }
34              
35             sub request_limit {
36 1     1 0 3 my ( $self ) = @_;
37 1         26 $self->header('x-dnsme-requestLimit');
38             }
39              
40             sub requests_remaining {
41 1     1 0 4 my ( $self ) = @_;
42 1         29 $self->header('x-dnsme-requestsRemaining');
43             }
44              
45             1;
46              
47             __END__
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             WWW::DNSMadeEasy::Response - DNSMadeEasy Response
56              
57             =head1 VERSION
58              
59             version 0.100
60              
61             =head1 SYNOPSIS
62              
63             my $response = WWW::DNSMadeEasy->new(...)->request(...);
64             if ($response->is_success) {
65             my $data = $response->as_hashref;
66             my $requestsremaining = $response->header('x-dnsme-requestsremaining');
67             } else {
68             my @errors = $response->error;
69             }
70              
71             =head1 DESCRIPTION
72              
73             Response object to fetch headers and error data
74              
75             =head1 METHODS
76              
77             =head2 is_success
78              
79             =head2 content
80              
81             =head2 decoded_content
82              
83             =head2 status_line
84              
85             =head2 code
86              
87             =head2 header
88              
89             =head2 as_string
90              
91             All above are from L<HTTP::Response>
92              
93             my $requestsremaining = $response->header('x-dnsme-requestsremaining');
94             my $json_data = $response->as_string;
95              
96             =head2 as_hashref
97              
98             my $data = $response->as_hashref;
99              
100             convert response JSON to HashRef
101              
102             =head2 error
103              
104             my @errors = $response->error;
105              
106             get the detailed request errors
107              
108             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
109              
110             =head1 SUPPORT
111              
112             =head2 Source Code
113              
114             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
115             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
116             from your repository :)
117              
118             L<https://github.com/Getty/p5-www-dnsmadeeasy>
119              
120             git clone https://github.com/Getty/p5-www-dnsmadeeasy.git
121              
122             =head1 AUTHOR
123              
124             Torsten Raudssus <torsten@raudssus.de>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2012 by L<Torsten Raudssus|https://raudssus.de/>.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut