Amazon-MWS
view release on metacpan or search on metacpan
lib/Amazon/MWS/Client.pm view on Meta::CPAN
=head3 merchant_id
Your Amazon Merchant ID
=head3 marketplace_id
The marketplace id for the calls being made by this object.
=head1 EXCEPTIONS
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
lib/Amazon/MWS/Client.pm view on Meta::CPAN
=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
If Amazon sends the 'Content-MD5' header and it does not match the content,
this exception will be thrown. The response can be found in $e->response.
=head1 INTERNAL METHODS
=head2 agent
The LWP::UserAgent object used to send the requests to Amazon.
=head1 API METHODS
The following methods may be called on objects of this class. All concerns
lib/Amazon/MWS/Routines.pm view on Meta::CPAN
Merchant => $self->{merchant_id},
SellerId => $self->{merchant_id},
SignatureVersion => 2,
SignatureMethod => 'HmacSHA256',
Timestamp => to_amazon('datetime', DateTime->now),
);
foreach my $name (keys %$params) {
my $param = $params->{$name};
unless (exists $args->{$name}) {
Amazon::MWS::Exception::MissingArgument->throw(name => $name) if $param->{required};
next;
}
my $type = $param->{type};
my $array_names = $param->{array_names};
my $value = $args->{$name};
if ($type =~ /^List$/) {
my %valuehash;
@valuehash{@{$param->{values}}}=();
Amazon::MWS::Exception::Invalid->throw(field => $name, value=>$value) unless (exists ($valuehash{$value}));
$form{$name} = $value;
next;
}
# Odd 'structured list' notation handled here
if ($type =~ /(\w+)List/) {
my $list_type = $1;
Amazon::MWS::Exception::Invalid->throw(field => $name, value=>$value, message=>"$name should be of type ARRAY") unless (ref $value eq 'ARRAY');
my $counter = 1;
foreach my $sub_value (@$value) {
my $listKey = "$name.$list_type." . $counter++;
$form{$listKey} = $sub_value;
}
next;
}
if ($type =~ /(\w+)Array/) {
Amazon::MWS::Exception::Invalid->throw(field => $name, value=>$value, message=>"$name should be of type ARRAY") unless (ref $value eq 'ARRAY');
my $list_type = $1;
my $counter = 0;
foreach my $sub_value (@$value) {
$counter++;
my $arr_col=0;
foreach my $array_name (@{$array_names}) {
if ( ! defined $sub_value->[$arr_col] ) { next; }
my $listKey = "$name.$list_type." . $counter;
$listKey .= ".$array_name";
$form{$listKey} = $sub_value->[$arr_col++];
lib/Amazon/MWS/Routines.pm view on Meta::CPAN
open LOG, ">>$self->{logfile}";
print LOG Dumper($response);
}
my $xs = XML::Simple->new( KeepRoot => 1 );
if ($response->code == 400 || $response->code == 403) {
my $hash = $xs->xml_in($content);
my $root = $hash->{ErrorResponse};
force_array($root, 'Error');
Amazon::MWS::Exception::Response->throw(errors => $root->{Error}, xml => $content);
}
if ($response->code == 503) {
my $hash = $xs->xml_in($content);
my $root = $hash->{ErrorResponse};
force_array($root, 'Error');
Amazon::MWS::Exception::Throttled->throw(errors => $root->{Error}, xml => $content);
}
unless ($response->is_success) {
Amazon::MWS::Exception::Transport->throw(request => $request, response => $response);
}
if (my $md5 = $response->header('Content-MD5')) {
Amazon::MWS::Exception::BedChecksum->throw(response => $response)
unless ($md5 eq md5_base64($content) . '==');
}
return $content if ($spec->{raw_body} || $args->{raw_body});
my $hash = $xs->xml_in($content);
my $root = $hash->{$method_name . 'Response'}
->{$method_name . 'Result'};
( run in 0.370 second using v1.01-cache-2.11-cpan-496ff517765 )