Add client, request and response classes

This commit is contained in:
Dan Milne
2019-09-03 12:57:43 +10:00
commit f816ad4fb1
17 changed files with 514 additions and 0 deletions

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

7
.travis.yml Normal file
View File

@@ -0,0 +1,7 @@
---
sudo: false
language: ruby
cache: bundler
rvm:
- 2.6.3
before_install: gem install bundler -v 2.0.2

4
Gemfile Normal file
View File

@@ -0,0 +1,4 @@
source "https://rubygems.org"
# Specify your gem's dependencies in aws_paa.gemspec
gemspec

40
Gemfile.lock Normal file
View File

@@ -0,0 +1,40 @@
PATH
remote: .
specs:
aws_paa (0.1.0)
rest-client (~> 2.0)
GEM
remote: https://rubygems.org/
specs:
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
http-accept (1.7.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
minitest (5.11.3)
netrc (0.11.0)
rake (10.5.0)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
PLATFORMS
ruby
DEPENDENCIES
aws_paa!
bundler (~> 2.0)
minitest (~> 5.0)
rake (~> 10.0)
BUNDLED WITH
2.0.2

21
LICENSE.txt Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2019 Dan Milne
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

39
README.md Normal file
View File

@@ -0,0 +1,39 @@
# AwsPaa
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aws_paa`. To experiment with that code, run `bin/console` for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'aws_paa'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install aws_paa
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_paa.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

10
Rakefile Normal file
View File

@@ -0,0 +1,10 @@
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task :default => :test

35
aws_paa.gemspec Normal file
View File

@@ -0,0 +1,35 @@
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "aws_paa/version"
Gem::Specification.new do |spec|
spec.name = "aws_paa"
spec.version = AwsPaa::VERSION
spec.authors = ["Dan Milne"]
spec.email = ["d@nmilne.com"]
spec.summary = %q{Ruby API for Amazon's Product Advertising API v5}
spec.homepage = "https://github.com/dkam/aws_paa"
spec.license = "MIT"
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 2.0"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_dependency 'httprb', '~> 0.1'
end

14
bin/console Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
require "bundler/setup"
require "aws_paa"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "irb"
IRB.start(__FILE__)

8
bin/setup Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx
bundle install
# Do any other automated setup that you need to do here

11
lib/aws_paa.rb Normal file
View File

@@ -0,0 +1,11 @@
require "aws_paa/version"
require 'aws_paa/client'
require 'aws_paa/request'
require 'aws_paa/response'
module AwsPaa
class Error < StandardError; end
class NotImplemented < StandardError; end
# Your code goes here...
end

8
lib/aws_paa/client.rb Normal file
View File

@@ -0,0 +1,8 @@
require 'rest-client'
module AwsPaa
class Client
def initialize(:access_key, :secret_key, :marketplace, partner_tag: nil, partner_type: 'Associates')
end
end
end

43
lib/aws_paa/request.rb Normal file
View File

@@ -0,0 +1,43 @@
module AwsPaa
class Request
def initialize()
@request_example = {
"Keywords": "Harry",
"Marketplace": "www.amazon.com",
"PartnerTag": "xyz-20",
"PartnerType": "Associates",
"Resources": ["Images.Primary.Small","ItemInfo.Title","Offers.Listings.Price"],
"SearchIndex": "All"
}
@headers = {
'host' => 'webservices.amazon.com',
'content-type' => 'application/json; charset=utf-8',
'content-encoding' => 'amz-1.0',
'x-amz-date' => '20160925T120000Z',
'x-amz-target' => 'com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems',
'Authorization' => 'AWS4-HMAC-SHA256 Credential=AKIAIOSFODNN7EXAMPLE, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=&5d672d79c15b13162d9279b0855cfba6789a8edb4c82c400e06b5924a6f2b5d7;'
}
@marketplaces = [www.amazon.com]
end
def get_browse_nodes
raise NotImplemented
end
def get_items
raise NotImplemented
end
def get_variations
raise NotImplemented
end
def search_items
raise NotImplemented
end
end
end

6
lib/aws_paa/response.rb Normal file
View File

@@ -0,0 +1,6 @@
require 'json'
module AwsPaa
class Response
end
end

3
lib/aws_paa/version.rb Normal file
View File

@@ -0,0 +1,3 @@
module AwsPaa
VERSION = "0.1.0"
end

253
test/aws_paa_test.rb Normal file
View File

@@ -0,0 +1,253 @@
require "test_helper"
class AwsPaaTest < Minitest::Test
def test_that_it_has_a_version_number
refute_nil ::AwsPaa::VERSION
end
def test_it_does_something_useful
assert false
end
def test_json_payload_generation
payload = {
"Keywords": "9781473619814",
"Resources": [
"Images.Primary.Large",
"ItemInfo.ByLineInfo",
"ItemInfo.ContentInfo",
"ItemInfo.ContentRating",
"ItemInfo.Classifications",
"ItemInfo.ExternalIds",
"ItemInfo.Features",
"ItemInfo.ManufactureInfo",
"ItemInfo.ProductInfo",
"ItemInfo.TechnicalInfo",
"ItemInfo.Title",
"ItemInfo.TradeInInfo",
"Offers.Listings.Availability.MaxOrderQuantity",
"Offers.Listings.Availability.Message",
"Offers.Listings.Availability.MinOrderQuantity",
"Offers.Listings.Availability.Type",
"Offers.Listings.Condition",
"Offers.Listings.Condition.SubCondition",
"Offers.Listings.DeliveryInfo.IsAmazonFulfilled",
"Offers.Listings.DeliveryInfo.IsFreeShippingEligible",
"Offers.Listings.DeliveryInfo.IsPrimeEligible",
"Offers.Listings.DeliveryInfo.ShippingCharges",
"Offers.Listings.IsBuyBoxWinner",
"Offers.Listings.LoyaltyPoints.Points",
"Offers.Listings.MerchantInfo",
"Offers.Listings.Price",
"Offers.Listings.ProgramEligibility.IsPrimeExclusive",
"Offers.Listings.ProgramEligibility.IsPrimePantry",
"Offers.Listings.Promotions",
"Offers.Listings.SavingBasis",
"Offers.Summaries.HighestPrice",
"Offers.Summaries.LowestPrice",
"Offers.Summaries.OfferCount"
],
"PartnerTag": "booko01-22",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com.au",
"Operation": "SearchItems"
}
headers = %q{Host: webservices.amazon.com.au
X-Amz-Date: 20190903T014126Z
X-Amz-Target: com.amazon.paapi5.v1.ProductAdvertisingAPIv1.SearchItems
Content-Encoding: amz-1.0}
request = %q{https://webservices.amazon.com.au/!YW16LTEuMDtjb20uYW1hem9uLnBhYXBpNS52MS5Qcm9kdWN0QWR2ZXJ0aXNpbmdBUEl2MS5TZWFyY2hJdGVtczt7CiAgICAiS2V5d29yZHMiOiAiOTc4MTQ3MzYxOTgxNCIsCiAgICAiUmVzb3VyY2VzIjogWwogICAgICAgICJJbWFnZXMuUHJpbWFyeS5MYXJnZSIsCiAgICAgICAgIkl0ZW1JbmZvLkJ5TGluZUluZm8iLAogICAgICAgICJJdGVtSW5mby5Db250ZW50SW5mbyIsCiAgICAgICAgIkl0ZW1JbmZvLkNvbnRlbnRSYXRpbmciLAogICAgICAgICJJdGVtSW5mby5DbGFzc2lmaWNhdGlvbnMiLAogICAgICAgICJJdGVtSW5mby5FeHRlcm5hbElkcyIsCiAgICAgICAgIkl0ZW1JbmZvLkZ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ICAgICAgIk9mZmVycy5MaXN0aW5ncy5QcmljZSIsCiAgICAgICAgIk9mZmVycy5MaXN0aW5ncy5Qcm9ncmFtRWxpZ2liaWxpdHkuSXNQcmltZUV4Y2x1c2l2ZSIsCiAgICAgICAgIk9mZmVycy5MaXN0aW5ncy5Qcm9ncmFtRWxpZ2liaWxpdHkuSXNQcmltZVBhbnRyeSIsCiAgICAgICAgIk9mZmVycy5MaXN0aW5ncy5Qcm9tb3Rpb25zIiwKICAgICAgICAiT2ZmZXJzLkxpc3RpbmdzLlNhdmluZ0Jhc2lzIiwKICAgICAgICAiT2ZmZXJzLlN1bW1hcmllcy5IaWdoZXN0UHJpY2UiLAogICAgICAgICJPZmZlcnMuU3VtbWFyaWVzLkxvd2VzdFByaWNlIiwKICAgICAgICAiT2ZmZXJzLlN1bW1hcmllcy5PZmZlckNvdW50IgogICAgXSwKICAgICJQYXJ0bmVyVGFnIjogImJvb2tvMDEtMjIiLAogICAgIlBhcnRuZXJUeXBlIjogIkFzc29jaWF0ZXMiLAogICAgIk1hcmtldHBsYWNlIjogInd3dy5hbWF6b24uY29tLmF1Igp9}
response = {
"SearchResult": {
"Items": [
{
"ASIN": "1473619815",
"DetailPageURL": "https://www.amazon.com.au/dp/1473619815?tag=booko01-22&linkCode=osi&th=1&psc=1",
"Images": {
"Primary": {
"Large": {
"Height": 500,
"URL": "https://m.media-amazon.com/images/I/51HoUcxVnFL.jpg",
"Width": 325
}
}
},
"ItemInfo": {
"ByLineInfo": {
"Contributors": [
{
"Locale": "en_AU",
"Name": "Chambers, Becky",
"Role": "Author"
}
],
"Manufacturer": {
"DisplayValue": "Hodder Paperbacks",
"Label": "Manufacturer",
"Locale": "en_AU"
}
},
"Classifications": {
"Binding": {
"DisplayValue": "Paperback",
"Label": "Binding",
"Locale": "en_AU"
},
"ProductGroup": {
"DisplayValue": "Book",
"Label": "ProductGroup",
"Locale": "en_AU"
}
},
"ContentInfo": {
"Edition": {
"DisplayValue": "1",
"Label": "Edition",
"Locale": "en_AU"
},
"Languages": {
"DisplayValues": [
{
"DisplayValue": "English",
"Type": "Published"
},
{
"DisplayValue": "English",
"Type": "Original Language"
},
{
"DisplayValue": "English",
"Type": "Unknown"
}
],
"Label": "Language",
"Locale": "en_AU"
},
"PagesCount": {
"DisplayValue": 432,
"Label": "NumberOfPages",
"Locale": "en_US"
},
"PublicationDate": {
"DisplayValue": "2016-03-08T00:00:01Z",
"Label": "PublicationDate",
"Locale": "en_US"
}
},
"ExternalIds": {
"EANs": {
"DisplayValues": [
"9781473619814"
],
"Label": "EAN",
"Locale": "en_US"
},
"ISBNs": {
"DisplayValues": [
"1473619815"
],
"Label": "ISBN",
"Locale": "en_US"
}
},
"ManufactureInfo": {
"ItemPartNumber": {
"DisplayValue": "23025256",
"Label": "PartNumber",
"Locale": "en_US"
}
},
"ProductInfo": {
"ItemDimensions": {
"Weight": {
"DisplayValue": 471,
"Label": "Weight",
"Locale": "en_AU",
"Unit": "Grams"
}
},
"ReleaseDate": {
"DisplayValue": "2016-03-08T00:00:01Z",
"Label": "ReleaseDate",
"Locale": "en_US"
},
"UnitCount": {
"DisplayValue": 1,
"Label": "NumberOfItems",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "The Long Way to a Small, Angry Planet: Wayfarers 1",
"Label": "Title",
"Locale": "en_AU"
}
},
"Offers": {
"Listings": [
{
"Availability": {
"MaxOrderQuantity": 20,
"Message": "In stock.",
"MinOrderQuantity": 1,
"Type": "Now"
},
"Condition": {
"SubCondition": {
"Value": "New"
},
"Value": "New"
},
"DeliveryInfo": {
"IsAmazonFulfilled": true,
"IsFreeShippingEligible": true,
"IsPrimeEligible": true
},
"Id": "1UP5v2BpBF5QeBZF7Dge7V%2BN3pdmW4ZkvT%2BvE4GABbmz4koGqDSZFDZwQj5o95bZrvKmWdqZPW0SiDhCIOjyAKlRmsz4hYXtSkQLSlwCc77AiiAbX1ja0CBjRVVdgLJ6",
"IsBuyBoxWinner": true,
"MerchantInfo": {
"Id": "ANEGB3WVEVKZB",
"Name": "Amazon AU"
},
"Price": {
"Amount": 16.41,
"Currency": "AUD",
"DisplayAmount": "$16.41"
},
"ProgramEligibility": {
"IsPrimeExclusive": false,
"IsPrimePantry": false
},
"ViolatesMAP": false
}
],
"Summaries": [
{
"Condition": {
"Value": "New"
},
"HighestPrice": {
"Amount": 49.31,
"Currency": "AUD",
"DisplayAmount": "$49.31"
},
"LowestPrice": {
"Amount": 15.46,
"Currency": "AUD",
"DisplayAmount": "$15.46"
},
"OfferCount": 18
}
]
}
}
],
"SearchURL": "https://www.amazon.com.au/s?k=9781473619814&rh=p_n_availability%3A-1&tag=booko01-22&linkCode=osi",
"TotalResultCount": 1
}
}
end
end

4
test/test_helper.rb Normal file
View File

@@ -0,0 +1,4 @@
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "aws_paa"
require "minitest/autorun"