carriage 1.2.0 → 1.2.1

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: 81c8dfff264cd4dea5094c483c609afccc1fca19e9b91da6e7bca55983f9cfcb
4
- data.tar.gz: be7d270310b5a22abde524ff6e22934f4556460f2e686ae22270a91c53195a4e
3
+ metadata.gz: e0a6df75b802ea7014df9978ab2d1aedb81a00328c2103ce83afc666822b7e15
4
+ data.tar.gz: 92e0e907d018c4fdd852c1ada76f671bd5e9ac328aaaf6a2f4684293211eb289
5
5
  SHA512:
6
- metadata.gz: '0000209ec66433e65ccb757f72ac4cf37e8239ade04c5d4cec71d98b7524b1c738a87f829c8f7c28bcc6c12ac4a5b119906297c0765f41ec5e111ee847cdbb5a'
7
- data.tar.gz: ebd344788003ca269bdfb07c732467cc4f5666f328bfd91d2c4d3756ee6a63013a4f6d24d9b0b1dc6ab222a1d022bc8f3222de69d2222f1e7b6dc08eb821a3e5
6
+ metadata.gz: ed3913d1b34914f84aa6c6e61765d43cfc927d84ea20a44c05a92d3da98423f4f768e12e9a65c72badf7a2b5c869e265b0d8530cf7f629511db4fa00d7506f81
7
+ data.tar.gz: 559346f9ea611a91d80afdd30f0bb6d77e434ed567a889417179a4958edc6899c0337e731a495cc09aca51df94444ba0b08e8b9b43bba48c8b91bc67755931a0
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .idea/
11
+ .rakeTasks
12
+ Gemfile.lock
@@ -0,0 +1,19 @@
1
+ ---
2
+
3
+ env:
4
+ global:
5
+ - CC_TEST_REPORTER_ID=60a3a7f0557745522235c43c9281570385a1c9d566a40946f91bb156e4ec4df0
6
+ language: ruby
7
+ cache: bundler
8
+ rvm:
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
14
+ before_install: gem install bundler -v 2.1.2
15
+ script:
16
+ - "bundle install"
17
+ - "bundle exec rake test"
18
+ after_script:
19
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,52 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [1.2.1]
8
+ - Rollback some changes in gemspec
9
+
10
+ ## [1.2.0]
11
+ ### Breaking change
12
+ - hash now accepts :id key, but doesn't accept :OfferListingId anymore.
13
+
14
+ ### Added
15
+ - test to verify that quantity could be set
16
+
17
+ ## [1.1.1]
18
+ ### Added
19
+ - Project website
20
+
21
+ ## [1.1.0]
22
+ ### Added
23
+ - Project logo
24
+
25
+ ### Changed
26
+ - Improve gem description
27
+ - Clean-up Gemfile
28
+ - Simplified Locale error handling
29
+ - Refactoring
30
+
31
+ ## [1.0.0]
32
+
33
+ - Finalize documentation
34
+ - Release 1 version to show completeness of api
35
+
36
+ ## [0.3.0]
37
+
38
+ ### Added
39
+ - Support for Amazon locales
40
+ - Support for OfferListingId
41
+
42
+ ## [0.2.0]
43
+ ### Added
44
+ - Set default quantity for a product
45
+ - Write down locales and respective hosts associated with them
46
+
47
+ ### Changed
48
+ - Using `URI.encode_www_form` to build URL parameters
49
+ - `AWSAccessKeyId` is not a required argument
50
+
51
+ ## [0.1.0]
52
+ First public version, only focused on supporting one region - US.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at sk@skylup.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in carriage.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Stanislav (Stas) Katkov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,87 @@
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)
4
+
5
+ # Carriage
6
+ <p align="center">
7
+ <img src="./vendor/logo.jpg" alt="Carriage project logo" width="400">
8
+ </p>
9
+
10
+ Carriage is a Ruby micro-wrapper to [Amazon's Cart Form](https://webservices.amazon.com/paapi5/documentation/add-to-cart-form.html) functionality. Gem helps add any number of items to customer's shopping cart and direct him to Amazon website to complete order.
11
+
12
+ To use this gem, you will eventually require Amazon's **AssociateTag**, so consider to [register first](https://webservices.amazon.com/paapi5/documentation/register-for-pa-api.html) with Amazon Associate program and become more familiar with it.
13
+
14
+ 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.
15
+
16
+ [Battle tested at aShop](https://www.ashop.co/?utm_source=carriage-gem)
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'carriage'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle install
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install carriage
33
+
34
+ ## Usage
35
+
36
+ A lot of examples could be found [in tests](https://github.com/skatkov/carriage/blob/master/test/carriage_test.rb)
37
+
38
+ There are basically two ways to use this gem `bare metal` and with `builder`. Let's start off with baremetal:
39
+
40
+ ### Bare metal
41
+ ```
42
+ Carriage.call(:us, {
43
+ AssociateTag:'tag',
44
+ "OfferListingId.1": "B00WR23X5I",
45
+ "Quantity.1": 1
46
+ }
47
+ )
48
+ ```
49
+ The only thing it will validate, is a presence of locale. All other parameters will be converted by `URI.encode_www_form` without any verification. Be carefull!
50
+
51
+ ### Builder
52
+ Library also offers a simpler interface that tries to valide data with convinince methods on top.
53
+
54
+ ```
55
+ items = [
56
+ {Id: '123123'}.
57
+ {ASIN: '1231234', quantity: 2}
58
+ ]
59
+
60
+ Carriage.build(items, tag: 'my_attribution_tag', locale: :uk)
61
+ ```
62
+
63
+ * Every item should be a hash, with `ASIN` or `ID` (short for `OfferListingId`) key provided. All keys are _case insensitive_.
64
+ * By default quantity is 1, feel free to rewrite that.
65
+ * `Carriage.build` also requires `:tag` attribute (short for `AssociateTag`)
66
+ * Defaults to `locale: :us`, if no other locale was provided.
67
+
68
+ ### Locale
69
+ All locale are based on a two letter country codes - **ISO 3166-1 alpha-2**. Here is an exact mapping:
70
+
71
+ https://github.com/skatkov/carriage/blob/master/lib/carriage/locale.rb#L7-L23
72
+
73
+ ## Getting help
74
+
75
+ * Ask specific questions about the API on the [Amazon forum](https://forums.aws.amazon.com/forum.jspa?forumID=9).
76
+ * Report bugs and discuss potential features in [GitHub issues](https://github.com/skatkov/carriage/issues).
77
+
78
+ ## Credits
79
+ Logo was done by [Max Kazmin](https://dribbble.com/maxpainter)
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
84
+
85
+ ## Code of Conduct
86
+
87
+ 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).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-minimal
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "carriage"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ require_relative 'lib/carriage/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "carriage"
5
+ spec.version = Carriage::VERSION
6
+ spec.authors = ["Stanislav (Stas) Katkov"]
7
+ spec.email = ["sk@skylup.com"]
8
+
9
+ spec.summary = "Carriage is a Ruby micro-wrapper to Amazon's Cart Form functionality (part of Product Advertising API v5.0)"
10
+ spec.description = "Gem helps add any number of items to customer's shopping cart and direct him to Amazon website to complete order."
11
+ spec.homepage = "https://skatkov.github.io/carriage/"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/skatkov/carriage"
17
+ spec.metadata["changelog_uri"] = "https://github.com/skatkov/carriage/blob/master/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'minitest'
31
+ spec.add_development_dependency 'm'
32
+ end
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-tactile
@@ -0,0 +1,14 @@
1
+ require 'carriage/version'
2
+ require 'carriage/locale'
3
+ require 'carriage/url'
4
+ require 'carriage/builder'
5
+ require 'forwardable'
6
+
7
+ module Carriage
8
+ class << self
9
+ extend Forwardable
10
+
11
+ def_delegator 'Carriage::Url', :call
12
+ def_delegator 'Carriage::Builder', :call, :build
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ module Carriage
2
+ class Builder
3
+ class << self
4
+ def call(items, tag:, key_id: nil, locale: :us)
5
+ params = {}
6
+
7
+ wrap(items).each_with_index do |obj, index|
8
+ item = obj.transform_keys(&:upcase)
9
+
10
+ if item[:ASIN]
11
+ params[:"ASIN.#{index + 1}"] = item[:ASIN]
12
+ elsif item[:ID]
13
+ params[:"OfferListingId.#{index + 1}"] = item[:ID]
14
+ else
15
+ next
16
+ end
17
+ params[:"Quantity.#{index + 1}"] = item.fetch(:QUANTITY, 1)
18
+ end
19
+
20
+ params[:AssociateTag] = tag
21
+ params[:AWSAccessKeyId] = key_id unless (key_id.nil? || key_id.empty?)
22
+
23
+ Carriage.call(locale, params)
24
+ end
25
+
26
+ private
27
+
28
+ def wrap(object)
29
+ if object.nil?
30
+ []
31
+ elsif object.respond_to?(:to_ary)
32
+ object.to_ary || [object]
33
+ else
34
+ [object]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ 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) do |value|
31
+ raise NotFound, "Locale not found: :#{value}"
32
+ end
33
+ end
34
+ end
35
+ end