carriage 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e81427fae2e36e6ee765fc14b94efb8a78efee6feacbe24e47b35e25f54a6ad
4
- data.tar.gz: 0ae15d63cff13b5d0c8a44a64f7262ccbb0ef98fd5f702e5845c79c81570ca1a
3
+ metadata.gz: 25fe0daa076913620f277937c6f97adbf436f3ee9195e19501f6dc6cfa39f948
4
+ data.tar.gz: b080bcbfa7a16433ec01c6b19989ecab73fef559fef0a7792e0044f6270b1551
5
5
  SHA512:
6
- metadata.gz: dc0891d5d827726e047b89f1689530e8908517d1403b50422f0f1e3bef987b8031fe0bb1d0de4c30f1b14ec0c6cdc68df13eea719eaf99bc9c38000590f517ca
7
- data.tar.gz: 3d16f7d941e8c7d16d6f5216f7a7eb26fec47708dfa2b2885f991997c1c3e5d673a2f7df06c1ab9247c9d37fb4320935a6e184c497102b031595df787d10fafb
6
+ metadata.gz: b630641b6be259bb65d63f79054bb28a68539475879bfd55a35a2c2c8c5e4a941570d1699cef65ecf567f11054123ea1b4749a898ac1d1440fb1a395c9943dd3
7
+ data.tar.gz: 1967ba5454db65c7d074a1e28015808641026980973f682443134fe710b4a361ec934d14602f8152779e2324d7f4647f2e396164c5c7f0b1a5fddd9a16d79c6e
data/.travis.yml CHANGED
@@ -1,9 +1,19 @@
1
1
  ---
2
+
3
+ env:
4
+ global:
5
+ - CC_TEST_REPORTER_ID=60a3a7f0557745522235c43c9281570385a1c9d566a40946f91bb156e4ec4df0
2
6
  language: ruby
3
7
  cache: bundler
4
8
  rvm:
5
9
  - 2.7.0
10
+ before_script:
11
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
12
+ - chmod +x ./cc-test-reporter
13
+ - ./cc-test-reporter before-build
6
14
  before_install: gem install bundler -v 2.1.2
7
15
  script:
8
16
  - "bundle install"
9
17
  - "bundle exec rake test"
18
+ after_script:
19
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/CHANGELOG.md CHANGED
@@ -4,10 +4,16 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ##[0.3.0]
8
+
9
+ ### Added
10
+ - Support for Amazon locales
11
+ - Support for OfferListingId
12
+
7
13
  ## [0.2.0]
8
14
  ### Added
9
15
  - Set default quantity for a product
10
- - Write down regions and respective hosts associated with them
16
+ - Write down locales and respective hosts associated with them
11
17
 
12
18
  ### Changed
13
19
  - Using `URI.encode_www_form` to build URL parameters
data/carriage.gemspec CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.bindir = "exe"
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency 'm'
27
29
  end
data/lib/carriage.rb CHANGED
@@ -1,44 +1,14 @@
1
1
  require 'carriage/version'
2
- require 'uri'
2
+ require 'carriage/locale'
3
+ require 'carriage/request'
4
+ require 'carriage/builder'
5
+ require 'forwardable'
3
6
 
4
7
  module Carriage
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
8
+ class << self
9
+ extend Forwardable
22
10
 
23
- def self.call(region, params)
24
- "#{HOSTS_AND_REGIONS[:us]}?#{URI.encode_www_form params}"
25
- end
26
-
27
- def self.build(items, tag, key_id=nil)
28
- return nil if items.nil? || items.empty?
29
-
30
- params = {}
31
- index = 0
32
-
33
- while index < items.size
34
- params[:"ASIN.#{index + 1}"] = items[index][:asin]
35
- params[:"Quantity.#{index + 1}"] = items[index].fetch(:quantity, 1)
36
- index += 1
37
- end
38
-
39
- params[:AssociateTag] = tag
40
- params[:AWSAccessKeyId] = key_id unless (key_id.nil? || key_id.empty?)
41
-
42
- call(:us, params)
11
+ def_delegator 'Carriage::Request', :call
12
+ def_delegator 'Carriage::Builder', :call, :build
43
13
  end
44
14
  end
@@ -0,0 +1,30 @@
1
+ module Carriage
2
+ class Builder
3
+ class << self
4
+ def call(items, tag:, key_id: nil, locale: :us)
5
+ return nil if items.nil? || items.empty?
6
+
7
+ params = {}
8
+ index = 0
9
+
10
+
11
+ while index < items.size
12
+ item = items[index].transform_keys(&:upcase)
13
+
14
+ if item[:ASIN]
15
+ params[:"ASIN.#{index + 1}"] = item[:ASIN]
16
+ else
17
+ params[:"OfferListingId.#{index + 1}"] = item[:OFFERLISTINGID]
18
+ end
19
+ params[:"Quantity.#{index + 1}"] = item.fetch(:QUANTITY, 1)
20
+ index += 1
21
+ end
22
+
23
+ params[:AssociateTag] = tag
24
+ params[:AWSAccessKeyId] = key_id unless (key_id.nil? || key_id.empty?)
25
+
26
+ Carriage.call(locale, params)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Carriage
4
+ class Locale
5
+ class NotFound < KeyError; end
6
+
7
+ HOSTS = {
8
+ au: 'https://www.amazon.com.au/gp/aws/cart/add.html',
9
+ br: 'https://www.amazon.com.br/gp/aws/cart/add.html',
10
+ ca: 'https://www.amazon.ca/gp/aws/cart/add.html',
11
+ fr: 'https://www.amazon.fr/gp/aws/cart/add.html',
12
+ de: 'https://www.amazon.de/gp/aws/cart/add.html',
13
+ in: 'https://www.amazon.in/gp/aws/cart/add.html',
14
+ it: 'https://www.amazon.it/gp/aws/cart/add.html',
15
+ jp: 'https://www.amazon.co.jp/gp/aws/cart/add.html',
16
+ mx: 'https://www.amazon.com.mx/gp/aws/cart/add.html',
17
+ sg: 'https://www.amazon.sg/gp/aws/cart/add.html',
18
+ es: 'https://www.amazon.es/gp/aws/cart/add.html',
19
+ tr: 'https://www.amazon.com.tr/gp/aws/cart/add.html',
20
+ ae: 'https://www.amazon.ae/gp/aws/cart/add.html',
21
+ uk: 'https://www.amazon.co.uk/gp/aws/cart/add.html',
22
+ us: 'https://www.amazon.com/gp/aws/cart/add.html'
23
+ }.freeze
24
+
25
+ private_constant :HOSTS
26
+
27
+ attr_reader :host
28
+
29
+ def initialize(locale)
30
+ @host = HOSTS.fetch(locale.to_sym.downcase)
31
+ rescue KeyError
32
+ raise NotFound, "Locale not found: :#{locale}"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module Carriage
6
+ class Request
7
+ def self.call(locale, params)
8
+ "#{Locale.new(locale).host}?#{URI.encode_www_form params}"
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Carriage
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.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.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanislav (Stas) Katkov
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2020-02-12 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: m
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: This gem helps add any number of items to a customer's shopping cart
14
28
  and sending him to Amazon website to complete his order.
15
29
  email:
@@ -30,6 +44,9 @@ files:
30
44
  - bin/setup
31
45
  - carriage.gemspec
32
46
  - lib/carriage.rb
47
+ - lib/carriage/builder.rb
48
+ - lib/carriage/locale.rb
49
+ - lib/carriage/request.rb
33
50
  - lib/carriage/version.rb
34
51
  homepage: https://www.github.com/skatkov/carriage
35
52
  licenses: