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 +4 -4
- data/.gitignore +12 -0
- data/.travis.yml +19 -0
- data/CHANGELOG.md +52 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/_config.yml +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/carriage.gemspec +32 -0
- data/docs/.gitkeep +1 -0
- data/docs/_config.yml +1 -0
- data/lib/carriage.rb +14 -0
- data/lib/carriage/builder.rb +39 -0
- data/lib/carriage/locale.rb +35 -0
- data/lib/carriage/url.rb +11 -0
- data/lib/carriage/version.rb +3 -0
- data/vendor/logo.ai +11798 -0
- data/vendor/logo.jpg +0 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0a6df75b802ea7014df9978ab2d1aedb81a00328c2103ce83afc666822b7e15
|
4
|
+
data.tar.gz: 92e0e907d018c4fdd852c1ada76f671bd5e9ac328aaaf6a2f4684293211eb289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed3913d1b34914f84aa6c6e61765d43cfc927d84ea20a44c05a92d3da98423f4f768e12e9a65c72badf7a2b5c869e265b0d8530cf7f629511db4fa00d7506f81
|
7
|
+
data.tar.gz: 559346f9ea611a91d80afdd30f0bb6d77e434ed567a889417179a4958edc6899c0337e731a495cc09aca51df94444ba0b08e8b9b43bba48c8b91bc67755931a0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -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
|
data/CHANGELOG.md
ADDED
@@ -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.
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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).
|
data/Rakefile
ADDED
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-minimal
|
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
data/carriage.gemspec
ADDED
@@ -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
|
data/docs/.gitkeep
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/docs/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-tactile
|
data/lib/carriage.rb
ADDED
@@ -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
|