Amazon-MWS
view release on metacpan or search on metacpan
lib/Amazon/MWS/Uploader.pm view on Meta::CPAN
package Amazon::MWS::Uploader;
use utf8;
use strict;
use warnings;
use DBI;
use Amazon::MWS::XML::Feed;
use Amazon::MWS::XML::Order;
use Amazon::MWS::Client;
use Amazon::MWS::XML::Response::FeedSubmissionResult;
use Amazon::MWS::XML::Response::OrderReport;
use Data::Dumper;
use File::Spec;
use DateTime;
use SQL::Abstract;
use Try::Tiny;
use Path::Tiny;
use Scalar::Util qw/blessed/;
use XML::Compile::Schema;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
use namespace::clean;
our $VERSION = '0.18';
use constant {
AMW_ORDER_WILDCARD_ERROR => 999999,
DEBUG => $ENV{AMZ_UPLOADER_DEBUG},
};
=head1 NAME
Amazon::MWS::Uploader -- high level agent to upload products to AMWS
=head1 DESCRIPTION
This module provide an high level interface to the upload process. It
has to keep track of the state to resume the uploading, which could
get stuck on the Amazon's side processing, so database credentials
have to be provided (or the database handle itself).
The table structure needed is defined and commented in sql/amazon.sql
=head1 SYNOPSIS
my $agent = Amazon::MWS::Uploader->new(
db_dsn => 'DBI:mysql:database=XXX',
db_username => 'xxx',
db_password => 'xxx',
db_options => \%options
# or dbh => $dbh,
schema_dir => '/path/to/xml_schema',
feed_dir => '/path/to/directory/for/xml',
merchant_id => 'xxx',
access_key_id => 'xxx',
secret_key => 'xxx',
marketplace_id => 'xxx',
endpoint => 'xxx',
products => \@products,
);
# say once a day, retrieve the full batch and send it up
$agent->upload;
# every 10 minutes or so, continue the work started with ->upload, if any
$agent->resume;
=head1 UPGRADE NOTES
When migrating from 0.05 to 0.06 please execute this SQL statement
ALTER TABLE amazon_mws_products ADD COLUMN listed BOOLEAN;
UPDATE amazon_mws_products SET listed = 1 WHERE status = 'ok';
When upgrading to 0.16, please execute this SQL statement:
ALTER TABLE amazon_mws_products ADD COLUMN warnings TEXT;
=head1 ACCESSORS
The following keys must be passed at the constructor and can be
accessed read-only:
=over 4
=item dbh
The DBI handle. If not provided will be built using the following
self-describing accessor:
=item db_dsn
=item db_username
=item db_password
=item db_options
E.g.
{
mysql_enable_utf8 => 1,
}
AutoCommit and RaiseError are set by us.
=cut
has db_dsn => (is => 'ro');
has db_password => (is => 'ro');
has db_username => (is => 'ro');
has db_options => (is => 'ro',
isa => AnyOf[Undef,HashRef],
);
has dbh => (is => 'lazy');
=item skus_warnings_modes
Determines how to treat warnings. This is a hash reference with the
code of the warning as key and one of the following modes as value:
=over 4
=item warn
Prints warning from Amazon with C<warn> function (default mode).
=item print
Prints warning from Amazon with C<print> function (default mode).
=item skip
Ignores warning from Amazon.
=back
=cut
has skus_warnings_modes => (is => 'rw',
isa => HashRef,
default => sub {{}},
);
=item order_days_range
When calling get_orders, check the orders for the last X days. It
accepts an integer which should be in the range 1-30. Defaults to 7.
Keep in mind that if you change the default and you have a lot of
orders, you will get throttled because for each order we retrieve the
orderline as well.
DEVEL NOTE: a possible smart fix would be to store this object in the
order (or into a closure) and make the orderline a lazy attribute
which will call C<ListOrderItems>.
=cut
has order_days_range => (is => 'rw',
default => sub { 7 },
isa => sub {
( run in 0.627 second using v1.01-cache-2.11-cpan-39bf76dae61 )