-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemLookupRequest.php
106 lines (92 loc) · 2.64 KB
/
ItemLookupRequest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/*
* This file is part of the InsigAWSBundle package.
*
* (c) Damon Jones <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Insig\AWSBundle;
use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Insig\AWSBundle\Exception as AWSException,
Insig\AWSBundle\Validator\UpcEanValidator,
Insig\AWSBundle\Validator\UpcEan
;
class ItemLookupRequest extends Request
{
/**
* Valid Response Groups
*/
private static $responseGroups = array(
'Accessories',
'BrowseNodes',
'EditorialReview',
'Images',
'ItemAttributes',
'ItemIds',
'Large',
'ListmaniaLists',
'Medium',
'MerchantItemAttributes',
'OfferFull',
'Offers',
'OfferSummary',
'Request',
'Reviews',
'SalesRank',
'Similarities',
'Small',
'Subjects',
'Tracks',
'VariationImage',
'VariationMinimum',
'Variations',
'VariationSummary'
);
public function __construct()
{
parent::__construct();
$this->setParameter('Operation', 'ItemLookup');
}
/**
* A convenience method which accepts a UPC/EAN,
* validates it and sets the ItemId, IdType
* and SearchIndex in the request query parameters
*/
public function setUPC($upc = null)
{
if (!$upc) {
throw new AWSException('UPC/EAN is required.');
}
$validator = new Validator(
new ClassMetadataFactory(new StaticMethodLoader()),
new ConstraintValidatorFactory()
);
$violations = $validator->validateValue($upc, new UpcEan);
if (count($violations)) {
throw new \InvalidArgumentException(sprintf('UPC/EAN is invalid (%s).', $upc));
}
$this->setParameter('ItemId', $upc);
$this->setParameter('IdType', 'UPC');
$this->setParameter('SearchIndex', 'DVD');
return $this;
}
/**
* A convenience method which accepts an ASIN,
* trims it and sets the ItemId and IdType
* in the request query parameters
*/
public function setASIN($asin = null)
{
if (!$asin) {
throw new AWSException('ASIN is required.');
}
$this->setParameter('ItemId', trim($asin));
$this->setParameter('IdType', 'ASIN');
return $this;
}
}