badass 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/badass.rb +7 -5
- data/lib/badass/client.rb +7 -14
- data/lib/badass/toy.rb +36 -13
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e48b4cc6729c2e2b669be4c10796aa438da25c9b58eaee979c3d1e4dbae0f89a
|
4
|
+
data.tar.gz: f8b76cd02126f0d0696b8c169cd21f832ea1c51b8a3f16d79f9d845e18e291f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 468602146563064d4755dda01ecc741a28615fa22fb2be25cad2778061baebe7a29bf8cac723e62f9419172d08ce1857229d283ffd5cc576109243ae5f71cea8
|
7
|
+
data.tar.gz: 857e993e52a020ea95b1f0d890a22fe8656a02514a122dfb20df8cb06a188996e058935f9f7656015d9318fb593afb8df785b6aaea68daa72f3da71c3835551f
|
data/lib/badass.rb
CHANGED
@@ -2,13 +2,15 @@ require 'net/http'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
module BadASS
|
5
|
-
|
5
|
+
FIRMNESSES = { '2' => 'Extra Soft', '3' => 'Soft', '5' => 'Medium', '8' => 'Firm', '3/5' => 'Soft Shaft, Med Base', '5/3' => 'Soft Shaft, Med Base', '3/8' => 'Soft Shaft, Firm Base', '8/3' => 'Soft Shaft, Firm Base', '5/8' => 'Med Shaft, Firm Base', '8/5' => 'Med Shaft, Firm Base' }.freeze
|
6
|
+
SIZES = { 'onesize' => 'One-Size', 'mini' => 'Mini', 'small' => 'Small', 'medium' => 'Medium', 'large' => 'Large', 'extralarge' => 'Extra Large' }.freeze
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
@baddragon_skus = {}
|
9
|
+
JSON.parse(Net::HTTP.get(URI('https://bad-dragon.com/api/inventory-toy/product-list'))).each do |toy|
|
10
|
+
@baddragon_skus[toy['sku']] = toy['name']
|
9
11
|
end
|
10
|
-
|
12
|
+
BAD_DRAGON_SKUS = @baddragon_skus.freeze
|
11
13
|
end
|
12
14
|
|
13
15
|
require 'badass/client'
|
14
|
-
require 'badass/
|
16
|
+
require 'badass/toy'
|
data/lib/badass/client.rb
CHANGED
@@ -1,32 +1,25 @@
|
|
1
1
|
class BadASS::Client
|
2
2
|
# Creates a client to do operations.
|
3
|
+
# Takes a :refresh_time argument to define how often the toy list should be refreshed.
|
3
4
|
def initialize(refresh_time: 600)
|
4
5
|
Thread.new do
|
5
|
-
@
|
6
|
-
JSON.parse(Net::HTTP.get(URI('https://bad-dragon.com/api/inventory-toy/product-list'))).each do |toy|
|
7
|
-
@baddragon_skus[toy['sku']] = toy['name']
|
8
|
-
end
|
6
|
+
@toys = []
|
9
7
|
loop do
|
10
|
-
@toys_finished = false
|
11
8
|
page = 1
|
12
|
-
|
9
|
+
toy_list = []
|
13
10
|
loop do
|
14
11
|
newtoys = JSON.parse(Net::HTTP.get(URI("https://bad-dragon.com/api/inventory-toys?price[min]=0&price[max]=300&noAccessories=false&cumtube=false&suctionCup=false&sort[field]=price&&sort[direction]=asc&page=#{page}&limit=60")))
|
12
|
+
page += 1
|
15
13
|
newtoys['toys'].each do |toy|
|
16
|
-
|
14
|
+
toy_list << BadASS::Toy.new(toy)
|
17
15
|
end
|
18
|
-
page += 1
|
19
|
-
@toys.concat(newtoys['toys'])
|
20
16
|
break if page > newtoys['totalPages']
|
21
17
|
end
|
22
|
-
@
|
18
|
+
@toys = toy_list
|
23
19
|
sleep(refresh_time)
|
24
20
|
end
|
25
21
|
end
|
26
22
|
end
|
27
23
|
|
28
|
-
|
29
|
-
sleep(0.1) until @toys_finished
|
30
|
-
@toys
|
31
|
-
end
|
24
|
+
attr_reader :toys
|
32
25
|
end
|
data/lib/badass/toy.rb
CHANGED
@@ -1,17 +1,40 @@
|
|
1
1
|
class BadASS::Toy
|
2
|
+
# Create a Toy object using a hash from the API.
|
2
3
|
def initialize(toy_hash)
|
3
|
-
@id = toy_hash['id']
|
4
|
-
@
|
5
|
-
@
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@filters = video_hash[:filters] || []
|
4
|
+
@id = toy_hash['id']
|
5
|
+
@sku = toy_hash['sku']
|
6
|
+
@size = toy_hash['size']
|
7
|
+
@price = toy_hash['price']
|
8
|
+
@weight = toy_hash['weight']
|
9
|
+
@color = toy_hash['color']
|
10
|
+
@colors = [toy_hash['color1'], toy_hash['color2'], toy_hash['color3']]
|
11
|
+
@flop_reason = toy_hash['flop_reason'].capitalize
|
12
|
+
@type = toy_hash['type'].capitalize
|
13
|
+
@cumtube = toy_hash['cumtube']
|
14
|
+
@suction_cup = toy_hash['suction_cup']
|
15
|
+
@images = toy_hash['images'].map { |toy| toy['fullFilename'] }
|
16
16
|
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
BadASS::BAD_DRAGON_SKUS[sku]
|
20
|
+
end
|
21
|
+
|
22
|
+
def cumtube?
|
23
|
+
@cumtube == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
def suction_cup?
|
27
|
+
@suction_cup == 1
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :id
|
31
|
+
attr_reader :sku
|
32
|
+
attr_reader :size
|
33
|
+
attr_reader :price
|
34
|
+
attr_reader :weight
|
35
|
+
attr_reader :color
|
36
|
+
attr_reader :colors
|
37
|
+
attr_reader :flop_reason
|
38
|
+
attr_reader :type
|
39
|
+
attr_reader :images
|
17
40
|
end
|