File Coverage

blib/lib/WebService/PayPal/PaymentsAdvanced/Response/FromHTTP.pm
Criterion Covered Total %
statement 33 33 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 11 11 100.0
pod 0 1 0.0
total 48 50 96.0


line stmt bran cond sub pod time code
1             package WebService::PayPal::PaymentsAdvanced::Response::FromHTTP;
2              
3 7     7   133121 use Moo;
  7         10785  
  7         46  
4              
5 7     7   3874 use namespace::autoclean;
  7         11633  
  7         44  
6              
7             our $VERSION = '0.000027';
8              
9 7     7   3852 use MooX::HandlesVia;
  7         14257  
  7         53  
10 7     7   1322 use MooX::StrictConstructor;
  7         4704  
  7         91  
11 7     7   29304 use Types::Standard qw( HashRef InstanceOf );
  7         81082  
  7         76  
12 7     7   6883 use Types::URI qw( Uri );
  7         100923  
  7         60  
13 7     7   2598 use URI;
  7         17  
  7         166  
14 7     7   522 use URI::QueryParam;
  7         940  
  7         169  
15 7     7   3456 use WebService::PayPal::PaymentsAdvanced::Error::HTTP;
  7         24  
  7         1664  
16              
17             # Don't use HasParams role as we want to build params rather than require them.
18              
19             has params => (
20             is => 'lazy',
21             isa => HashRef,
22             init_arg => undef,
23             );
24              
25             has _http_response => (
26             is => 'ro',
27             isa => InstanceOf ['HTTP::Response'],
28             init_arg => 'http_response',
29             required => 1,
30             handles => { _code => 'code', _content => 'content', },
31             );
32              
33             has _request_uri => (
34             init_arg => 'request_uri',
35             is => 'ro',
36             isa => Uri,
37             coerce => 1,
38             required => 1,
39             );
40              
41             sub BUILD {
42 19     19 0 56669 my $self = shift;
43             return
44 19 100 66     108 if $self->_http_response->is_success
45             && !$self->_http_response->header('X-Died');
46              
47 4         57 WebService::PayPal::PaymentsAdvanced::Error::HTTP
48             ->throw_from_http_response(
49             http_response => $self->_http_response,
50             request_uri => $self->_request_uri,
51             );
52             }
53              
54             sub _build_params {
55 14     14   1379 my $self = shift;
56 14         223 my $results = URI->new( '?' . $self->_content );
57 14         1214 return $results->query_form_hash;
58             }
59              
60             1;
61              
62             =pod
63              
64             =encoding UTF-8
65              
66             =head1 NAME
67              
68             WebService::PayPal::PaymentsAdvanced::Response::FromHTTP - Response object for WebService::PayPal::PaymentsAdvanced instantiated from HTTP::Response object
69              
70             =head1 VERSION
71              
72             version 0.000027
73              
74             =head1 DESCRIPTION
75              
76             This module provides an interface for extracting returned params from an
77             L<HTTP::Response> object. You won't need to this module directly if you are
78             using L<PayPal::PaymentsAdvanced/create_secure_token>.
79              
80             Throws a L<WebService::PayPal::PaymentsAdvanced::Error::HTTP> exception if the
81             HTTP request was not successful.
82              
83             =head1 OBJECT INSTANTIATION
84              
85             The following parameters can be supplied to C<new()> when creating a new object.
86              
87             =head2 Required Parameters
88              
89             =head3 http_response
90              
91             An L<HTTP::Response> object.
92              
93             =head2 Methods
94              
95             =head3 params
96              
97             Returns a C<HashRef> of parameters which have been extracted from the
98             L<HTTP::Response> object.
99              
100             =head1 SUPPORT
101              
102             Bugs may be submitted through L<https://github.com/maxmind/webservice-paypal-paymentsadvanced/issues>.
103              
104             =head1 AUTHOR
105              
106             Olaf Alders <olaf@wundercounter.com>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2021 by MaxMind, Inc.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut
116              
117             __END__
118             # ABSTRACT: Response object for WebService::PayPal::PaymentsAdvanced instantiated from HTTP::Response object
119