amazon_bundler 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/amazon_bundler.rb +33 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb56b396dba05027b13aa61e19a12cb3967f157f9bc8eec7407b2a3c330464eb
|
4
|
+
data.tar.gz: c8bfee0f14bb33d469748b53e1fb73bd8f0ed9334a0e8ad0ac1c4b0a7cd37a56
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c90389cc3b3274917d95acee1f104c546087618cd85ca2209ed1519c4b8e2e3aa058a588b1541e41d5b5df39ebc9066dac046eaf7a0faa7f311ea7ed5fcb4026
|
7
|
+
data.tar.gz: dbb1f05fdffab100e1801b9e34a92130650b9926edba165c655655f39ffa3831b1d9c5febf50f026bb5f06b1be4ef5c7a9f77300c4278c75bf0ef728907bdd09
|
data/lib/amazon_bundler.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
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
|
10
|
-
|
11
|
-
|
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
|
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
|
-
|
20
|
-
"#{base_url}#{affiliate_info}#{
|
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.
|
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.
|
32
|
+
version: 2.5.0
|
33
33
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
34
|
requirements:
|
35
35
|
- - ">="
|