carriage 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f5731948e95e6eabc30c63bdc9d9ab781b9f2a259ed1f31c7b24fd9182ea144
4
- data.tar.gz: 4bc1df903a37ed1a5cb6e1302677cf5c1a2cfbe6054e9cbb255ca514c806070c
3
+ metadata.gz: 6e81427fae2e36e6ee765fc14b94efb8a78efee6feacbe24e47b35e25f54a6ad
4
+ data.tar.gz: 0ae15d63cff13b5d0c8a44a64f7262ccbb0ef98fd5f702e5845c79c81570ca1a
5
5
  SHA512:
6
- metadata.gz: c1a761f0808373a2756dc6907e58b7f81a5044a6f1d126a9d0e7433d7767de2879bbde27140f7b46f81e6a8b871cc8f029c31c07f35141593de9aabc70cde35b
7
- data.tar.gz: c9f22786974d6eddbd5dc12c03be524b68ddaa20f7c635c0b71718c929e583487bf016da17cb3835d7f537f0f726be2cde889c64799da0e4083608e4407cdf18
6
+ metadata.gz: dc0891d5d827726e047b89f1689530e8908517d1403b50422f0f1e3bef987b8031fe0bb1d0de4c30f1b14ec0c6cdc68df13eea719eaf99bc9c38000590f517ca
7
+ data.tar.gz: 3d16f7d941e8c7d16d6f5216f7a7eb26fec47708dfa2b2885f991997c1c3e5d673a2f7df06c1ab9247c9d37fb4320935a6e184c497102b031595df787d10fafb
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  .idea/
11
11
  .rakeTasks
12
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -4,3 +4,6 @@ cache: bundler
4
4
  rvm:
5
5
  - 2.7.0
6
6
  before_install: gem install bundler -v 2.1.2
7
+ script:
8
+ - "bundle install"
9
+ - "bundle exec rake test"
data/CHANGELOG.md CHANGED
@@ -2,5 +2,16 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [Unreleased]
6
+
7
+ ## [0.2.0]
8
+ ### Added
9
+ - Set default quantity for a product
10
+ - Write down regions and respective hosts associated with them
11
+
12
+ ### Changed
13
+ - Using `URI.encode_www_form` to build URL parameters
14
+ - `AWSAccessKeyId` is not a required argument
15
+
5
16
  ## [0.1.0]
6
17
  First public version, only focused on supporting one region - US.
