Skip to content

Commit 69ec5b6

Browse files
author
Marc Littlemore
committed
Tidy up README + code
1 parent 2d277b5 commit 69ec5b6

File tree

2 files changed

+72
-16
lines changed

2 files changed

+72
-16
lines changed

AmazonAPI.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,45 @@ class AmazonAPI
3838

3939
// Valid names that can be used for search
4040
private $mValidSearchNames = array(
41-
'All','Apparel','Appliances','Automotive','Baby','Beauty','Blended','Books','Classical','DVD','Electronics','Grocery','HealthPersonalCare','HomeGarden','HomeImprovement','Jewelry','KindleStore','Kitchen','Lighting','Marketplace','MP3Downloads','Music','MusicTracks','MusicalInstruments','OfficeProducts','OutdoorLiving','Outlet','PetSupplies','PCHardware','Shoes','Software','SoftwareVideoGames','SportingGoods','Tools','Toys','VHS','Video','VideoGames','Watches',
41+
'All',
42+
'Apparel',
43+
'Appliances',
44+
'Automotive',
45+
'Baby',
46+
'Beauty',
47+
'Blended',
48+
'Books',
49+
'Classical',
50+
'DVD',
51+
'Electronics',
52+
'Grocery',
53+
'HealthPersonalCare',
54+
'HomeGarden',
55+
'HomeImprovement',
56+
'Jewelry',
57+
'KindleStore',
58+
'Kitchen',
59+
'Lighting',
60+
'Marketplace',
61+
'MP3Downloads',
62+
'Music',
63+
'MusicTracks',
64+
'MusicalInstruments',
65+
'OfficeProducts',
66+
'OutdoorLiving',
67+
'Outlet',
68+
'PetSupplies',
69+
'PCHardware',
70+
'Shoes',
71+
'Software',
72+
'SoftwareVideoGames',
73+
'SportingGoods',
74+
'Tools',
75+
'Toys',
76+
'VHS',
77+
'Video',
78+
'VideoGames',
79+
'Watches'
4280
);
4381

4482
private $mErrors = array();

README.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ It supports all Amazon regions:
4444
* United Kingdom ('uk')
4545
* United States ('us').
4646

47-
The default is UK but to set the locale call SetLocale __before__ calling the product methods. E.g.
47+
The default is UK but to set the locale call `SetLocale()` __before__ calling the product methods. E.g.
4848

4949
```php
5050
$amazonAPI->SetLocale('us');
@@ -62,14 +62,26 @@ $amazonAPI->SetSSL(false);
6262
To search for an item use the ItemSearch method:
6363

6464
```php
65-
// Search for Harry Potter items in all categories
66-
$items = $amazonAPI->ItemSearch( 'harry potter' );
65+
// Search for harry potter items in all categories
66+
$items = $amazonAPI->ItemSearch('harry potter');
6767

68-
// Search for Harry Potter items in Books category only
69-
$items = $amazonAPI->ItemSearch( 'harry potter', 'Books' );
68+
// Search for harry potter items in Books category only
69+
$items = $amazonAPI->ItemSearch('harry potter', 'Books');
7070
```
7171

72-
To determine valid categories for search call GetValidSearchNames() :
72+
#### Default sort
73+
74+
By default, the `ItemSearch` method will search by featured. If you want to sort by another category then pass a 3rd parameter with the name of the category you wish to sort by. These differ by category type but the two you'll probably need are `price` (sort by price low to high) or `-price` (sort by price high to low). See [ItemSearch Sort Values](http://docs.aws.amazon.com/AWSECommerceService/latest/DG/APPNDX_SortValuesArticle.html) for more details.
75+
76+
```php
77+
// Search for harry potter items in Books category, sort by low to high
78+
$items = $amazonAPI->ItemSearch('harry potter', 'Books', 'price');
79+
80+
// Search for harry potter items in Books category, sort by high to low
81+
$items = $amazonAPI->ItemSearch('harry potter', 'Books', '-price');
82+
```
83+
84+
To determine valid categories for search call `GetValidSearchNames()`:
7385

7486
```php
7587
// Get an array of valid search categories we can use
@@ -81,21 +93,21 @@ To look up product using the product ASIN number use ItemLookup:
8193

8294
```php
8395
// Retrieve specific item by id
84-
$items = $amazonAPI->ItemLookUp( 'B003U6I396' );
96+
$items = $amazonAPI->ItemLookUp('B003U6I396');
8597

8698
// Retrieve a list of items by ids
87-
$asinIds = array( 'B003U6I396', 'B003U6I397', 'B003U6I398' );
88-
$items = $amazonAPI->ItemLookUp( $asinIds );
99+
$asinIds = array('B003U6I396', 'B003U6I397', 'B003U6I398');
100+
$items = $amazonAPI->ItemLookUp($asinIds);
89101
```
90102

91103
## Returned data
92104
By default the data will be returned as SimpleXML nodes. However if you call `SetRetrieveAsArray()` then a simplified array of items will be returned. For example:
93105

94106
```php
95107
// Return XML data
96-
$amazonAPI = new AmazonAPI( $keyId, $secretKey, $associateId );
97-
$items = $amazonAPI->ItemSearch( 'harry potter' );
98-
var_dump( $items );
108+
$amazonAPI = new AmazonAPI($keyId, $secretKey, $associateId);
109+
$items = $amazonAPI->ItemSearch('harry potter');
110+
var_dump($items);
99111
```
100112

101113
This will output:
@@ -115,10 +127,10 @@ class SimpleXMLElement#2 (2) {
115127
116128
```php
117129
// Return simplified data
118-
$amazonAPI = new AmazonAPI( $keyId, $secretKey, $associateId );
130+
$amazonAPI = new AmazonAPI($keyId, $secretKey, $associateId);
119131
$amazonAPI->SetRetrieveAsArray();
120-
$items = $amazonAPI->ItemSearch( 'harry potter' );
121-
var_dump( $items );
132+
$items = $amazonAPI->ItemSearch('harry potter');
133+
var_dump($items);
122134
```
123135
124136
Returning simplified data gives a PHP array
@@ -158,9 +170,15 @@ array(10) {
158170
```
159171
160172
## TODO
173+
161174
* Need to make the simplified data less hardcoded!
162175
* Make this a Composer package
163176
* Add unit tests
164177
165178
## Thanks
179+
166180
This library uses code based on [AWS API authentication For PHP](http://randomdrake.com/2009/07/27/amazon-aws-api-rest-authentication-for-php-5/) by [David Drake](https://github.com/randomdrake).
181+
182+
## LICENSE
183+
184+
See [LICENSE](LICENSE)

0 commit comments

Comments
 (0)