Skip to content

Commit 013e514

Browse files
committed
Add Amazon Product API README
Since the instructions are getting more complicated, this commit adds a README (with new endpoint instructions) to the Amazon Product API. This has three benefits: * It keeps the root README clean and relevant to most people. * It allows us to go into more documentation detail. * It facilitates an eventual extraction of the Amazon Product API lib. It might be worth extracting more from the "Getting Amazon Product Advertising API Working Locally" section into the lib README, but for now there's just endpoint information.
1 parent 32b9faa commit 013e514

File tree

2 files changed

+72
-1
lines changed

2 files changed

+72
-1
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ account or login locally:
175175
176176
By the end of this section, you should be able to search Amazon products and
177177
add items to wishlists on your local machine (when your logged-in user is an
178-
admin or site manager).
178+
admin or site manager). *Note: if you're adding a new API endpoint, read more
179+
[here][API client README].*
180+
181+
[API client README]: lib/amazon_product_api/README.md
179182

180183
**This step is only required for site managers and admins searching/adding
181184
Amazon products.** If your issue doesn't involve working with the Amazon

lib/amazon_product_api/README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Amazon Product Advertising API Client
2+
3+
This folder contains the wrapper code for the Amazon Product Advertising API.
4+
For more details on the API, check the [Amazon documentation].
5+
6+
[Amazon documentation]: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html
7+
8+
## Adding an Endpoint
9+
10+
All endpoints should be subclassed from `AmazonProductAPI::Endpoint`. In order
11+
to add a new endpoint, you'll need to modify the template below in a few ways:
12+
13+
* Prepend any new attributes to the `#initialize` parameter list. Any
14+
validations or processing can be done in `#initialize` as shown. Note:
15+
setting `aws_credentials` is **required**!
16+
17+
* Add endpoint-specific request parameters to `#request_params`. These can
18+
be found in the Amazon API documentation.
19+
20+
* Add any post-processing of the API response in `#process_response`.
21+
22+
* Update the class name and comments.
23+
24+
### Endpoint Template
25+
26+
```ruby
27+
require 'amazon_product_api/endpoint'
28+
29+
module AmazonProductAPI
30+
# Responsible for building and executing <...>
31+
#
32+
# <endpoint url>
33+
#
34+
# Contains all specialization logic for this endpoint including request
35+
# parameters, parameter validation, and response parsing.
36+
class TemplateEndpoint < Endpoint
37+
# Add any parameters you need for the specific endpoint.
38+
#
39+
# Make sure you set `@aws_credentials`-the query won't work without it!
40+
def initialize(aws_credentials)
41+
# Attribute validations
42+
# raise InvalidQueryError, 'reason' if ...
43+
44+
# Initialize attributes
45+
@aws_credentials = aws_credentials
46+
end
47+
48+
private
49+
50+
attr_accessor :aws_credentials # any other attrs
51+
52+
# Add any post-processing of the response hash.
53+
def process_response(response_hash)
54+
ExampleResponse.new(response_hash).item
55+
end
56+
57+
# Include request parameters unique to this endpoint.
58+
def request_params
59+
{
60+
# 'Operation' => 'ItemLookup',
61+
# 'IdType' => 'ASIN',
62+
# 'ItemId' => 'the item asin',
63+
# ...
64+
}
65+
end
66+
end
67+
end
68+
```

0 commit comments

Comments
 (0)