data/README.md CHANGED
@@ -1,9 +1,13 @@
1
- # Carriage
1
+ [![Gem Version](https://badge.fury.io/rb/carriage.svg)](https://badge.fury.io/rb/carriage)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/79ddcbeb02fe9447cd0d/maintainability)](https://codeclimate.com/github/skatkov/carriage/maintainability)
3
+ [![Build Status](https://travis-ci.org/skatkov/carriage.svg?branch=master)](https://travis-ci.org/skatkov/carriage)
2
4
 
5
+ # Carriage
3
6
  Carriage is a Ruby wrapper to [Amazon Product Advertising API 5.0 - Cart Form](https://webservices.amazon.com/paapi5/documentation/add-to-cart-form.html). This gem helps add any number of items to a customer's shopping cart and sending him to Amazon website to complete his order.
4
7
 
5
8
  To use this gem, you need to have Amazon **AssociateTag**, so don't forget to [register first](https://webservices.amazon.com/paapi5/documentation/register-for-pa-api.html) with Amazon Associate program.
6
9
 
10
+ Programmatic access to product data is out of scope for this gem, but I recommend to use [vacuum gem](https://github.com/hakanensari/vacuum) if there is such a need.
7
11
 
8
12
  ## Installation
9
13
 
@@ -25,15 +29,10 @@ Or install it yourself as:
25
29
 
26
30
  TODO: Write usage instructions here
27
31
 
28
- ## Development
29
-
30
- 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.
31
-
32
- 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).
33
-
34
- ## Contributing
32
+ ## Getting help
35
33
 
36
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/carriage. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/carriage/blob/master/CODE_OF_CONDUCT.md).
34
+ * Ask specific questions about the API on the [Amazon forum](https://forums.aws.amazon.com/forum.jspa?forumID=9).
35
+ * Report bugs and discuss potential features in [GitHub issues](https://github.com/skatkov/carriage/issues).
37
36
 
38
37
 
39
38
  ## License
@@ -42,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
42
41
 
43
42
  ## Code of Conduct
44
43
 
45
- Everyone interacting in the Carriage project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/carriage/blob/master/CODE_OF_CONDUCT.md).
44
+ Everyone interacting in the Carriage project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/skatkov/carriage/blob/master/CODE_OF_CONDUCT.md).
data/carriage.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://www.github.com/skatkov/carriage"
12
12
  spec.license = "MIT"
13
13
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
-
14
+
15
15
  spec.metadata["homepage_uri"] = spec.homepage
16
16
  spec.metadata["source_code_uri"] = "https://www.github.com/skatkov/carriage"
17
17
  spec.metadata["changelog_uri"] = "https://github.com/skatkov/carriage/blob/master/CHANGELOG.md"
data/lib/carriage.rb CHANGED
@@ -1,26 +1,44 @@
1
- require "carriage/version"
1
+ require 'carriage/version'
2
+ require 'uri'
2
3
 
3
4
  module Carriage
4
- class Error < StandardError; end
5
+ HOSTS_AND_REGIONS = {
6
+ au: 'https://www.amazon.com.au/gp/aws/cart/add.html',
7
+ br: 'https://www.amazon.com.br/gp/aws/cart/add.html',
8
+ ca: 'https://www.amazon.ca/gp/aws/cart/add.html',
9
+ fr: 'https://www.amazon.fr/gp/aws/cart/add.html',
10
+ de: 'https://www.amazon.de/gp/aws/cart/add.html',
11
+ in: 'https://www.amazon.in/gp/aws/cart/add.html',
12
+ it: 'https://www.amazon.it/gp/aws/cart/add.html',
13
+ jp: 'https://www.amazon.co.jp/gp/aws/cart/add.html',
14
+ mx: 'https://www.amazon.com.mx/gp/aws/cart/add.html',
15
+ sg: 'https://www.amazon.sg/gp/aws/cart/add.html',
16
+ es: 'https://www.amazon.es/gp/aws/cart/add.html',
17
+ tr: 'https://www.amazon.com.tr/gp/aws/cart/add.html',
18
+ ae: 'https://www.amazon.ae/gp/aws/cart/add.html',
19
+ uk: 'https://www.amazon.co.uk/gp/aws/cart/add.html',
20
+ us: 'https://www.amazon.com/gp/aws/cart/add.html'
21
+ }.freeze
5
22
 
6
- BASE_URL = "https://www.amazon.com/gp/aws/cart/add.html?".freeze
23
+ def self.call(region, params)
24
+ "#{HOSTS_AND_REGIONS[:us]}?#{URI.encode_www_form params}"
25
+ end
7
26
 
8
- def self.build(items, tag, key_id)
27
+ def self.build(items, tag, key_id=nil)
9
28
  return nil if items.nil? || items.empty?
10
29
 
11
- params = ""
30
+ params = {}
12
31
  index = 0
13
32
 
14
33
  while index < items.size
15
- params << '&' if index > 0
16
- params << "ASIN.#{index+1}=#{items[index][:asin]}&Quantity.#{index+1}=#{items[index][:quantity]}"
34
+ params[:"ASIN.#{index + 1}"] = items[index][:asin]
35
+ params[:"Quantity.#{index + 1}"] = items[index].fetch(:quantity, 1)
17
36
  index += 1
18
37
  end
19
38
 
20
- if key_id.nil? || key_id.empty?
21
- "#{BASE_URL}#{params}&AssociateTag=#{tag}"
22
- else
23
- "#{BASE_URL}#{params}&AssociateTag=#{tag}&AWSAccessKeyId=#{key_id}"
24
- end
39
+ params[:AssociateTag] = tag
40
+ params[:AWSAccessKeyId] = key_id unless (key_id.nil? || key_id.empty?)
41
+
42
+ call(:us, params)
25
43
  end
26
44
  end
@@ -1,3 +1,3 @@
1
1
  module Carriage
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carriage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov
@@ -23,7 +23,6 @@ files:
23
23
  - CHANGELOG.md
24
24
  - CODE_OF_CONDUCT.md
25
25
  - Gemfile
26
- - Gemfile.lock
27
26
  - LICENSE.txt
28
27
  - README.md
29
28
  - Rakefile
data/Gemfile.lock DELETED
@@ -1,21 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- carriage (0.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- minitest (5.13.0)
10
- rake (12.3.2)
11
-
12
- PLATFORMS
13
- ruby
14
-
15
- DEPENDENCIES
16
- carriage!
17
- minitest (~> 5.0)
18
- rake (~> 12.0)
19
-
20
- BUNDLED WITH
21
- 1.17.3