amazon_bundler 0.0.2 → 0.1.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: cb56b396dba05027b13aa61e19a12cb3967f157f9bc8eec7407b2a3c330464eb
4
- data.tar.gz: c8bfee0f14bb33d469748b53e1fb73bd8f0ed9334a0e8ad0ac1c4b0a7cd37a56
3
+ metadata.gz: 960d68e17d7f66fc99ea2a09b7f3673d75bec43014737695315d479ace1c8cf6
4
+ data.tar.gz: 808172429bec75850fd2d52f8f961ba0ea82ee5a645fd16610328f3ecde5e6f8
5
5
  SHA512:
6
- metadata.gz: c90389cc3b3274917d95acee1f104c546087618cd85ca2209ed1519c4b8e2e3aa058a588b1541e41d5b5df39ebc9066dac046eaf7a0faa7f311ea7ed5fcb4026
7
- data.tar.gz: dbb1f05fdffab100e1801b9e34a92130650b9926edba165c655655f39ffa3831b1d9c5febf50f026bb5f06b1be4ef5c7a9f77300c4278c75bf0ef728907bdd09
6
+ metadata.gz: 37efbe1a16e413100dd66f1346d90e3581785a4d7a6b427fed181977788d5866c7bd87bac22b0ffbf47a93004397893b108b1fb7e9c986064217467e828f547c
7
+ data.tar.gz: 67e8bcac8d9ce5d632fde20d6f37a053e71573b65253aa2259780992771497cf573151d6fdc00c3429fe1c3f77d36b0982f78f4a368ec9cdfbf799d2724bffac
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-05-02
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in amazon_bundler.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem "rspec", "~> 3.0"
10
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ amazon_bundler (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.5.0)
12
+ ffi (1.15.5)
13
+ formatador (1.1.0)
14
+ guard (2.18.0)
15
+ formatador (>= 0.2.4)
16
+ listen (>= 2.7, < 4.0)
17
+ lumberjack (>= 1.0.12, < 2.0)
18
+ nenv (~> 0.1)
19
+ notiffany (~> 0.0)
20
+ pry (>= 0.13.0)
21
+ shellany (~> 0.0)
22
+ thor (>= 0.18.1)
23
+ guard-compat (1.2.1)
24
+ guard-rspec (4.7.3)
25
+ guard (~> 2.1)
26
+ guard-compat (~> 1.1)
27
+ rspec (>= 2.99.0, < 4.0)
28
+ listen (3.7.1)
29
+ rb-fsevent (~> 0.10, >= 0.10.3)
30
+ rb-inotify (~> 0.9, >= 0.9.10)
31
+ lumberjack (1.2.8)
32
+ method_source (1.0.0)
33
+ nenv (0.3.0)
34
+ notiffany (0.1.3)
35
+ nenv (~> 0.1)
36
+ shellany (~> 0.0)
37
+ parallel (1.22.1)
38
+ parser (3.1.2.0)
39
+ ast (~> 2.4.1)
40
+ pry (0.14.1)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
43
+ pry-nav (1.0.0)
44
+ pry (>= 0.9.10, < 0.15)
45
+ pry-remote (0.1.8)
46
+ pry (~> 0.9)
47
+ slop (~> 3.0)
48
+ rainbow (3.1.1)
49
+ rake (13.0.6)
50
+ rb-fsevent (0.11.1)
51
+ rb-inotify (0.10.1)
52
+ ffi (~> 1.0)
53
+ regexp_parser (2.3.1)
54
+ rexml (3.2.5)
55
+ rspec (3.11.0)
56
+ rspec-core (~> 3.11.0)
57
+ rspec-expectations (~> 3.11.0)
58
+ rspec-mocks (~> 3.11.0)
59
+ rspec-core (3.11.0)
60
+ rspec-support (~> 3.11.0)
61
+ rspec-expectations (3.11.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.11.0)
64
+ rspec-mocks (3.11.1)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.11.0)
67
+ rspec-support (3.11.0)
68
+ rubocop (1.28.2)
69
+ parallel (~> 1.10)
70
+ parser (>= 3.1.0.0)
71
+ rainbow (>= 2.2.2, < 4.0)
72
+ regexp_parser (>= 1.8, < 3.0)
73
+ rexml
74
+ rubocop-ast (>= 1.17.0, < 2.0)
75
+ ruby-progressbar (~> 1.7)
76
+ unicode-display_width (>= 1.4.0, < 3.0)
77
+ rubocop-ast (1.17.0)
78
+ parser (>= 3.1.1.0)
79
+ ruby-progressbar (1.11.0)
80
+ shellany (0.0.1)
81
+ slop (3.6.0)
82
+ thor (1.2.1)
83
+ unicode-display_width (2.1.0)
84
+
85
+ PLATFORMS
86
+ x86_64-darwin-21
87
+
88
+ DEPENDENCIES
89
+ amazon_bundler!
90
+ guard
91
+ guard-rspec
92
+ pry
93
+ pry-nav
94
+ pry-remote
95
+ rake (~> 13.0)
96
+ rspec (~> 3.0)
97
+ rubocop (~> 1.21)
98
+
99
+ BUNDLED WITH
100
+ 2.3.8
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 TODO: Write your name
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,43 @@
1
+ # AmazonBundler
2
+
3
+ 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/amazon_bundler`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'amazon_bundler'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install amazon_bundler
22
+
23
+ ## Usage
24
+ Feed the bundler a hash of Amazon Product ASINs, Quantities, and OfferIDs (Optional) and it will give you back a link to add all items to your cart with one click. Optionally, you can also give it your Amazon Associate ID and it will give you referral credit.
25
+
26
+ ### Example
27
+ ```
28
+ AmazonBundler.create_bundle_link(product_hash: product_hash, affiliate_id: '666666')
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
34
+
35
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/amazon_bundler.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmazonBundler
4
+ VERSION = "0.1.0"
5
+ end
@@ -1,26 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "amazon_bundler/version"
4
+ require "error_checking"
5
+
3
6
  # Creates a one-click url to add a bundle of Amazon products to cart
