Class: LHC::Throttle

Inherits:
Interceptor show all
Defined in:
lib/lhc/interceptors/throttle.rb

Defined Under Namespace

Classes: OutOfQuota

Class Attribute Summary collapse

Attributes inherited from Interceptor

#request

Instance Method Summary collapse

Methods inherited from Interceptor

#after_request, #before_raw_request, #before_response, dup, #initialize, #response

Constructor Details

This class inherits a constructor from LHC::Interceptor

Class Attribute Details

.trackObject

Returns the value of attribute track.



11
12
13
# File 'lib/lhc/interceptors/throttle.rb', line 11

def track
  @track
end

Instance Method Details

#after_responseObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lhc/interceptors/throttle.rb', line 22

def after_response
  options = response.request.options.dig(:throttle)
  return unless options
  return unless options.dig(:track)
  self.class.track ||= {}
  self.class.track[options.dig(:provider)] = {
    limit: limit(options: options[:limit], response: response),
    remaining: remaining(options: options[:remaining], response: response),
    expires: expires(options: options[:expires], response: response)
  }
end

#before_requestObject



14
15
16
17
18
19
20
# File 'lib/lhc/interceptors/throttle.rb', line 14

def before_request
  options = request.options.dig(:throttle)
  return unless options
  break_options = options.dig(:break)
  return unless break_options
  break_when_quota_reached! if break_options.match('%')
end