Ebay.pm

filter: Statementstmt 32.1% 75 / 233 Branchbran 1.6% 1 / 62 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 52.5% 21 / 40 Podpod 100% 14 / 14 totaltotal 29.1% 111 / 381 CC 43 SCAR 31.1
CC
43
Cov
24%
api_call_wrapper_silent
56.0
api_call_wrapper
56.0
api_call
42.0
CRAP 22.5
« Ebay/Response.pm ↑ Summary Ebay/Order.pm »
1 package Marketplace::Ebay;
2  
3 4 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use HTTP::Thin;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use XML::Compile::Schema;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use XML::Compile::Util qw/pack_type/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use XML::LibXML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Marketplace::Ebay::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Marketplace::Ebay::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 =head1 NAME
23  
24 Marketplace::Ebay - Making API calls to eBay (with XSD validation)
25  
26 =head1 VERSION
27  
28 Version 0.19
29  
30 =cut
31  
32 4 our $VERSION = '0.19';
33  
34 =head1 SYNOPSIS
35  
36 my $ebay = Marketplace::Ebay->new(
37 production => 0,
38 site_id => 77,
39 developer_key => '1234',
40 application_key => '6789',
41 certificate_key => '6666',
42 token => 'asd12348',
43 xsd_file => 'ebay.xsd',
44 );
45 my $res = $ebay->api_call('GeteBayOfficialTime', {});
46 print Dumper($res);
47  
48  
49 L<http://developer.ebay.com/Devzone/XML/docs/Concepts/MakingACall.html>
50  
51 =head1 DESCRIPTION
52  
53 =head2 International Selling
54  
55 Products propagate from your local selling account to all Ebay sites
56 where you are going to ship your items to:
57  
58 L<http://sellercentre.ebay.co.uk/advanced-international-selling>
59  
60 =head1 ACCESSORS
61  
62 =head2 Credentials
63  
64 The following are required for a successful API call.
65  
66 =head3 developer_key
67  
68 =head3 application_key
69  
70 =head3 certificate_key
71  
72 =head3 token
73  
74 =head3 site_id
75  
76 The id of the site. E.g., Germany is 77.
77  
78 L<https://developer.ebay.com/DevZone/merchandising/docs/Concepts/SiteIDToGlobalID.html>
79  
80 =head3 xsd_file
81  
82 Path to the XSD file with the eBay definitions.
83  
84 http://developer.ebay.com/webservices/latest/ebaySvc.xsd
85  
86 =head3 production
87  
88 Boolean. Default to false.
89  
90 By default, the API calls are done against the sandbox. Set it to true
91 in production.
92  
93 =head3 endpoint
94  
95 Set lazily by the class depending on the C<production> value.
96  
97 =head3 compatibility_level
98  
99 The version of API and XSD used. Please keep this in sync with the XSD.
100  
101 =head3 last_response
102  
103 You can get the HTTP::Response object of the last call using this
104 accessor.
105  
106 =head2 last_request
107  
108 You can get the HTTP::Request object of the last call using this
109 accessor.
110  
111 =head3 last_parsed_response
112  
113 Return a L<Marketplace::Ebay::Response> object (or undef on failure)
114 out of the return value of the last C<api_call>.
115  
116 =head3 log_file
117  
118 A filename where to log requests and responses.
119  
120 =head3 name_from_shipping_address
121  
122 Passed to L<Marketplace::Ebay::Order>. Defaults to true.
123  
124 =cut
125  
126 4 has developer_key => (is => 'ro', required => 1);
127 4 has application_key => (is => 'ro', required => 1);
128 4 has certificate_key => (is => 'ro', required => 1);
129 4 has token => (is => 'ro', required => 1);
130 4 has site_id => (is => 'ro', required => 1);
131 4 has site_code => (is => 'lazy');
132 2 ▶has name_from_shipping_address => (is => 'ro', isa => Bool, default => sub { 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
133  
134 sub _build_site_code {
135 0 ▶ my $self = shift;
Subroutine _build_site_code: not called CC=2 SCAR=17.9
136 0 my $code = $self->ebay_sites_id_to_name->{$self->site_id};
137 0 ▶ die $self->site_id . " doesn't map to a site name!" unless $code;
Branch: 1 branch
BranchTrueFalseTotal
unless $code 0 0 0
138 0 return $code;
139 }
140  
141 # totally random, as per Net::eBay
142 has compatibility_level => (is => 'ro',
143 2 ▶ default => sub { '655' });
Subroutine __ANON__: called CC=1 SCAR=0.0
144  
145 4 has session_certificate => (is => 'lazy');
146 0 ▶has production => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: not called CC=1 SCAR=1.2
147 4 has endpoint => (is => 'lazy');
148  
149 4 has last_response => (is => 'rwp');
150 4 has last_parsed_response => (is => 'rwp');
151 4 has last_request => (is => 'rwp');
152 4 has log_file => (is => 'rw');
153  
154 sub _build_endpoint {
155 0 ▶ my $self = shift;
Subroutine _build_endpoint: not called CC=2 SCAR=17.9
156 0 ▶ if ($self->production) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->production) { } 0 0 0
157 0 return 'https://api.ebay.com/ws/api.dll';
158 }
159 else {
160 0 return 'https://api.sandbox.ebay.com/ws/api.dll';
161 }
162 }
163  
164 sub _build_session_certificate {
165 1 ▶ my $self = shift;
Subroutine _build_session_certificate: called CC=1 SCAR=0.0
166 1 return join(';',
167 $self->developer_key,
168 $self->application_key,
169 $self->certificate_key);
170 }
171  
172 4 has xsd_file => (is => 'ro', required => 1);
173  
174 4 has schema => (is => 'lazy');
175  
176 sub _build_schema {
177 2 ▶ my $self = shift;
Subroutine _build_schema: called CC=2 SCAR=7.6
178 2 my $xsd_file = $self->xsd_file;
179 2 ▶ die "$xsd_file is not a file" unless -f $xsd_file;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $xsd_file 2 0 2
180 0 return XML::Compile::Schema->new($self->xsd_file);
181 }
182  
183  
184 =head1 METHODS
185  
186 =head2 api_call($name, \%data, \%options)
187  
188 Do the API call $name with payload in %data. Return the data structure
189 of the L<Marketplace::Ebay::Response> object. In case of failure,
190 return nothing. In this case, you can inspect the details of the
191 failure inspecting, e.g.,
192  
193 $self->last_response->status_line;
194  
195 With option C<requires_struct> set to a true value, the method doesn't
196 return the object, but a plain hashref with the structure returned
197 (old behaviour).
198  
199 With an option C<no_validate>, the XML is parsed using XMLin, not the
200 schema, so the result could be unstable, but on the other hand, you
201 get something out of XML which doesn't comply with the schema.
202  
203 =head2 prepare_xml($name, \%data)
204  
205 Create the XML document to send for the API call $name.
206  
207 =head2 show_xml_template($call, $call_type)
208  
209 Utility for development. Show the expected structure for the API call
210 $call. The second argument is optional, and may be Request or
211 Response, defaulting to Request.
212  
213 =head2 log_event(@data)
214  
215 Append the arguments to the C<log_file>, if it was defined.
216  
217 =cut
218  
219 sub api_call {
220 0 ▶ my ($self, $call, $data, $options) = @_;
Subroutine api_call: not called CC=6 SCAR=37.4
Pod documented
221 0 ▶ $options ||= {};
Condition0%0/2
$options ||= {}
l!l
00
MC/DC0%0/1
$options ||= {}
$options
Truth table0%0/2
A
A= $options
Aresult
11
00
222 0 $self->log_event("Preparing call to $call for " . Dumper($data));
223 0 my $xml = $self->prepare_xml($call, $data);
224 0 my $headers = $self->_prepare_headers($call);
225 0 my $request = HTTP::Request->new(POST => $self->endpoint, $headers, $xml);
226 0 $self->_set_last_request($request);
227 0 $self->log_event("Doing $call request\n" . $request->as_string);
228 0 my $response = HTTP::Thin->new->request($request);
229 0 $self->_set_last_response($response);
230 0 $self->log_event("Retrieving $call response\n" . $response->as_string);
231 0 $self->_set_last_parsed_response(undef);
232 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) 0 0 0
233 0 my $struct;
234 0 ▶ if ($options->{no_validate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'no_validate'}) { } 0 0 0
235 0 $struct = XMLin($response->decoded_content);
236 }
237 else {
238 0 $struct = $self->_parse_response($call, $response->decoded_content)
239 }
240 0 ▶ if ($struct) {
Branch: 1 branch
BranchTrueFalseTotal
if ($struct) 0 0 0
241 0 my $obj = Marketplace::Ebay::Response->new(struct => $struct);
242 0 $self->_set_last_parsed_response($obj);
243 0 $self->log_event("Got response:" . Dumper($struct));
244 0 ▶ if ($options->{requires_struct}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'requires_struct'}) { } 0 0 0
245 0 return $struct;
246 }
247 else {
248 0 return $obj;
249 }
250 }
251 }
252 0 return;
253 }
254  
255 sub _parse_response {
256 1 ▶ my ($self, $call, $xml) = @_;
Subroutine _parse_response: called CC=1 SCAR=2.6
257 1 my $reader = $self->schema->compile(READER => $self->_xml_type($call,
258 'Response'));
259 0 my $struct;
260 0 eval {
261 0 $struct = $reader->($xml);
262 };
263 0 return $struct;
264 }
265  
266 sub log_event {
267 0 ▶ my ($self, @strings) = @_;
Subroutine log_event: not called CC=4 SCAR=30.0
Pod documented
268 0 ▶ if (my $file = $self->log_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->log_file) 0 0 0
269 0 ▶ open (my $fh, '>>', $file) or die "Cannot open $file $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $file or die "Cannot open $file $!" 0 0 0
270 0 my $now = "\n" . localtime() . "\n";
271 0 print $fh $now, @strings;
272 0 ▶ close $fh or die "Cannot close $file $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Cannot close $file $!" 0 0 0
273 }
274 }
275  
276 sub _prepare_headers {
277 0 ▶ my ($self, $call) = @_;
Subroutine _prepare_headers: not called CC=1 SCAR=6.9
278 0 my $headers = HTTP::Headers->new;
279 0 $headers->push_header('X-EBAY-API-COMPATIBILITY-LEVEL' => $self->compatibility_level);
280 0 $headers->push_header('X-EBAY-API-DEV-NAME' => $self->developer_key);
281 0 $headers->push_header('X-EBAY-API-APP-NAME' => $self->application_key);
282 0 $headers->push_header('X-EBAY-API-CERT-NAME' => $self->certificate_key);
283 0 $headers->push_header('X-EBAY-API-CALL-NAME' => $call);
284 0 $headers->push_header('X-EBAY-API-SITEID' => $self->site_id);
285 0 $headers->push_header('Content-Type' => 'text/xml');
286 0 return $headers;
287 }
288  
289 sub show_xml_template {
290 0 ▶ my ($self, $call, $call_type) = @_;
Subroutine show_xml_template: not called CC=1 SCAR=6.9
Pod documented
291 0 return $self->schema->template(PERL => $self->_xml_type($call, $call_type),
292 use_default_namespace => 1);
293 }
294  
295 sub _xml_type {
296 0 ▶ my ($self, $call, $call_type) = @_;
Subroutine _xml_type: not called CC=4 SCAR=30.0
297 0 ▶ $call_type ||= 'Request';
Condition0%0/2
$call_type ||= "Request"
l!l
00
MC/DC0%0/1
$call_type ||= "Request"
$call_type
Truth table0%0/2
A
A= $call_type
Aresult
11
00
298 0 ▶ die "Second argument must be Request or Response, defaulting to Request"
Branch: 1 branch
BranchTrueFalseTotal
unless $call_type eq "Request" or $call_type eq "Response" 0 0 0
Condition0%0/3
$call_type eq "Request" or $call_type eq "Response"
l!l&&r!l&&!r
000
MC/DC0%0/2
$call_type eq "Request" or $call_type eq "Response"
$call_type eq "Request" $call_type eq "Response"
Truth table0%0/3
A or B
A= $call_type eq "Request"B= $call_type eq "Response"
ABresult
1X1
011
000
299 unless ($call_type eq 'Request' or $call_type eq 'Response');
300 0 return pack_type('urn:ebay:apis:eBLBaseComponents', $call . $call_type);
301 }
302  
303 sub prepare_xml {
304 0 ▶ my ($self, $name, $data) = @_;
Subroutine prepare_xml: not called CC=2 SCAR=17.9
Pod documented
305 0 ▶ $data ||= {};
Condition0%0/2
$data ||= {}
l!l
00
MC/DC0%0/1
$data ||= {}
$data
Truth table0%0/2
A
A= $data
Aresult
11
00
306 # inject the token
307 0 $data->{RequesterCredentials}->{eBayAuthToken} = $self->token;
308 0 my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
309 0 my $type = $self->_xml_type($name);
310 0 my $write = $self->schema->compile(WRITER => $type,
311 use_default_namespace => 1);
312 0 my $xml = $write->($doc, $data);
313 0 $doc->setDocumentElement($xml);
314 0 return $doc->toString(1);
315 }
316  
317 =head1 CONVENIENCE METHODS
318  
319 =cut
320  
321 =head2 api_call_wrapper($call, $data, @ids)
322  
323 Call Ebay's API $call with data $data. Then check the response and
324 return it. This ends calling $self->api_call($call, $data), but after
325 that the response is checked and diagnostics are printed out. If you
326 want something quiet and which is not going to die, or you're
327 expecting invalid structures, you should use C<api_call> directly.
328  
329 Return the response object. If no response object is found, it will
330 die.
331  
332 =head2 api_call_wrapper_silent($call, $data, @ids)
333  
334 Same as C<api_call_wrapper>, but do not emit "warn" on warnings. Just
335 print them out. Also, do not print ids or fees.
336  
337 =cut
338  
339 sub api_call_wrapper_silent {
340 0 ▶ my ($self, $call, $data, @identifiers) = @_;
Subroutine api_call_wrapper_silent: not called CC=7 SCAR=40.3
Pod documented
341 0 my $res = $self->api_call($call, $data);
342 0 my $message = $call;
343 0 ▶ if (@identifiers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@identifiers) 0 0 0
344 0 $message .= " on " . join(' ', @identifiers);
345 }
346 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 0 0 0
347 0 ▶ if ($res->request_ok) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->request_ok) { } 0 0 0
elsif ($res->errors) { } 0 0 0
348 0 ▶ if ($res->is_success) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
elsif ($res->errors) { } 0 0 0
349 0 print "$message OK\n";
350 }
351 elsif ($res->errors) {
352 0 print "$message:\n" . $res->errors_as_string;
353 }
354 else {
355 0 print "$message not a success but no errors found (OK?)\n";
356 }
357 }
358 elsif ($res->errors) {
359 0 warn "$message:\n" . $res->errors_as_string;
360 }
361 else {
362 0 die "$message: Nor success, nor errors!" . Dumper($res);
363 }
364 }
365 else {
366 0 die "No response found!" . $self->last_response->status_line
367 . "\n" . $self->last_response->content;
368 }
369 0 return $res;
370 }
371  
372  
373 sub api_call_wrapper {
374 0 ▶ my ($self, $call, $data, @identifiers) = @_;
Subroutine api_call_wrapper: not called CC=7 SCAR=40.3
Pod documented
375 0 my $res = $self->api_call($call, $data);
376 0 my $message = $call;
377 0 ▶ if (@identifiers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@identifiers) 0 0 0
378 0 $message .= " on " . join(' ', @identifiers);
379 }
380 0 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 0 0 0
381 0 ▶ if ($res->is_success) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
elsif ($res->errors) { } 0 0 0
382 0 print "$message OK\n";
383 }
384 elsif ($res->errors) {
385 0 warn "$message:\n" . $res->errors_as_string;
386 }
387 else {
388 0 die "$message: Nor success, nor errors!" . Dumper($res);
389 }
390 0 ▶ if (my $item_id = $res->item_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $item_id = $res->item_id) 0 0 0
391 0 print "$message: ebay id: $item_id\n";
392 }
393 0 my $fee = $res->total_listing_fee;
394 0 ▶ if (defined $fee) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fee) 0 0 0
395 0 print "$message Fee is $fee\n";
396 }
397 }
398 else {
399 0 die "No response found!" . $self->last_response->status_line
400 . "\n" . $self->last_response->content;
401 }
402 0 return $res;
403 }
404  
405 =head2 cancel_item($identifier, $id, $reason)
406  
407 $identifier is mandatory and can be C<SKU> or C<ItemID> (depending if
408 you do tracking by sku (this is possible only if the sku was uploaded
409 with InventoryTrackingMethod = SKU) or by ebay item id. The $id is
410 mandatory and is the sku or the ebay_id.
411  
412 Reason can be one of the following, defaulting to OtherListingError: Incorrect, LostOrBroken, NotAvailable, OtherListingError, SellToHighBidder, Sold.
413  
414 It calls EndFixedPriceItem, so this method is useful only for shops.
415  
416 =cut
417  
418 sub cancel_item {
419 0 ▶ my ($self, $key, $value, $reason) = @_;
Subroutine cancel_item: not called CC=6 SCAR=37.4
Pod documented
420 0 ▶ die "Missing SKU or ItemID" unless $key;
Branch: 1 branch
BranchTrueFalseTotal
unless $key 0 0 0
421 0 my %mapping = (
422 SKU => 'sku',
423 ItemID => 'ebay_sku',
424 );
425 0 my %reasons = (
426 Incorrect => 1,
427 LostOrBroken => 1,
428 NotAvailable => 1,
429 OtherListingError => 1,
430 SellToHighBidder => 1,
431 Sold => 1,
432 );
433 0 ▶ die "Invalid key $key" unless $mapping{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $mapping{$key} 0 0 0
434 0 ▶ unless ($reason && $reasons{$reason}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($reason and $reasons{$reason}) 0 0 0
Condition0%0/3
$reason and $reasons{$reason}
!ll&&!rl&&r
000
MC/DC0%0/2
$reason and $reasons{$reason}
$reason $reasons{$reason}
Truth table0%0/3
A and B
A= $reasonB= $reasons{$reason}
ABresult
0X0
100
111
435 0 $reason = 'OtherListingError';
436 }
437 0 ▶ die "Missing $key" unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
438 0 my $res = $self
439 ->api_call_wrapper(EndFixedPriceItem => {
440 EndingReason => $reason,
441 ErrorLanguage => 'en_US',
442 $key => $value,
443 }, $key, $value);
444 0 return $res;
445 }
446  
447 =head2 delete_sku_variations($sku, \@list_of_sku_variations)
448  
449 It uses ReviseFixedPriceItem to cancel variations of a given sku, not
450 passing asking for a deletion, but instead setting the quantity to 0.
451 This because deleting a variation is not possible if a purchase has
452 been done against it.
453  
454 =cut
455  
456 sub delete_sku_variations {
457 0 ▶ my ($self, $sku, $list) = @_;
Subroutine delete_sku_variations: not called CC=3 SCAR=24.8
Pod documented
458 0 ▶ die unless $sku && $list;
Branch: 1 branch
BranchTrueFalseTotal
unless $sku and $list 0 0 0
Condition0%0/3
$sku and $list
!ll&&!rl&&r
000
MC/DC0%0/2
$sku and $list
$sku $list
Truth table0%0/3
A and B
A= $skuB= $list
ABresult
0X0
100
111
459 0 my @delete = map { +{
460 0 Quantity => 0,
461 SKU => $_,
462 } } @$list;
463 0 my $data = {
464 ErrorLanguage => 'en_US',
465 WarningLevel => 'High',
466 Item => {
467 SKU => $sku,
468 Variations => {
469 Variation => \@delete,
470 }
471 },
472 };
473 0 my $res = $self->api_call_wrapper(ReviseFixedPriceItem => $data, $sku, "delete variations");
474 0 return $res;
475 }
476  
477 =head2 get_category_specifics($id)
478  
479 Return a dump of the structure found in the GetCategorySpecifics
480  
481 =cut
482  
483 sub get_category_specifics {
484 0 ▶ my ($self, $id) = @_;
Subroutine get_category_specifics: not called CC=2 SCAR=17.9
Pod documented
485 0 ▶ die "Missing category id" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
486 0 my $res = $self->api_call_wrapper(GetCategorySpecifics => {
487 CategoryID => $id,
488 }, "category id $id");
489 0 return $res;
490 }
491  
492 =head2 get_orders($number_of_days)
493  
494 Retrieve the last orders in the last number of days, defaulting to 7.
495 Return a list of L<Marketplace::Ebay::Order> objects. You can access
496 the raw structures with $object->order.
497  
498 =cut
499  
500 sub get_orders {
501 0 ▶ my ($self, $backlog) = @_;
Subroutine get_orders: not called CC=6 SCAR=37.4
Pod documented
502 0 ▶ $backlog ||= 7;
Condition0%0/2
$backlog ||= 7
l!l
00
MC/DC0%0/1
$backlog ||= 7
$backlog
Truth table0%0/2
A
A= $backlog
Aresult
11
00
503 0 my $request = {
504 NumberOfDays => $backlog,
505 Pagination => {
506 PageNumber => 1,
507 EntriesPerPage => 100,
508 },
509 ErrorLanguage => 'en_US',
510 };
511 0 my $repeat = 1;
512 0 my @orders;
513 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$repeat and do { do { my $obj = $self->api_call_wrapper_silent("GetOrders", $request); my $res = $obj->struct; if (exists $res->{"OrderArray"} and exists $res->{"OrderArray"}{"Order"}) { foreach my $ord (@{$$res{"OrderArray"}{"Order"};}) { push @orders, "Marketplace::Ebay::Order"->new("order", $ord, "name_from_shipping_address", $self->name_from_shipping_address); } ; } ; $repeat = $res->{"HasMoreOrders"}; ++$request->{"Pagination"}{"PageNumber"} } } 0 0 0
514 # we use the silent variant because it's a known warning spammer.
515 0 my $obj = $self->api_call_wrapper_silent(GetOrders => $request);
516 0 my $res = $obj->struct;
517 0 ▶ if (exists $res->{OrderArray} and
Branch: 1 branch
BranchTrueFalseTotal
if (exists $res->{"OrderArray"} and exists $res->{"OrderArray"}{"Order"}) 0 0 0
Condition0%0/3
exists $res->{"OrderArray"} and exists $res->{"OrderArray"}{"Order"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $res->{"OrderArray"} and exists $res->{"OrderArray"}{"Order"}
exists $res->{"OrderArray"} exists $res->{"OrderArray"}{"Order"}
Truth table0%0/3
A and B
A= exists $res->{"OrderArray"}B= exists $res->{"OrderArray"}{"Order"}
ABresult
0X0
100
111
518 exists $res->{OrderArray}->{Order}) {
519 0 foreach my $ord (@{$res->{OrderArray}->{Order}}) {
520 0 push @orders, Marketplace::Ebay::Order->new(order => $ord,
521 name_from_shipping_address => $self->name_from_shipping_address);
522 }
523 }
524 0 $repeat = $res->{HasMoreOrders};
525 0 $request->{Pagination}->{PageNumber}++;
526 } while ($repeat);
527  
528 0 return @orders;
529 }
530  
531 =head2 get_orders_for_site
532  
533 Like get_orders, but filter the orders by the site_id of the object
534 (otherwise you pull the orders from all the international sites).
535  
536 =cut
537  
538 sub get_orders_for_site {
539 0 ▶ my ($self, $backlog) = @_;
Subroutine get_orders_for_site: not called CC=1 SCAR=6.9
Pod documented
540 0 my @orders = $self->get_orders($backlog);
541 0 my $name = $self->site_code;
542 0 return grep { $_->ebay_site eq $name } @orders;
543 }
544  
545 =head2 ebay_site_code_types (internal)
546  
547 L<http://developer.ebay.com/devzone/XML/docs/Reference/ebay/types/SiteCodeType.html>
548 turned into an hashref to map the site name to an id.
549  
550 =head2 ebay_sites_name_to_id
551  
552 Return an hashref for mapping ebay site names and abbreviations to a numeric id.
553  
554 =head2 ebay_sites_id_to_name
555  
556 Return an hashref for mapping ebay site id to its name.
557 # http://developer.ebay.com/devzone/XML/docs/Reference/ebay/types/SiteCodeType.html
558  
559 =cut
560  
561 sub ebay_site_code_types {
562  
563 0 ▶ my %codes = (
Subroutine ebay_site_code_types: not called CC=1 SCAR=6.9
Pod documented
564 Australia => { id => 15, abbreviation => "AU" },
565 Austria => { id => 16, abbreviation => "AT" },
566 Belgium_Dutch => { id => 123, abbreviation => "BENL" },
567 Belgium_French => { id => 23, abbreviation => "BEFR" },
568 Canada => { id => 2, abbreviation => "CA" },
569 CanadaFrench => { id => 210, abbreviation => "CAFR" },
570 France => { id => 71, abbreviation => "FR" },
571 Germany => { id => 77, abbreviation => "DE" },
572 HongKong => { id => 201, abbreviation => "HK" },
573 India => { id => 203, abbreviation => "IN" },
574 Ireland => { id => 205, abbreviation => "IE" },
575 Italy => { id => 101, abbreviation => "IT" },
576 Malaysia => { id => 207, abbreviation => "MY" },
577 Netherlands => { id => 146, abbreviation => "NL" },
578 Philippines => { id => 211, abbreviation => "PH" },
579 Poland => { id => 212, abbreviation => "PL" },
580 Russia => { id => 215, abbreviation => "RU" },
581 Singapore => { id => 216, abbreviation => "SG" },
582 Spain => { id => 186, abbreviation => "ES" },
583 Switzerland => { id => 193, abbreviation => "CH" },
584 UK => { id => 3, abbreviation => "UK" },
585 US => { id => 0, abbreviation => "US" },
586 );
587 0 return %codes;
588 }
589  
590 sub ebay_sites_name_to_id {
591 0 ▶ my $self = shift;
Subroutine ebay_sites_name_to_id: not called CC=2 SCAR=17.9
Pod documented
592 0 my %out;
593 0 my %codes = $self->ebay_site_code_types;
594 0 foreach my $k (keys %codes) {
595 0 $out{$k} = $codes{$k}{id};
596 0 $out{$codes{$k}{abbreviation}} = $codes{$k}{id};
597 }
598 0 return \%out;
599 }
600  
601 sub ebay_sites_id_to_name {
602 0 ▶ my $self = shift;
Subroutine ebay_sites_id_to_name: not called CC=2 SCAR=17.9
Pod documented
603 0 my %codes = $self->ebay_site_code_types;
604 0 my %out;
605 0 foreach my $k (keys %codes) {
606 0 $out{$codes{$k}{id}} = $k;
607 }
608 0 return \%out;
609 }
610  
611 =head1 AUTHOR
612  
613 Marco Pessotto, C<< <melmothx at gmail.com> >>
614  
615 =head1 BUGS
616  
617 Please report any bugs or feature requests to C<bug-marketplace-ebay at rt.cpan.org>, or through
618 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Marketplace-Ebay>. I will be notified, and then you'll
619 automatically be notified of progress on your bug as I make changes.
620  
621  
622  
623  
624 =head1 SUPPORT
625  
626 You can find documentation for this module with the perldoc command.
627  
628 perldoc Marketplace::Ebay
629  
630  
631 You can also look for information at:
632  
633 =over 4
634  
635 =item * RT: CPAN's request tracker (report bugs here)
636  
637 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Marketplace-Ebay>
638  
639 =item * AnnoCPAN: Annotated CPAN documentation
640  
641 L<http://annocpan.org/dist/Marketplace-Ebay>
642  
643 =item * CPAN Ratings
644  
645 L<http://cpanratings.perl.org/d/Marketplace-Ebay>
646  
647 =item * Search CPAN
648  
649 L<http://search.cpan.org/dist/Marketplace-Ebay/>
650  
651 =back
652  
653  
654 =head1 ACKNOWLEDGEMENTS
655  
656  
657 =head1 LICENSE AND COPYRIGHT
658  
659 Copyright 2014 Marco Pessotto.
660  
661 This program is free software; you can redistribute it and/or modify it
662 under the terms of either: the GNU General Public License as published
663 by the Free Software Foundation; or the Artistic License.
664  
665 See L<http://dev.perl.org/licenses/> for more information.
666  
667  
668 =cut
669  
670 4 1; # End of Marketplace::Ebay
« Ebay/Response.pm ↑ Summary Ebay/Order.pm »