4
7
  module AmazonBundler
5
8
  module_function
6
9
 
7
10
  def base_url
8
- 'https://www.amazon.com/gp/aws/cart/add.html?'
11
+ "https://www.amazon.com/gp/aws/cart/add.html?"
9
12
  end
10
13
 
11
- def products_with_index(product_hash)
12
- product_hash.each_with_index do |product, index|
14
+ def products_with_index(product_array)
15
+ product_array.each_with_index do |product, index|
13
16
  product[:index] = index + 1
14
17
  end
15
18
  end
16
19
 
17
- def convert_products_hash_to_url(product_hash)
18
- product_hash = products_with_index(product_hash)
19
- product_hash.map { |product| convert_product_to_url(product) }.join('&')
20
+ def convert_products_array_to_url(product_array)
21
+ product_array = products_with_index(product_array)
22
+ product_array.map { |product| convert_product_to_url(product) }.join("&")
20
23
  end
21
24
 
22
25
  def convert_product_to_url(product)
23
- [asin(product), quantity(product), offer(product)].join('&')
26
+ [asin(product), quantity(product), offer(product)].join("&")
24
27
  end
25
28
 
26
29
  def asin(product)
@@ -33,12 +36,13 @@ module AmazonBundler
33
36
 
34
37
  def offer(product)
35
38
  offer_id = product[:offer_id].to_s
36
- offer_id ? "OfferListingId.#{product[:index]}=#{offer_id}" : ''
39
+ offer_id.empty? ? "" : "OfferListingId.#{product[:index]}=#{offer_id}"
37
40
  end
38
41
 
