amazon_bundler 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/amazon_bundler.rb +33 -12
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1519dcc8d71e9b513eeb886300b03f41b92c0d8d359daa5d78c6665ab489aeae
4
- data.tar.gz: ca62a1f7f261d64ec735c54edaea4dc0c3987e29d2be3ed3a9b71b7aced11ee8
3
+ metadata.gz: cb56b396dba05027b13aa61e19a12cb3967f157f9bc8eec7407b2a3c330464eb
4
+ data.tar.gz: c8bfee0f14bb33d469748b53e1fb73bd8f0ed9334a0e8ad0ac1c4b0a7cd37a56
5
5
  SHA512:
6
- metadata.gz: 10657336353400e1f4bdcee55c773c14cdceb3c1fe0f31075f17647fbd31e440ad511c306faf60574f5d3bb57c84c1ec4331decced0579543b1a37452be1197d
7
- data.tar.gz: 3cff512eae8504684d5e7540a121c7953421631aeed35e4f955c49357f70da09ea34e872e59982d24574eef24955c58b21928eab04be262dc5a9891f6d902ddc
6
+ metadata.gz: c90389cc3b3274917d95acee1f104c546087618cd85ca2209ed1519c4b8e2e3aa058a588b1541e41d5b5df39ebc9066dac046eaf7a0faa7f311ea7ed5fcb4026
7
+ data.tar.gz: dbb1f05fdffab100e1801b9e34a92130650b9926edba165c655655f39ffa3831b1d9c5febf50f026bb5f06b1be4ef5c7a9f77300c4278c75bf0ef728907bdd09
@@ -2,22 +2,43 @@
2
2
 
3
3
  # Creates a one-click url to add a bundle of Amazon products to cart
4
4
  module AmazonBundler
5
- def self.convert_products_to_url(product_hash)
6
- product_hash.each_with_index.map { |product, index| convert_product_to_url(product, index) }.join('&')
5
+ module_function
6
+
7
+ def base_url
8
+ 'https://www.amazon.com/gp/aws/cart/add.html?'
9
+ end
10
+
11
+ def products_with_index(product_hash)
12
+ product_hash.each_with_index do |product, index|
13
+ product[:index] = index + 1
14
+ end
15
+ end
16
+
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
+ end
21
+
22
+ def convert_product_to_url(product)
23
+ [asin(product), quantity(product), offer(product)].join('&')
24
+ end
25
+
26
+ def asin(product)
27
+ "ASIN.#{product[:index]}=#{product[:asin]}"
28
+ end
29
+
30
+ def quantity(product)
31
+ "Quantity.#{product[:index]}=#{product[:quantity]}"
7
32
  end
8
33
 
9
- def self.convert_product_to_url(product, index)
10
- asin = "ASIN.#{index + 1}=#{product[:asin]}"
11
- quantity = "Quantity.#{index + 1}=#{product[:quantity]}"
12
- offer = product[:offer_id].nil? ? '' : "OfferListingId.#{index + 1}=#{product[:offer_id]}"
13
- [asin, quantity, offer].join('&')
34
+ def offer(product)
35
+ offer_id = product[:offer_id].to_s
36
+ offer_id ? "OfferListingId.#{product[:index]}=#{offer_id}" : ''
14
37
  end
15
38
 
16
- def self.create_bundle_link(product_hash: {}, affiliate_id: nil)
17
- base_url = 'https://www.amazon.com/gp/aws/cart/add.html?'
39
+ def create_bundle_link(product_hash: {}, affiliate_id: nil)
18
40
  affiliate_info = affiliate_id ? "AssociateTag=#{affiliate_id}&" : ''
19
- products = convert_products_to_url(product_hash)
20
- "#{base_url}#{affiliate_info}#{products}"
41
+ products_url = convert_products_hash_to_url(product_hash)
42
+ "#{base_url}#{affiliate_info}#{products_url}"
21
43
  end
22
- 'https://www.amazon.com/gp/aws/cart/add.html?AssociateTag=your_tag&tag=your_tagQ&ASIN.1=B012NH05UW&Quantity.1=1&ASIN.2=B012M8LXQW&Quantity.2=1'
23
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon_bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bobby Meyer
@@ -29,7 +29,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 2.7.0
32
+ version: 2.5.0
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
34
  requirements:
35
35
  - - ">="