1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Copyright 2016 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 search operation |
22
|
|
|
* |
23
|
|
|
* @see http://docs.aws.amazon.com/AWSECommerceService/2011-08-01/DG/ItemSearch.html |
24
|
|
|
* @author Jan Eichhorn <[email protected]> |
25
|
|
|
* |
26
|
|
|
* @method Search setMerchantId(string $merchantId) |
27
|
|
|
*/ |
28
|
|
|
class Search extends AbstractOperation |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function getName() |
34
|
|
|
{ |
35
|
|
|
return 'ItemSearch'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Return the amazon category |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getCategory() |
44
|
|
|
{ |
45
|
|
|
return $this->getSingleOperationParameter('SearchIndex'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Sets the amazon category |
50
|
|
|
* |
51
|
|
|
* @param string $category |
52
|
|
|
* |
53
|
|
|
* @return \ApaiIO\Operations\Search |
54
|
|
|
*/ |
55
|
|
|
public function setCategory($category) |
56
|
|
|
{ |
57
|
|
|
$this->parameters['SearchIndex'] = $category; |
58
|
|
|
|
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Returns the keywords |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
public function getKeywords() |
68
|
|
|
{ |
69
|
|
|
return $this->getSingleOperationParameter('Keywords'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Sets the keywords |
74
|
|
|
* |
75
|
|
|
* @param string $keywords |
76
|
|
|
* |
77
|
|
|
* @return \ApaiIO\Operations\Search |
78
|
|
|
*/ |
79
|
|
|
public function setKeywords($keywords) |
80
|
|
|
{ |
81
|
|
|
$this->parameters['Keywords'] = $keywords; |
82
|
|
|
|
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Returns the sort |
88
|
|
|
* |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getSort() |
92
|
|
|
{ |
93
|
|
|
return $this->getSingleOperationParameter('Sort'); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Sets the sort |
98
|
|
|
* |
99
|
|
|
* @param string $sort |
100
|
|
|
* |
101
|
|
|
* @return \ApaiIO\Operations\Search |
102
|
|
|
*/ |
103
|
|
|
public function setSort($sort) |
104
|
|
|
{ |
105
|
|
|
$this->parameters['Sort'] = $sort; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return the resultpage |
112
|
|
|
* |
113
|
|
|
* @return integer |
114
|
|
|
*/ |
115
|
|
|
public function getPage() |
116
|
|
|
{ |
117
|
|
|
return $this->getSingleOperationParameter('ItemPage'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Sets the resultpage to a specified value |
122
|
|
|
* Allows to browse resultsets which have more than one page |
123
|
|
|
* |
124
|
|
|
* @param integer $page |
125
|
|
|
* |
126
|
|
|
* @return \ApaiIO\Operations\Search |
127
|
|
|
*/ |
128
|
|
|
public function setPage($page) |
129
|
|
|
{ |
130
|
|
|
if (false === is_numeric($page) || $page < 1 || $page > 10) { |
131
|
|
|
throw new \InvalidArgumentException(sprintf('%s is an invalid page value. It has to be numeric, positive and between 1 and 10', |
132
|
|
|
$page)); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$this->parameters['ItemPage'] = $page; |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Return the minimum price as integer so 8.99$ will be returned as 899 |
142
|
|
|
* |
143
|
|
|
* @return integer |
144
|
|
|
*/ |
145
|
|
|
public function getMinimumPrice() |
146
|
|
|
{ |
147
|
|
|
return $this->getSingleOperationParameter('MinimumPrice'); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Sets the minimum price to a specified value for the search |
152
|
|
|
* Currency will be given by the site you are querying: EUR for IT, USD for COM |
153
|
|
|
* Price should be given as integer. 8.99$ USD becomes 899 |
154
|
|
|
* |
155
|
|
|
* @param integer $price |
156
|
|
|
* |
157
|
|
|
* @return \ApaiIO\Operations\Search |
158
|
|
|
*/ |
159
|
|
|
public function setMinimumPrice($price) |
160
|
|
|
{ |
161
|
|
|
$this->validatePrice($price); |
162
|
|
|
$this->parameters['MinimumPrice'] = $price; |
163
|
|
|
|
164
|
|
|
return $this; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns the maximum price as integer so 8.99$ will be returned as 899 |
169
|
|
|
* @return mixed |
170
|
|
|
*/ |
171
|
|
|
public function getMaximumPrice() |
172
|
|
|
{ |
173
|
|
|
return $this->getSingleOperationParameter('MaximumPrice'); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets the maximum price to a specified value for the search |
178
|
|
|
* Currency will be given by the site you are querying: EUR for IT, USD for COM |
179
|
|
|
* Price should be given as integer. 8.99$ USD becomes 899 |
180
|
|
|
* |
181
|
|
|
* @param integer $price |
182
|
|
|
* |
183
|
|
|
* @return \ApaiIO\Operations\Search |
184
|
|
|
*/ |
185
|
|
|
public function setMaximumPrice($price) |
186
|
|
|
{ |
187
|
|
|
$this->validatePrice($price); |
188
|
|
|
$this->parameters['MaximumPrice'] = $price; |
189
|
|
|
|
190
|
|
|
return $this; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Returns the condition of the items to return. New | Used | Collectible | Refurbished | All |
195
|
|
|
* |
196
|
|
|
* @return string |
197
|
|
|
*/ |
198
|
|
|
public function getCondition() |
199
|
|
|
{ |
200
|
|
|
return $this->getSingleOperationParameter('Condition'); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Sets the condition of the items to return: New | Used | Collectible | Refurbished | All |
205
|
|
|
* |
206
|
|
|
* Defaults to New. |
207
|
|
|
* |
208
|
|
|
* @param string $condition |
209
|
|
|
* |
210
|
|
|
* @return \ApaiIO\Operations\Search |
211
|
|
|
*/ |
212
|
|
|
public function setCondition($condition) |
213
|
|
|
{ |
214
|
|
|
$this->parameters['Condition'] = $condition; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Returns the availability. |
221
|
|
|
* |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
|
|
public function getAvailability() |
225
|
|
|
{ |
226
|
|
|
return $this->getSingleOperationParameter('Availability'); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Sets the availability. Don't use method if you want the default Amazon behaviour. |
231
|
|
|
* Only valid value = Available |
232
|
|
|
* |
233
|
|
|
* @param string $availability |
234
|
|
|
* @see http://docs.aws.amazon.com/AWSECommerceService/latest/DG/CHAP_ReturningPriceAndAvailabilityInformation-itemsearch.html |
235
|
|
|
* |
236
|
|
|
* @return \ApaiIO\Operations\Search |
237
|
|
|
*/ |
238
|
|
|
public function setAvailability($availability) |
239
|
|
|
{ |
240
|
|
|
$this->parameters['Availability'] = $availability; |
241
|
|
|
|
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Returns the browseNodeId |
247
|
|
|
* |
248
|
|
|
* @return integer |
249
|
|
|
*/ |
250
|
|
|
public function getBrowseNode() |
251
|
|
|
{ |
252
|
|
|
return $this->getSingleOperationParameter('BrowseNode'); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Sets the browseNodeId |
257
|
|
|
* |
258
|
|
|
* @param integer $browseNodeId |
259
|
|
|
* |
260
|
|
|
* @return \ApaiIO\Operations\Search |
261
|
|
|
*/ |
262
|
|
|
public function setBrowseNode($browseNodeId) |
263
|
|
|
{ |
264
|
|
|
$this->parameters['BrowseNode'] = $browseNodeId; |
265
|
|
|
|
266
|
|
|
return $this; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Validates the given price. |
271
|
|
|
* |
272
|
|
|
* @param integer $price |
273
|
|
|
*/ |
274
|
|
|
protected function validatePrice($price) |
275
|
|
|
{ |
276
|
|
|
if (false === is_numeric($price) || $price < 1) { |
277
|
|
|
throw new \InvalidArgumentException(sprintf('%s is an invalid price value. It has to be numeric and >= than 1', |
278
|
|
|
$price)); |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
} |
282
|
|
|
|