Class: BadASS::Client
- Inherits:
-
Object
- Object
- BadASS::Client
- Defined in:
- lib/badass/client.rb
Instance Attribute Summary collapse
-
#toys ⇒ Object
readonly
Returns the value of attribute toys.
Instance Method Summary collapse
-
#initialize(refresh_time: 600) ⇒ Client
constructor
Creates a client to do operations.
Constructor Details
#initialize(refresh_time: 600) ⇒ Client
Creates a client to do operations. Takes a :refresh_time argument to define how often the toy list should be refreshed.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/badass/client.rb', line 4 def initialize(refresh_time: 600) Thread.new do @toys = [] loop do page = 1 toy_list = [] loop do 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"))) page += 1 newtoys['toys'].each do |toy| toy_list << BadASS::Toy.new(toy) end break if page > newtoys['totalPages'] end @toys = toy_list sleep(refresh_time) end end end |
Instance Attribute Details
#toys ⇒ Object (readonly)
Returns the value of attribute toys.
24 25 26 |
# File 'lib/badass/client.rb', line 24 def toys @toys end |