|
| 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