File Coverage

blib/lib/Amazon/MWS/XML/Feed.pm
Criterion Covered Total %
statement 18 38 47.3
branch 0 8 0.0
condition n/a
subroutine 6 12 50.0
pod 5 5 100.0
total 29 63 46.0


line stmt bran cond sub pod time code
1             package Amazon::MWS::XML::Feed;
2              
3 7     7   596 use strict;
  7         11  
  7         259  
4 7     7   30 use warnings;
  7         11  
  7         225  
5 7     7   31 use utf8;
  7         9  
  7         46  
6              
7 7     7   186 use base 'Amazon::MWS::XML::GenericFeed';
  7         13  
  7         3799  
8 7     7   62 use Data::Dumper;
  7         12  
  7         504  
9              
10 7     7   55 use Moo;
  7         13  
  7         40  
11              
12             =head1 NAME
13              
14             Amazon::MWS::XML::Feed -- module to create XML feeds for Amazon MWS
15              
16             =head2 DESCRIPTION
17              
18             Extends Amazon::MWS::XML::GenericFeed and inherits its accessors/methods.
19              
20             =head1 ACCESSORS
21              
22             =head2 merchant_id
23              
24             Required. The merchant id provided by Amazon.
25              
26             =head2 products
27              
28             Required. An arrayref with products objects. The objects must respond
29             to the following methods:
30              
31             =over 4
32              
33             =item as_hash
34              
35             The data structure to populate the Product stanza.
36              
37             =back
38              
39             =cut
40              
41              
42             has products => (is => 'ro',
43             required => 1,
44             isa => sub {
45             die "Not an arrayref" unless ref($_[0]) eq 'ARRAY';
46             });
47              
48             sub _create_feed {
49 0     0     my ($self, $operation) = @_;
50              
51 0           my %methods = (
52             Product => 'as_product_hash',
53             Inventory => 'as_inventory_hash',
54             Price => 'as_price_hash',
55             ProductImage => 'as_images_array',
56             Relationship => 'as_variants_hash',
57             );
58              
59 0 0         my $method = $methods{$operation} or die "$operation is not supported";
60              
61 0           my @messages;
62 0           my $message_counter = 1;
63 0           my @products = @{ $self->products };
  0            
64 0           for (my $i = 0; $i < @products; $i++) {
65 0           my $data = $products[$i]->$method;
66 0 0         print Dumper($data) if $self->debug;
67             # unclear if it's the right thing to do
68 0 0         if (ref($data) eq 'ARRAY') {
    0          
69 0           foreach my $msg (@$data) {
70 0           push @messages, {
71             MessageID => $message_counter++,
72             OperationType => 'Update',
73             $operation => $msg,
74             };
75             }
76             }
77             elsif ($data) {
78 0           push @messages, {
79             MessageID => $message_counter++,
80             OperationType => 'Update',
81             # here will crash if the object is not the one required.
82             $operation => $data,
83             };
84             }
85             }
86 0           return $self->create_feed($operation, \@messages);
87             }
88              
89              
90             =head1 METHODS
91              
92             =head2 product_feed
93              
94             Return a string with the product XML.
95              
96             The Product feed contains descriptive information about the products
97             in your catalog. This information allows Amazon to build a record and
98             assign a unique identifier known as an ASIN (Amazon Standard Item
99             Number) to each product. This feed is always the first step in
100             submitting products to Amazon because it establishes the mapping
101             between the seller's unique identifier (SKU) and Amazon's unique
102             identifier (ASIN).
103              
104             =cut
105              
106             sub product_feed {
107 0     0 1   return shift->_create_feed('Product');
108             }
109              
110             =head2 inventory_feed
111              
112             The Inventory feed allows you to update inventory quantities (stock
113             levels) for your items. For each item you offer only on Amazon, send
114             the exact number you currently have in stock. If you use multiple
115             sales channels, we recommend configuring your systems to send a value
116             of zero once your available inventory reaches a level you specify.
117             When the quantity is greater than zero the buy button is activated and
118             the quantity is decremented with each order. When the quantity reaches
119             zero, the item is no longer available for purchase on Amazon until you
120             send a replenishment value. The inventory feed can also be used to
121             indicate the lead-time to ship a given item. If no value is sent, the
122             default value of two business days is used.
123              
124             =head2 inventory_feed_name
125              
126             =cut
127              
128             sub inventory_feed {
129 0     0 1   return shift->_create_feed('Inventory');
130             }
131              
132             =head2 price_feed
133              
134             The Price feed allows you to set the current price and sale price
135             (when applicable) for an item. The sale price is optional, but, if
136             used, the start and end date must be provided also (so far, not
137             implemented).
138              
139             =head2 price_feed_name
140              
141             =cut
142              
143             sub price_feed {
144 0     0 1   return shift->_create_feed('Price');
145             }
146              
147             =head2 image_feed
148              
149             The Image feed allows you to upload various images for a product.
150             Amazon can display several images for each product. It is in your best
151             interest to provide several high-resolution images for each of your
152             products so customers can make informed buying decisions.
153              
154             =head3 Image Requirements
155              
156             =over 4
157              
158             =item Format - photographs, not drawings
159              
160             =item Color Model - RGB (no CMYK images)
161              
162             =item Background - white or clear, no borders or words, no brand logos
163              
164             =item Recommended dimensions
165              
166             Images should be 1000 pixels or larger in either height or width as
167             this will enable zoom functionality on the website (zoom has proven to
168             enhance sales). The smallest your file should be is 500 pixels on the
169             longest side. Consistently sized images are strongly recommended.
170              
171             =item File type - JPEG (.jpg) or GIF (.gif)
172              
173             =item Resolution - 72 ppi
174              
175             =item Animation - none
176              
177             =back
178              
179             =cut
180              
181             sub image_feed {
182 0     0 1   return shift->_create_feed('ProductImage');
183             }
184              
185             =head2 variants_feed
186              
187             Creates variants feed.
188              
189             =cut
190              
191             sub variants_feed {
192 0     0 1   return shift->_create_feed('Relationship');
193             }
194              
195             1;
196              
197