|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright 2013 Jan Eichhorn <[email protected]> |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ApaiIO\Operations; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* A item lookup operation |
|
22
|
|
|
* |
|
23
|
|
|
* @see http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/ItemLookup.html |
|
24
|
|
|
* @author Jan Eichhorn <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class Lookup extends AbstractOperation |
|
27
|
|
|
{ |
|
28
|
|
|
const TYPE_ASIN = 'ASIN'; |
|
29
|
|
|
const TYPE_SKU = 'SKU'; |
|
30
|
|
|
const TYPE_UPC = 'UPC'; |
|
31
|
|
|
const TYPE_EAN = 'EAN'; |
|
32
|
|
|
const TYPE_ISBN = 'ISBN'; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritdoc} |
|
36
|
|
|
*/ |
|
37
|
1 |
|
public function getName() |
|
38
|
|
|
{ |
|
39
|
1 |
|
return 'ItemLookup'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Pass up to 10 itemid's which should be looked up |
|
44
|
|
|
* |
|
45
|
|
|
* @param array $itemIds |
|
46
|
|
|
* |
|
47
|
|
|
* @return \ApaiIO\Operations\Lookup |
|
48
|
|
|
*/ |
|
49
|
2 |
|
public function setItemIds(array $itemIds) |
|
50
|
|
|
{ |
|
51
|
2 |
|
if (count($itemIds) > 10) { |
|
52
|
1 |
|
throw new \Exception('setItemIds accepts not more then 10 itemid\'s at once'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
$asinString = implode(',', $itemIds); |
|
56
|
1 |
|
$this->setItemId($asinString); |
|
57
|
|
|
|
|
58
|
1 |
|
return $this; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Returns the itemid |
|
63
|
|
|
* |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
2 |
|
public function getItemId() |
|
67
|
|
|
{ |
|
68
|
2 |
|
return $this->getSingleOperationParameter('ItemId'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Sets the itemid which should be looked up |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $itemId |
|
75
|
|
|
* |
|
76
|
|
|
* @return \ApaiIO\Operations\Lookup |
|
77
|
|
|
*/ |
|
78
|
3 |
|
public function setItemId($itemId) |
|
79
|
|
|
{ |
|
80
|
3 |
|
$this->parameter['ItemId'] = $itemId; |
|
81
|
|
|
|
|
82
|
3 |
|
return $this; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Returns the idtype either ASIN (Default), SKU, UPC, EAN, and ISBN |
|
87
|
|
|
* |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
1 |
|
public function getIdType() |
|
91
|
|
|
{ |
|
92
|
1 |
|
return $this->getSingleOperationParameter('IdType'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Sets the idtype either ASIN (Default), SKU, UPC, EAN, and ISBN |
|
97
|
|
|
* |
|
98
|
|
|
* @param string $idType |
|
99
|
|
|
* |
|
100
|
|
|
* @return \ApaiIO\Operations\Lookup |
|
101
|
|
|
*/ |
|
102
|
7 |
|
public function setIdType($idType) |
|
103
|
|
|
{ |
|
104
|
|
|
$idTypes = array( |
|
105
|
7 |
|
self::TYPE_ASIN, |
|
106
|
7 |
|
self::TYPE_SKU, |
|
107
|
7 |
|
self::TYPE_UPC, |
|
108
|
7 |
|
self::TYPE_EAN, |
|
109
|
|
|
self::TYPE_ISBN |
|
110
|
7 |
|
); |
|
111
|
|
|
|
|
112
|
7 |
|
if (!in_array($idType, $idTypes)) { |
|
113
|
1 |
|
throw new \InvalidArgumentException(sprintf( |
|
114
|
1 |
|
"Invalid type '%s' passed. Valid types are: '%s'", |
|
115
|
1 |
|
$idType, |
|
116
|
1 |
|
implode(', ', $idTypes) |
|
117
|
1 |
|
)); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
6 |
|
$this->parameter['IdType'] = $idType; |
|
121
|
|
|
|
|
122
|
6 |
|
if (empty($this->parameter['SearchIndex']) && $idType != self::TYPE_ASIN) { |
|
123
|
5 |
|
$this->parameter['SearchIndex'] = 'All'; |
|
124
|
5 |
|
} |
|
125
|
|
|
|
|
126
|
6 |
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Returns the searchindex |
|
131
|
|
|
* |
|
132
|
|
|
* @return mixed |
|
133
|
|
|
*/ |
|
134
|
1 |
|
public function getSearchIndex() |
|
135
|
|
|
{ |
|
136
|
1 |
|
return $this->getSingleOperationParameter('SearchIndex'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Sets the searchindex which should be used when set IdType other than ASIN |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $searchIndex |
|
143
|
|
|
* |
|
144
|
|
|
* @return \ApaiIO\Operations\Lookup |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function setSearchIndex($searchIndex) |
|
147
|
|
|
{ |
|
148
|
1 |
|
$this->parameter['SearchIndex'] = $searchIndex; |
|
149
|
|
|
|
|
150
|
1 |
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* Returns the condition of the items to return. New | Used | Collectible | Refurbished | All |
|
155
|
|
|
* |
|
156
|
|
|
* @return string |
|
157
|
|
|
*/ |
|
158
|
2 |
|
public function getCondition() |
|
159
|
|
|
{ |
|
160
|
2 |
|
return $this->getSingleOperationParameter('Condition'); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Sets the condition of the items to return: New | Used | Collectible | Refurbished | All |
|
165
|
|
|
* |
|
166
|
|
|
* Defaults to New. |
|
167
|
|
|
* |
|
168
|
|
|
* @param string $condition |
|
169
|
|
|
* |
|
170
|
|
|
* @return \ApaiIO\Operations\Search |
|
171
|
|
|
*/ |
|
172
|
2 |
|
public function setCondition($condition) |
|
173
|
|
|
{ |
|
174
|
2 |
|
$this->parameter['Condition'] = $condition; |
|
175
|
|
|
|
|
176
|
2 |
|
return $this; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|