Skip to content

Commit

Permalink
Add Amazon Product API README
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
leesharma committed Oct 26, 2017
1 parent 72a7f8f commit 2f91a89
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ account or login locally:
By the end of this section, you should be able to search Amazon products and
add items to wishlists on your local machine (when your logged-in user is an
admin or site manager).
admin or site manager). *Note: if you're adding a new API endpoint, read more
[here][API client README].*

[API client README]: lib/amazon_product_api/README.md

**This step is only required for site managers and admins searching/adding
Amazon products.** If your issue doesn't involve working with the Amazon
Expand Down
68 changes: 68 additions & 0 deletions lib/amazon_product_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Amazon Product Advertising API Client

This folder contains the wrapper code for the Amazon Product Advertising API.
For more details on the API, check the [Amazon documentation].

[Amazon documentation]: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/Welcome.html

## Adding an Endpoint

All endpoints should be subclassed from `AmazonProductAPI::Endpoint`. In order
to add a new endpoint, you'll need to modify the template below in a few ways:

* Prepend any new attributes to the `#initialize` parameter list. Any
validations or processing can be done in `#initialize` as shown. Note:
setting `aws_credentials` is **required**!

* Add endpoint-specific request parameters to `#request_params`. These can
be found in the Amazon API documentation.

* Add any post-processing of the API response in `#process_response`.

* Update the class name and comments.

### Endpoint Template

```ruby
require 'amazon_product_api/endpoint'

module AmazonProductAPI
# Responsible for building and executing <...>
#
# <endpoint url>
#
# Contains all specialization logic for this endpoint including request
# parameters, parameter validation, and response parsing.
class TemplateEndpoint < Endpoint
# Add any parameters you need for the specific endpoint.
#
# Make sure you set `@aws_credentials`-the query won't work without it!
def initialize(aws_credentials)
# Attribute validations
# raise InvalidQueryError, 'reason' if ...

# Initialize attributes
@aws_credentials = aws_credentials
end

private

attr_accessor :aws_credentials # any other attrs

# Add any post-processing of the response hash.
def process_response(response_hash)
ExampleResponse.new(response_hash).item
end

# Include request parameters unique to this endpoint.
def request_params
{
# 'Operation' => 'ItemLookup',
# 'IdType' => 'ASIN',
# 'ItemId' => 'the item asin',
# ...
}
end
end
end
```

0 comments on commit 2f91a89

Please sign in to comment.