Class: Client
- Inherits:
-
Struct
- Object
- Struct
- Client
- Extended by:
- GluttonRatelimit
- Defined in:
- lib/client.rb
Constant Summary collapse
- MUTEX =
Mutex.new
- OUTPUT =
Mutex.new
Instance Attribute Summary collapse
-
#state ⇒ Object
Returns the value of attribute state.
-
#store ⇒ Object
Returns the value of attribute store.
-
#token ⇒ Object
Returns the value of attribute token.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
- #get(path, after: 0, page_size: 5000) ⇒ Object
- #output(object) ⇒ Object
- #process(model, after = 0) ⇒ Object
Instance Attribute Details
#state ⇒ Object
Returns the value of attribute state
6 7 8 |
# File 'lib/client.rb', line 6 def state @state end |
#store ⇒ Object
Returns the value of attribute store
6 7 8 |
# File 'lib/client.rb', line 6 def store @store end |
#token ⇒ Object
Returns the value of attribute token
6 7 8 |
# File 'lib/client.rb', line 6 def token @token end |
#verbose ⇒ Object
Returns the value of attribute verbose
6 7 8 |
# File 'lib/client.rb', line 6 def verbose @verbose end |
Class Method Details
.requests_per_second=(rps) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/client.rb', line 11 def self.requests_per_second=(rps) rps = rps.to_r if rps > 0 rate_limit :get, rps.numerator, rps.denominator end end |
Instance Method Details
#get(path, after: 0, page_size: 5000) ⇒ Object
48 49 50 |
# File 'lib/client.rb', line 48 def get(path, after: 0, page_size: 5000) connection.get("/api/2.0/#{path}", after: after, page_size: page_size).body end |
#output(object) ⇒ Object
42 43 44 45 46 |
# File 'lib/client.rb', line 42 def output(object) OUTPUT.synchronize do puts JSON.generate(object) end end |
#process(model, after = 0) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/client.rb', line 18 def process(model, after = 0) MUTEX.synchronize do self.state ||= Concurrent::Hash.new() end state['value'] ||= Concurrent::Hash.new() return unless model.path after = state['value'][model.stream].to_i records = get(model.path, after: after) if Array(records['data']).flatten.compact.any? records['data'].peach(50) do |record| model.new(record, self).records.flatten.each do |model_record| output model_record end end state['value'][model.stream] = records['version']['max'] end output(type: :STATE, value: state) end |