Client/NoMoose.pm

filter: Statementstmt 51.0% 47 / 92 Branchbran 16.6% 2 / 12 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 55.0% 11 / 20 Podpod 100% 9 / 9 totaltotal 47.9% 71 / 148 CC 11 SCAR 17.1
CC
11
Cov
45%
detail_sale
20.0
list_sales
6.0
detail_coupon
6.0
CRAP 5.5
« Client/Moose.pm ↑ Summary Client.pm »
1 package VendorAPI::2Checkout::Client::NoMoose;
2  
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use URI::QueryParam;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 VendorAPI::2Checkout::Client::NoMoose - an non-Moose OO interface to the 2Checkout.com Vendor API
16  
17 =head1 VERSION
18  
19 Version 0.1502
20  
21 =cut
22  
23 1 ▶use vars qw( $VERSION @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 @ISA = ( 'VendorAPI::2Checkout::Client' );
26 1 $VERSION = '0.1502';
27  
28 =head1 SYNOPSIS
29  
30 use VendorAPI::2Checkout::Client;
31  
32 my $tco = VendorAPI::2Checkout::Client->new($username, $password, $format);
33 $response = $tco->list_sales();
34  
35 $response = $tco->detail_sale(sale_id => 1234554323);
36  
37 $response = $tco->list_coupons();
38  
39 $response = $tco->detail_coupon(coupon_code => 'COUPON42');
40  
41 $response = $tco->list_payments();
42  
43 $response = $tco->list_products();
44  
45 $response = $tco->list_options();
46  
47 ...
48  
49 =head1 DESCRIPTION
50  
51 This module is an OO interface to the 2Checkout.com Vendor API.
52  
53 This modules uses Params::Validate which likes to die() when the parameters do not pass validation, so
54 wrap your code in evals, etc.
55  
56 Presently implements list_sales(), detail_sale(), list_coupons(), and detail_coupon(), list_payments(),
57 list_options(), list_products().
58  
59 Return data is in XML or JSON.
60  
61 Please refer to L<2Checkout's Back Office Admin API Documentation|http://www.2checkout.com/documentation/api>
62 for input parameters and expexted return values.
63  
64 =head1 CONSTRUCTORS AND METHODS
65  
66 =over 4
67  
68 =item $c = VendorAPI::2Checkout::Client->new($username, $password, $format)
69  
70 Contructs a new C<VendorAPI::2Checkout::Client> object to comminuncate with the 2Checkout Back Office Admin API.
71 You must pass your Vendor API username and password or the constructor will return undef;
72  
73 =cut
74  
75 3 ▶sub new {
Subroutine new: called CC=5 SCAR=17.8
Pod documented
76 3 my $class = shift;
77 3 my $username = shift;
78 3 my $password = shift;
79 3 my $accept = shift;
80  
81 3 ▶ unless ( $username && $password) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($username and $password) 0 3 3
Condition33%1/3
$username and $password
!ll&&!rl&&r
003
MC/DC0%0/2
$username and $password
$username $password
Truth table33%1/3
A and B
A= $usernameB= $password
ABresult
0X0
100
111
82 0 return undef;
83 }
84  
85 3 ▶ unless ( defined $accept && $accept =~ qr/^(?:XML|JSON)$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $accept and $accept =~ qr/^(?:XML|JSON)$/) 0 3 3
Condition33%1/3
defined $accept and $accept =~ qr/^(?:XML|JSON)$/
!ll&&!rl&&r
003
MC/DC0%0/2
defined $accept and $accept =~ qr/^(?:XML|JSON)$/
defined $accept $accept =~ qr/^(?:XML|JSON)$/
Truth table33%1/3
A and B
A= defined $acceptB= $accept =~ qr/^(?:XML|JSON)$/
ABresult
0X0
100
111
86 0 $accept = 'XML';
87 }
88  
89 3 my $self = bless {}, $class;
90 3 my $ua = LWP::UserAgent->new( agent => "VendorAPI::2Checkout::Client/${VERSION}" );
91 3 $ua->credentials($self->SUPER::_netloc(), $self->SUPER::_realm(), $username, $password);
92  
93 3 $self->{ua} = $ua;
94 3 $self->{accept} = $self->mime_type($accept);
95 3 return $self;
96 }
97  
98 =item $response = $c->list_sales();
99  
100 Retrieves the list of sales for the vendor
101  
102 =cut
103  
104 1 my $sort_col_re = qr/^(sale_id|date_placed|customer_name|recurring|recurring_declined|usd_total)$/;
105 1 my $sort_dir_re = qr/^(ASC|DESC)$/;
106  
107 1 my %v = (
108 sale_id => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, },
109 invoice_id => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, },
110 pagesize => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, },
111 cur_page => { type => SCALAR, regex => qw/^\d+$/ , untaint => 1, optional => 1, },
112 customer_name => { type => SCALAR, regex => qw/^[-A-Za-z.]+$/ , untaint => 1, optional => 1, },
113 customer_email => { type => SCALAR, regex => qw/^[-\w.+@]+$/ , untaint => 1, optional => 1, },
114 customer_phone => { type => SCALAR, regex => qw/^[\d()-]+$/ , untaint => 1, optional => 1, },
115 vendor_product_id => { type => SCALAR, regex => qw/^.+$/ , untaint => 1, optional => 1, },
116 ccard_first6 => { type => SCALAR, regex => qw/^\d{6}$/ , untaint => 1, optional => 1, },
117 ccard_last2 => { type => SCALAR, regex => qw/^\d\d$/ , untaint => 1, optional => 1, },
118 date_sale_end => { type => SCALAR, regex => qw/^\d{4}-\d\d-\d\d$/ , untaint => 1, optional => 1, },
119 date_sale_begin => { type => SCALAR, regex => qw/^\d{4}-\d\d-\d\d$/ , untaint => 1, optional => 1, },
120 sort_col => { type => SCALAR, regex => $sort_col_re , untaint => 1, optional => 1, },
121 sort_dir => { type => SCALAR, regex => $sort_dir_re , untaint => 1, optional => 1, },
122 active_recurrings => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, },
123 declined_recurrings => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, },
124 refunded => { type => SCALAR, regex => qr/^[01]$/, untaint => 1, optional => 1, },
125 );
126  
127 1 my $_profile = { map { $_ => $v{$_} } keys %v };
128  
129 0 ▶sub list_sales {
Subroutine list_sales: not called CC=2 SCAR=17.9
Pod documented
130 0 my $self = shift;
131 0 my $uri = URI->new($self->SUPER::_base_uri . '/sales/list_sales');
132 0 my %headers = ( Accept => $self->_accept() );
133  
134 0 my %input_params = validate(@_, $_profile);
135  
136 0 foreach my $param_name ( keys %input_params ) {
137 0 $uri->query_param($param_name => $input_params{$param_name});
138 }
139  
140 0 $self->_ua->get($uri, %headers);
141 }
142  
143 =item $response = $c->list_coupons();
144  
145 Retrieves the list of coupons for the vendor
146  
147 =cut
148  
149 0 ▶sub list_coupons {
Subroutine list_coupons: not called CC=1 SCAR=6.9
Pod documented
150 0 my $self = shift;
151 0 $self->call_2co_api('/products/list_coupons');
152 }
153  
154 =item $response = $c->detail_sale(sale_id => $sale_id);
155  
156 Retrieves the details for the named sale.
157  
158 =cut
159  
160 0 ▶sub detail_sale {
Subroutine detail_sale: not called CC=4 SCAR=30.0
Pod documented
161 0 my $self = shift;
162 0 my $_detail_profile = { map { $_ => $v{$_} } qw/sale_id invoice_id/ };
163 0 my %p = validate(@_, $_detail_profile);
164  
165 0 ▶ unless ($p{sale_id} || $p{invoice_id}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"sale_id"} or $p{"invoice_id"}) 0 0 0
Condition0%0/3
$p{"sale_id"} or $p{"invoice_id"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$p{"sale_id"} or $p{"invoice_id"}
$p{"sale_id"} $p{"invoice_id"}
Truth table0%0/3
A or B
A= $p{"sale_id"}B= $p{"invoice_id"}
ABresult
1X1
011
000
166 0 confess("detail_sale requires sale_id or invoice_id and received neither");
167 }
168  
169 0 my $uri = URI->new($self->SUPER::_base_uri . '/sales/detail_sale');
170 0 my %headers = ( Accept => $self->_accept() );
171  
172 0 ▶ if ($p{invoice_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{'invoice_id'}) { } 0 0 0
173 0 $uri->query_param(invoice_id => $p{invoice_id});
174 }
175 else {
176 0 $uri->query_param(sale_id => $p{sale_id});
177 }
178  
179 0 $self->_ua->get($uri, %headers);
180 }
181  
182 =item $response = $c->detail_coupon(coupon_code => $coupon_code);
183  
184 Retrieves the details for the named coupon.
185  
186 =cut
187  
188 0 ▶sub detail_coupon {
Subroutine detail_coupon: not called CC=2 SCAR=17.9
Pod documented
189 0 my $self = shift;
190 0 my $_detail_profile = { coupon_code => { type => SCALAR, regex => qr/^\w+$/, untaint => 1, optional => 0, }, };
191 0 my %p = validate(@_, $_detail_profile);
192  
193 0 ▶ unless ( $p{coupon_code} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($p{"coupon_code"}) 0 0 0
194 0 confess("detail_coupon requires coupon_code");
195 }
196  
197 0 my $uri = URI->new($self->SUPER::_base_uri . '/products/detail_coupon');
198 0 my %headers = ( Accept => $self->_accept() );
199  
200 0 $uri->query_param(coupon_code => $p{coupon_code});
201  
202 0 $self->_ua->get($uri, %headers);
203 }
204  
205 =item $response = $c->list_payments();
206  
207 Retrieves the list of payments for the vendor
208  
209 =cut
210  
211 0 ▶sub list_payments {
Subroutine list_payments: not called CC=1 SCAR=6.9
Pod documented
212 0 my $self = shift;
213 0 $self->call_2co_api('/acct/list_payments');
214 }
215  
216 =item $response = $c->list_products();
217  
218 Retrieves the list of products for the vendor
219  
220 =cut
221  
222 0 ▶sub list_products {
Subroutine list_products: not called CC=1 SCAR=6.9
Pod documented
223 0 my $self = shift;
224 0 $self->call_2co_api('/products/list_products');
225 }
226  
227 =item $response = $c->list_options();
228  
229 Retrieves the list of options for the vendor
230  
231 =cut
232  
233 0 ▶sub list_options {
Subroutine list_options: not called CC=1 SCAR=6.9
Pod documented
234 0 my $self = shift;
235 0 $self->call_2co_api('/products/list_options');
236 }
237  
238  
239 =item $response = $c->call_2co_api();
240  
241 Talks to 2CO on behalf of the API methods
242  
243 =cut
244  
245 0 ▶sub call_2co_api {
Subroutine call_2co_api: not called CC=2 SCAR=17.9
Pod documented
246 0 my $self = shift;
247 0 my $api_path = shift;
248 0 ▶ return undef unless $api_path;
Branch: 1 branch
BranchTrueFalseTotal
unless $api_path 0 0 0
249 0 my $uri = URI->new($self->SUPER::_base_uri . $api_path);
250 0 my %headers = ( Accept => $self->_accept() );
251 0 $self->_ua->get($uri, %headers);
252 }
253  
254  
255 #####################################################
256  
257 2 ▶sub _accept {
Subroutine _accept: called CC=1 SCAR=0.0
258 2 $_[0]->{accept};
259 };
260  
261 0 ▶sub _ua {
Subroutine _ua: not called CC=1 SCAR=6.9
262 0 $_[0]->{ua};
263 };
264  
265 =back
266  
267 =head1 AUTHOR
268  
269 Len Jaffe, C<< <lenjaffe at jaffesystems.com> >>
270  
271 =head1 GITHUB
272  
273 The source code is available at
274 L<Github|https://github.com/vampirechicken/VendorAPI--2Checkout--Client>
275  
276 =head1 BUGS
277  
278 Please report any bugs or feature requests to C<bug-vendorapi-2checkout-client at rt.cpan.org>, or through
279 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=VendorAPI-2Checkout-Client>. I will be notified, and then you'll
280 automatically be notified of progress on your bug as I make changes.
281  
282 =head1 SUPPORT
283  
284 You can find documentation for this module with the perldoc command.
285  
286 perldoc VendorAPI::2Checkout::Client
287  
288 You can also look for information at:
289  
290 =over 4
291  
292 =item * RT: CPAN's request tracker (report bugs here)
293  
294 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=VendorAPI-2Checkout-Client>
295  
296 =item * AnnoCPAN: Annotated CPAN documentation
297  
298 L<http://annocpan.org/dist/VendorAPI-2Checkout-Client>
299  
300 =item * CPAN Ratings
301  
302 L<http://cpanratings.perl.org/d/VendorAPI-2Checkout-Client>
303  
304 =item * Search CPAN
305  
306 L<http://search.cpan.org/dist/VendorAPI-2Checkout-Client/>
307  
308 =back
309  
310 =head1 ACKNOWLEDGEMENTS
311  
312 =head1 LICENSE AND COPYRIGHT
313  
314 Copyright 2012 Len Jaffe.
315  
316 This program is free software; you can redistribute it and/or modify it
317 under the terms of either: the GNU General Public License as published
318 by the Free Software Foundation; or the Artistic License.
319  
320 See http://dev.perl.org/licenses/ for more information.
321  
322 =cut
323  
324 1 1; # End of VendorAPI::2Checkout::Client
« Client/Moose.pm ↑ Summary Client.pm »