Amazon-MWS

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.130 Sat Apr  2 08:08:26 2016 CEST

     [ENHANCEMENTS]

     * Add method to retrieve skus with warnings (Marco Pessotto).
     * Add color and size mismatches, also handle errors in German
       (Marco Pessotto).

     [BUG FIXES]

     * Strip trailing slash from endpoint
       (Marco Pessotto, jordanmhiller, GH #9).

     [DOCUMENTATION]

     * Add possible explanation for error code 8572 (Stefan Hornburg/Racke).

0.120 Tue Mar 29 07:35:46 2016 CEST

     [ENHANCEMENTS]

lib/Amazon/MWS/Client.pm  view on Meta::CPAN


=head3 application

The name of your application.  Defaults to 'Amazon::MWS::Client'

=head3 version

The version of your application.  Defaults to the current version of this
module.

=head3 endpoint

Where MWS lives.  Defaults to 'https://mws.amazonaws.com'.

=head3 access_key_id

Your AWS Access Key Id

=head3 secret_key

Your AWS Secret Access Key

lib/Amazon/MWS/Client.pm  view on Meta::CPAN

Any of the L<API METHODS> can throw the following exceptions
(Exception::Class).  They are all subclasses of Amazon::MWS::Exception.

=head2 Amazon::MWS::Exception::MissingArgument

The call to the API method was missing a required argument.  The name of the
missing argument can be found in $e->name.

=head2 Amazon::MWS::Exception::Transport

There was an error communicating with the Amazon endpoint.  The HTTP::Request
and Response objects can be found in $e->request and $e->response.

=head2 Amazon::MWS::Exception::Response

Amazon returned an response, but indicated an error.  An arrayref of hashrefs
corresponding to the error xml (via XML::Simple on the Error elements) is
available at $e->errors, and the entire xml response is available at $e->xml.

=head2 Amazon::MWS::Exception::BadChecksum

lib/Amazon/MWS/Routines.pm  view on Meta::CPAN

            if ($type eq 'HTTP-BODY') {
                $body = $value;
            }
            else {
                $form{$name} = to_amazon($type, $value);
            }
        }

	$form{Version} = $spec->{version} || '2010-01-01';

	my $endpoint = ( $spec->{service} ) ? "$self->{endpoint}$spec->{service}" : $self->{endpoint};

        my $uri = URI->new($endpoint);

        my $request = HTTP::Request->new;
	   $request->protocol('HTTP/1.0');

        my ($response, $content);

	$spec->{method} = 'GET' unless $spec->{method};

        if ($spec->{method} eq 'POST') {
            $request->uri($uri);

lib/Amazon/MWS/Routines.pm  view on Meta::CPAN

 $opts{configfile} ||= 'amazon.xml';

  if (-r $opts{configfile} ) {

    my $xmlconfig = XML::Simple::XMLin("$opts{configfile}");

    $opts{access_key_id} ||= $xmlconfig->{access_key_id};
    $opts{secret_key} ||= $xmlconfig->{secret_key};
    $opts{merchant_id} ||= $xmlconfig->{merchant_id};
    $opts{marketplace_id} ||= $xmlconfig->{marketplace_id};
    $opts{endpoint} ||= $xmlconfig->{endpoint};
    $opts{debug} ||= $xmlconfig->{debug};
    $opts{logfile} ||= $xmlconfig->{logfile};
 }

 my $attr = $opts->{agent_attributes};
    $attr->{Language} = 'Perl';

    my $attr_str = join ';', map { "$_=$attr->{$_}" } keys %$attr;
    my $appname  = $opts{Application} || 'Amazon::MWS::Client';
    my $version  = $opts{Version}     || 0.5;

lib/Amazon/MWS/Routines.pm  view on Meta::CPAN


    if ($opts{debug}) {
       open LOG, ">$opts{logfile}" or die "Cannot open logfile.";
       print LOG DateTime->now();
       print LOG "\nNew instance created. \n";
       print LOG Dumper(\%opts);
       close LOG; 
    }

 # https://github.com/interchange/Amazon-MWS/issues/9
 $opts{endpoint} ||= 'https://mws.amazonaws.com';
 # strip the trailing slashes
 $opts{endpoint} =~ s/\/+\z//;

  bless {
    package => "$pkg",
    agent => LWP::UserAgent->new(agent => $agent_string),
    endpoint => $opts{endpoint},
    access_key_id => $opts{access_key_id},
    secret_key => $opts{secret_key},
    merchant_id => $opts{merchant_id},
    marketplace_id => $opts{marketplace_id}, 
    debug => $opts{debug}, 
    logfile => $opts{logfile},
	}, $pkg;

}

lib/Amazon/MWS/Uploader.pm  view on Meta::CPAN

                                         # 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;

lib/Amazon/MWS/Uploader.pm  view on Meta::CPAN

Provided by Amazon.

=item secret_key

Provided by Amazon.

=item marketplace_id

L<http://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html>

=item endpoint

Ditto.

=cut

has merchant_id => (is => 'ro', required => 1);
has access_key_id => (is => 'ro', required => 1);
has secret_key => (is => 'ro', required => 1);
has marketplace_id => (is => 'ro', required => 1);
has endpoint => (is => 'ro', required => 1);

=item products

An arrayref of L<Amazon::MWS::XML::Product> objects, or anything that
(properly) responds to C<as_product_hash>, C<as_inventory_hash>,
C<as_price_hash>. See L<Amazon::MWS::XML::Product> for details.