39
- def create_bundle_link(product_hash: {}, affiliate_id: nil)
40
- affiliate_info = affiliate_id ? "AssociateTag=#{affiliate_id}&" : ''
41
- products_url = convert_products_hash_to_url(product_hash)
42
+ def create_bundle_link(product_array: [], affiliate_id: nil)
43
+ ErrorChecking.product_array_valid?(product_array)
44
+ affiliate_info = affiliate_id ? "AssociateTag=#{affiliate_id}&" : ""
45
+ products_url = convert_products_array_to_url(product_array)
42
46
  "#{base_url}#{affiliate_info}#{products_url}"
43
47
  end
44
48
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Check for valid data, provide helpful errors if not
4
+ module ErrorChecking
5
+ module_function
6
+
7
+ def product_array_valid?(product_array)
8
+ errors = []
9
+ errors.push("AmazonBundler expects an Array of Products") unless product_array.is_a?(Array) || !product_array.empty?
10
+ product_array.each do |product|
11
+ product_valid?(product, errors)
12
+ end
13
+ raise StandardError.new(errors.join("\n")) unless errors.empty?
14
+ end
15
+
16
+ def product_valid?(product, errors)
17
+ valid_hash = product.is_a?(Hash)
18
+ errors.push("AmazonBundler expects Products to be a Hash") unless valid_hash
19
+ return unless valid_hash
20
+
21
+ errors.push("AmazonBundler expects Products to have an ASIN") unless product.key?(:asin) || !product[:asin].to_s.empty?
22
+ errors.push("AmazonBundler expects Products to have a Quantity") unless product.key?(:quantity) || !product[:quantity].to_s.empty?
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ module AmazonBundler
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/spec.rake ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core/rake_task"
4
+ require "bundler/gem_tasks"
5
+
6
+ # Default directory to look in is `/specs`
7
+ # Run with `rake spec`
8
+ RSpec::Core::RakeTask.new(:spec) do |task|
9
+ task.rspec_opts = ["--color", "--format", "nested"]
10
+ end
11
+
12
+ task default: :spec
metadata CHANGED
@@ -1,26 +1,140 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon_bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bobby Meyer
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2022-05-02 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Formats lists of ASINs for creating single click bundles of Amazon products
14
- email: bobby@bobbymeyer.com
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: guard
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-nav
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-remote
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - bobby@bobbymeyer.com
15
114
  executables: []
16
115
  extensions: []
17
116
  extra_rdoc_files: []
18
117
  files:
118
+ - ".rspec"
119
+ - ".rubocop.yml"
120
+ - CHANGELOG.md
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
19
126
  - lib/amazon_bundler.rb
20
- homepage: https://rubygems.org/gems/amazon_bundler
127
+ - lib/amazon_bundler/version.rb
128
+ - lib/error_checking.rb
129
+ - sig/amazon_bundler.rbs
130
+ - spec.rake
131
+ homepage: https://github.com/bobbymeyer/amazon_bundler
21
132
  licenses:
22
133
  - MIT
23
- metadata: {}
134
+ metadata:
135
+ homepage_uri: https://github.com/bobbymeyer/amazon_bundler
136
+ source_code_uri: https://github.com/bobbymeyer/amazon_bundler
137
+ changelog_uri: https://github.com/bobbymeyer/amazon_bundler/blob/main/CHANGELOG.md
24
138
  post_install_message:
25
139
  rdoc_options: []
26
140
  require_paths:
@@ -29,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
143
  requirements:
30
144
  - - ">="
31
145
  - !ruby/object:Gem::Version
32
- version: 2.5.0
146
+ version: 2.6.0
33
147
  required_rubygems_version: !ruby/object:Gem::Requirement
34
148
  requirements:
35
149
  - - ">="
@@ -39,5 +153,5 @@ requirements: []
39
153
  rubygems_version: 3.3.7
40
154
  signing_key:
41
155
  specification_version: 4
42
- summary: Bundle Amazon products and add to cart with one-click
156
+ summary: Add multiple items to an Amazon Cart with one link.
43
157
  test_files: []