Amazon-MWS
view release on metacpan or search on metacpan
lib/Amazon/MWS/Uploader.pm view on Meta::CPAN
An L<Amazon::MWS::Client> object, built lazily, so you don't have to
pass it.
=back
=cut
has client => (is => 'lazy');
sub _build_client {
my $self = shift;
my %mws_args = map { $_ => $self->$_ } (qw/merchant_id
marketplace_id
access_key_id
secret_key
debug
logfile
endpoint/);
return Amazon::MWS::Client->new(%mws_args);
}
has _mismatch_patterns => (is => 'lazy', isa => HashRef);
sub _build__mismatch_patterns {
my $self = shift;
my $merchant_re = qr{\s+\((?:Merchant|Verkäufer):\s+'(.*?)'\s+/};
my $amazon_re = qr{\s+.*?/\s*Amazon:\s+'(.*?)'\)};
my %patterns = (
# informative only
asin => qr{ASIN(?:\s+überein)?\s+([0-9A-Za-z]+)},
shop_part_number => qr{part_number$merchant_re},
amazon_part_number => qr{part_number$amazon_re},
shop_title => qr{item_name$merchant_re},
amazon_title => qr{item_name$amazon_re},
shop_manufacturer => qr{manufacturer$merchant_re},
amazon_manufacturer => qr{manufacturer$amazon_re},
shop_brand => qr{brand$merchant_re},
amazon_brand => qr{brand$amazon_re},
shop_color => qr{color$merchant_re},
amazon_color => qr{color$amazon_re},
shop_size => qr{size$merchant_re},
amazon_size => qr{size$amazon_re},
);
return \%patterns;
}
=head1 MAIN METHODS
=head2 upload
If the products is set, begin the routine to upload them. Because of
the asynchronous way AMWS works, at some point it will bail out,
saving the state in the database. You should reinstantiate the object
and call C<resume> on it every 10 minutes or so.
The workflow is described here:
L<http://docs.developer.amazonservices.com/en_US/feeds/Feeds_Overview.html>
This has to be done for each feed: Product, Inventory, Price, Image,
Relationship (for variants).
This method first generate the feeds in the feed directory, and then
calls C<resume>, which is in charge for the actual uploading.
=head2 resume
Restore the state and resume where it was left.
This method accepts an optional list of parameters. Each parameter may be:
=over 4
=item a scalar
This is considered a job id.
=item a hashref
This will be merged in the query to retrieve the pending jobs. A
sample usage could be:
$upload->resume({ task => [qw/upload product_deletion/] });
to resume only those specific tasks.
=back
=head2 get_pending_jobs
Return the list of hashref with the pending jobs out of the database.
Accepts the same parameters as C<resume> (which actually calls this
method).
=cut
=head1 INTERNAL METHODS
=head2 prepare_feeds($type, { name => $feed_name, content => "<xml>..."}, { name => $feed_name2, content => "<xml>..."}, ....)
Prepare the feed of type $type with the feeds provided as additional
arguments.
Return the job id
=cut
sub _feed_job_dir {
my ($self, $job_id, $create) = @_;
die unless $job_id;
my $shop_id = $self->_unique_shop_id;
$shop_id =~ s/[^0-9A-Za-z_-]//g;
( run in 0.605 second using v1.01-cache-2.11-cpan-5837b0d9d2c )