B<This is set as read-write, so you can set the product after the
object construction, but if you change it afterward, you will get
unexpected results>.

lib/Amazon/MWS/Uploader.pm  view on Meta::CPAN

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+'(.*?)'\)};

lib/Amazon/MWS/amazon.xml  view on Meta::CPAN

<amazon>
	<access_key_id>ACCESS KET HERE</access_key_id>
        <secret_key>SECRET KEY HERE</secret_key>
        <merchant_id>MERCHANT ID HERE</merchant_id>
        <marketplace_id>HOME MARKETPLACE HERE</marketplace_id>
        <endpoint>ENDPOINT HERE </endpoint>
	<debug>0</debug>
	<logfile>LOG FILE PATH HERE</logfile>
</amazon>

t/error-parsing.t  view on Meta::CPAN

use warnings;
use Amazon::MWS::Uploader;
use Data::Dumper;
use Test::More;

my %constructor = (
                   merchant_id => '__MERCHANT_ID__',
                   access_key_id => '12341234',
                   secret_key => '123412341234',
                   marketplace_id => '123412341234',
                   endpoint => 'https://mws-eu.amazonservices.com',
                   feed_dir => 't/feeds',
                   schema_dir => 'schemas',
                  );

plan skip_all => "Missing schema and feed dirs"
  unless (-d $constructor{schema_dir} && -d $constructor{feed_dir});

my $uploader = Amazon::MWS::Uploader->new(%constructor);

my $error_msg = q{upload-2016-03-14-19-07-09 8541 The SKU data provided conflicts with the Amazon catalog. The standard_product_id value(s) provided correspond to the ASIN  XXXXXX, but some information contradicts with the Amazon catalog. The followi...

t/job-selection.t  view on Meta::CPAN

unless (-d $feed_dir) {
    mkdir $feed_dir or die "Cannot create $feed_dir $!";
}

my %constructor = (
                   merchant_id => '__MERCHANT_ID__',
                   shop_id => 'shoppe',
                   access_key_id => '12341234',
                   secret_key => '123412341234',
                   marketplace_id => '123412341234',
                   endpoint => 'https://mws-eu.amazonservices.com',
                   feed_dir => $feed_dir,
                   schema_dir => 'schemas',
                   db_dsn => 'dbi:SQLite:dbname=t/test.db',
                   db_username => '',
                   db_password => '',
                  );



my $uploader = Amazon::MWS::Uploader->new(%constructor);

t/order-reports.t  view on Meta::CPAN

                                                               Title => 'bac');
is $test_obj->Title, 'bac';



my %constructor = (
                   merchant_id => '__MERCHANT_ID__',
                   access_key_id => '12341234',
                   secret_key => '123412341234',
                   marketplace_id => '123412341234',
                   endpoint => 'https://mws-eu.amazonservices.com',
                   schema_dir => 'schemas',
                   feed_dir => File::Spec->catdir(qw/t feeds/),
                  );
my $uploader = Amazon::MWS::Uploader->new(%constructor);

ok($uploader);

my $xml = <<'AMAZONXML';
<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">
  <Header>

t/product-filtering.t  view on Meta::CPAN

my @products = (Amazon::MWS::XML::Product->new(sku => '1234',
                                               price => '10',
                                               ean => '4444123412343',
                                              ));

my %constructor = (
                   merchant_id => '__MERCHANT_ID__',
                   access_key_id => '12341234',
                   secret_key => '123412341234',
                   marketplace_id => '123412341234',
                   endpoint => 'https://mws-eu.amazonservices.com',
                   feed_dir => 't/feeds',
                   schema_dir => 'schemas',
                   existing_products => $existing_products,
                   products => \@products,
                   debug => 1,
                  );

my $uploader = Amazon::MWS::Uploader->new(%constructor);
ok($uploader, "object created");

t/shipping-confirmation.t  view on Meta::CPAN


exit unless $test_extended;

my $feed_dir = 't/feeds';

my $uploader = Amazon::MWS::Uploader->new(
                                          merchant_id => 'My Store',
                                          access_key_id => '12341234',
                                          secret_key => '123412341234',
                                          marketplace_id => '123412341234',
                                          endpoint => 'https://mws-eu.amazonservices.com',
                                          feed_dir => $feed_dir,
                                          schema_dir => $schema_dir,
                                          );
ok($uploader, "Uploader ok");

my $feed = $uploader->shipping_confirmation_feed($shipped_order);
ok($feed, "Can create the feed and validates against the schema"); # and diag $feed;

# test against the example provided in the documentation

t/uploader.t  view on Meta::CPAN


unless (-d $feed_dir) {
    mkdir $feed_dir or die "Cannot create $feed_dir $!";
}

my %constructor = (
                   merchant_id => '__MERCHANT_ID__',
                   access_key_id => '12341234',
                   secret_key => '123412341234',
                   marketplace_id => '123412341234',
                   endpoint => 'https://mws-eu.amazonservices.com',
                   feed_dir => $feed_dir,
                   schema_dir => 'schemas',
                  );

my $uploader = Amazon::MWS::Uploader->new(%constructor);

ok($uploader);
ok($uploader->client->can('agent'), "Client can call agent");
ok($uploader->client->agent->isa('LWP::UserAgent'));
ok($uploader->schema, "schema built");



( run in 0.366 second using v1.01-cache-2.11-cpan-27979f6cc8f )