badass 0.0.4 → 0.0.5
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 +24 -9
- data/lib/badass/client.rb +11 -19
- data/lib/badass/sale.rb +7 -0
- data/lib/badass/toy.rb +20 -0
- 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: '0580bae8125e3617dc67f8d4af1ddac75074a1ddbcf904a73a0bf4a86ea79fb5'
|
4
|
+
data.tar.gz: 14197b74f3bbb0c229d6ee3329d0033acc88cc318c75fdb6ec083e62eb92dc0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0536b342f82207dfcd831042ff07e11038cde4e550910eda2c256e6d31bbd1201b124cebfd5afc9e00fbf3075de7d6f65e5c0278d8f9d056ad8de887ece4b675
|
7
|
+
data.tar.gz: 4f412703af4a0d5c5ed01b829d8efc34f35d452487f7a4e23ab6524824b4f84591b835fd1ef623721fd8d29c6bf2b8c2dad102f947b2193871437460a86b9874
|
data/lib/badass.rb
CHANGED
@@ -1,24 +1,39 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
3
|
require 'date'
|
4
|
-
|
5
|
-
#
|
4
|
+
# @todo Add rspec testing.
|
5
|
+
# Contains a few constants used across BD's site, and a few helper methods.
|
6
6
|
module BadASS
|
7
|
+
# A hash of API mappings of number to firmness.
|
7
8
|
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
|
9
|
+
# A hash of API mappings to correctly capitalize a size.
|
8
10
|
SIZES = { 'onesize' => 'One-Size', 'mini' => 'Mini', 'small' => 'Small', 'medium' => 'Medium', 'large' => 'Large', 'extralarge' => 'Extra Large' }.freeze
|
11
|
+
# A hash of API mappings of toy SKU to toy name.
|
12
|
+
BAD_DRAGON_SKUS = JSON.parse(Net::HTTP.get(URI('https://bad-dragon.com/api/inventory-toy/product-list'))).map { |toy| { toy['sku'] => toy['name'] } }.reduce({}, :update)
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
@baddragon_skus[toy['sku']] = toy['name']
|
13
|
-
end
|
14
|
-
BAD_DRAGON_SKUS = @baddragon_skus.freeze
|
15
|
-
|
16
|
-
# Gets the current sales. Returns a hash of sales.
|
14
|
+
# Get the current sales on the site.
|
15
|
+
# @return [Array<BadASS::Sale>]
|
17
16
|
def self.sales
|
18
17
|
JSON.parse(Net::HTTP.get(URI('https://bad-dragon.com/api/sales'))).map do |sale|
|
19
18
|
BadASS::Sale.new(sale)
|
20
19
|
end
|
21
20
|
end
|
21
|
+
|
22
|
+
# Get the current drops on the site.
|
23
|
+
# @return [Array<BadASS::Toy>]
|
24
|
+
def self.drops
|
25
|
+
page = 1
|
26
|
+
toy_list = []
|
27
|
+
loop do
|
28
|
+
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")))
|
29
|
+
page += 1
|
30
|
+
newtoys['toys'].each do |toy|
|
31
|
+
toy_list << BadASS::Toy.new(toy)
|
32
|
+
end
|
33
|
+
break if page > newtoys['totalPages']
|
34
|
+
end
|
35
|
+
toy_list
|
36
|
+
end
|
22
37
|
end
|
23
38
|
|
24
39
|
require 'badass/client'
|
data/lib/badass/client.rb
CHANGED
@@ -1,25 +1,17 @@
|
|
1
|
+
# A client to periodically check for new toys and news to avoid spamming the BD API directly.
|
1
2
|
class BadASS::Client
|
2
|
-
# Creates a client to do operations.
|
3
|
-
#
|
4
|
-
def initialize(
|
3
|
+
# Creates a client to do API operations.
|
4
|
+
# @param refresh_rate [Integer] the rate at which the Client should refresh its list of toys.
|
5
|
+
def initialize(refresh_rate: 600)
|
5
6
|
Thread.new do
|
6
|
-
@toys =
|
7
|
-
|
8
|
-
|
9
|
-
toy_list = []
|
10
|
-
loop do
|
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
|
13
|
-
newtoys['toys'].each do |toy|
|
14
|
-
toy_list << BadASS::Toy.new(toy)
|
15
|
-
end
|
16
|
-
break if page > newtoys['totalPages']
|
17
|
-
end
|
18
|
-
@toys = toy_list
|
19
|
-
sleep(refresh_time)
|
20
|
-
end
|
7
|
+
@toys = BadASS.drops
|
8
|
+
@sale = BadASS.sales
|
9
|
+
sleep(refresh_rate)
|
21
10
|
end
|
22
11
|
end
|
23
12
|
|
24
|
-
|
13
|
+
# @return [Array<BadASS::Toy>] the current drops
|
14
|
+
attr_reader :drops
|
15
|
+
# @return [Array<BadASS::Sale>] the current BD sales
|
16
|
+
attr_reader :sales
|
25
17
|
end
|
data/lib/badass/sale.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# Base class containing a Bad Dragon sale and it's attributes.
|
1
2
|
class BadASS::Sale
|
2
3
|
# Create a Sale object using a hash from the API.
|
4
|
+
# @param [Hash]
|
3
5
|
def initialize(sale_hash)
|
4
6
|
@title = sale_hash['title']
|
5
7
|
@description = JSON.parse(sale_hash['content'])['blocks'].map { |x| x['text'] }.join("\n")
|
@@ -8,9 +10,14 @@ class BadASS::Sale
|
|
8
10
|
@end_date = Date.rfc3339(sale_hash['endDate']) rescue nil
|
9
11
|
end
|
10
12
|
|
13
|
+
# @return [String] the title of the sale
|
11
14
|
attr_reader :title
|
15
|
+
# @return [String] the description of the sale
|
12
16
|
attr_reader :description
|
17
|
+
# @return [String] the image URL of the sale
|
13
18
|
attr_reader :image
|
19
|
+
# @return [Date] the start date of the sale
|
14
20
|
attr_reader :start_date
|
21
|
+
# @return [Date] the end date of the sale
|
15
22
|
attr_reader :end_date
|
16
23
|
end
|
data/lib/badass/toy.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# Base class containing a Bad Dragon toy and it's attributes.
|
1
2
|
class BadASS::Toy
|
2
3
|
# Create a Toy object using a hash from the API.
|
4
|
+
# @param [Hash]
|
3
5
|
def initialize(toy_hash)
|
4
6
|
@id = toy_hash['id']
|
5
7
|
@sku = toy_hash['sku']
|
@@ -16,30 +18,48 @@ class BadASS::Toy
|
|
16
18
|
@images = toy_hash['images'].map { |toy| toy['fullFilename'] }
|
17
19
|
end
|
18
20
|
|
21
|
+
# Gets the full product name of the toy.
|
22
|
+
# @return [String]
|
19
23
|
def name
|
20
24
|
BadASS::BAD_DRAGON_SKUS[@sku]
|
21
25
|
end
|
22
26
|
|
27
|
+
# Checks if a toy has a cumtube or not.
|
28
|
+
# @return [Boolean]
|
23
29
|
def cumtube?
|
24
30
|
@cumtube == 1
|
25
31
|
end
|
26
32
|
|
33
|
+
# Checks if a toy has a suction cup or not.
|
34
|
+
# @return [Boolean]
|
27
35
|
def suction_cup?
|
28
36
|
@suction_cup == 1
|
29
37
|
end
|
30
38
|
|
39
|
+
# Gets the firmness of a toy.
|
40
|
+
# @return [String]
|
31
41
|
def firmness
|
32
42
|
BadASS::FIRMNESSES[@firmness]
|
33
43
|
end
|
34
44
|
|
45
|
+
# @return [Integer] the ID of the toy
|
35
46
|
attr_reader :id
|
47
|
+
# @return [String] the SKU of the toy
|
36
48
|
attr_reader :sku
|
49
|
+
# @return [String] the size of the toy
|
37
50
|
attr_reader :size
|
51
|
+
# @return [Integer] the price of the toy
|
38
52
|
attr_reader :price
|
53
|
+
# @return [Float] the weight of the toy
|
39
54
|
attr_reader :weight
|
55
|
+
# @return [String] the color of the toy
|
40
56
|
attr_reader :color
|
57
|
+
# @return [Array(Integer, Integer, Integer)] the 3 colors of the toy
|
41
58
|
attr_reader :colors
|
59
|
+
# @return [String] the flop reason of a toy
|
42
60
|
attr_reader :flop_reason
|
61
|
+
# @return [String] the type of a toy
|
43
62
|
attr_reader :type
|
63
|
+
# @return [Array] the image URLs of a toy
|
44
64
|
attr_reader :images
|
45
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: badass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- charagarlnad
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple Bad Dragon Assistant Gem.
|
14
14
|
email: ''
|