Search::getKeywords()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
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 1
    public function getName()
34
    {
35 1
        return 'ItemSearch';
36
    }
37
38
    /**
39
     * Return the amazon category
40
     *
41
     * @return string
42
     */
43 1
    public function getCategory()
44
    {
45 1
        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 1
    public function setCategory($category)
56
    {
57 1
        $this->parameters['SearchIndex'] = $category;
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * Returns the keywords
64
     *
65
     * @return string
66
     */
67 1
    public function getKeywords()
68
    {
69 1
        return $this->getSingleOperationParameter('Keywords');
70
    }
71
72
    /**
73
     * Sets the keywords
74
     *
75
     * @param string $keywords
76
     *
77
     * @return \ApaiIO\Operations\Search
78
     */
79 1
    public function setKeywords($keywords)
80
    {
81 1
        $this->parameters['Keywords'] = $keywords;
82
83 1
        return $this;
84
    }
85
86
    /**
87
     * Returns the sort
88
     *
89
     * @return string
90
     */
91 1
    public function getSort()
92
    {
93 1
        return $this->getSingleOperationParameter('Sort');
94
    }
95
96
    /**
97
     * Sets the sort
98
     *
99
     * @param string $sort
100
     *
101
     * @return \ApaiIO\Operations\Search
102
     */
103 1
    public function setSort($sort)
104
    {
105 1
        $this->parameters['Sort'] = $sort;
106
107 1
        return $this;
108
    }
109
110
    /**
111
     * Return the resultpage
112
     *
113
     * @return integer
114
     */
115 1
    public function getPage()
116
    {
117 1
        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 3
    public function setPage($page)
129
    {
130 3
        if (false === is_numeric($page) || $page < 1 || $page > 10) {
131 1
            throw new \InvalidArgumentException(sprintf('%s is an invalid page value. It has to be numeric, positive and between 1 and 10',
132 1
                    $page));
133
        }
134
135 2
        $this->parameters['ItemPage'] = $page;
136
137 2
        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 2
    public function getMinimumPrice()
146
    {
147 2
        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 3
    public function setMinimumPrice($price)
160
    {
161 3
        $this->validatePrice($price);
162 2
        $this->parameters['MinimumPrice'] = $price;
163
164 2
        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 2
    public function getMaximumPrice()
172
    {
173 2
        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 3
    public function setMaximumPrice($price)
186
    {
187 3
        $this->validatePrice($price);
188 2
        $this->parameters['MaximumPrice'] = $price;
189
190 2
        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 2
    public function getCondition()
199
    {
200 2
        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 2
    public function setCondition($condition)
213
    {
214 2
        $this->parameters['Condition'] = $condition;
215
216 2
        return $this;
217
    }
218
219
    /**
220
     * Returns the availability.
221
     *
222
     * @return string
223
     */
224 2
    public function getAvailability()
225
    {
226 2
        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 2
    public function setAvailability($availability)
239
    {
240 2
        $this->parameters['Availability'] = $availability;
241
242 2
        return $this;
243
    }
244
245
    /**
246
     * Returns the browseNodeId
247
     *
248
     * @return integer
249
     */
250 2
    public function getBrowseNode()
251
    {
252 2
        return $this->getSingleOperationParameter('BrowseNode');
253
    }
254
255
    /**
256
     * Sets the browseNodeId
257
     *
258
     * @param integer $browseNodeId
259
     *
260
     * @return \ApaiIO\Operations\Search
261
     */
262 2
    public function setBrowseNode($browseNodeId)
263
    {
264 2
        $this->parameters['BrowseNode'] = $browseNodeId;
265
266 2
        return $this;
267
    }
268
269
    /**
270
     * Validates the given price.
271
     *
272
     * @param integer $price
273
     */
274 6
    protected function validatePrice($price)
275
    {
276 6
        if (false === is_numeric($price) || $price < 0) {
277 2
            throw new \InvalidArgumentException(sprintf('%s is an invalid price value. It has to be numeric and >= than 0',
278 2
                    $price));
279
        }
280 4
    }
281
}
282