Class: Nexaas::Throttle::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/nexaas/throttle/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



48
49
50
51
52
53
54
55
56
# File 'lib/nexaas/throttle/configuration.rb', line 48

def initialize
  @throttle = true
  @track = true
  @period = 1.minute
  @limit = 60
  @request_identifier = nil
  @redis_options = default_redis_options
  @ignored_user_agents = nil
end

Instance Attribute Details

#ignored_user_agentsArray

Ignores how many User-Agent the application wants, in case of other applications from the same organization. Example: [/[Gg]oogle/, /Amazon/]

Returns:

  • (Array)


43
44
45
# File 'lib/nexaas/throttle/configuration.rb', line 43

def ignored_user_agents
  @ignored_user_agents
end

#limitInteger

How many requests a consumer can do during a window until he starts being throttled. Example: 60

Returns:

  • (Integer)


20
21
22
# File 'lib/nexaas/throttle/configuration.rb', line 20

def limit
  @limit
end

#periodInteger

The size of the throttle window. Example: 1.minute, 1.hour, 60(s)

Returns:

  • (Integer)


15
16
17
# File 'lib/nexaas/throttle/configuration.rb', line 15

def period
  @period
end

#redis_optionsHash

Redis hash configuration with the following default values:

- host      => localhost
- port      => 6379
- db        => 0
- namespace => nexaas:throttle

Returns:

  • (Hash)


38
39
40
# File 'lib/nexaas/throttle/configuration.rb', line 38

def redis_options
  @redis_options
end

#request_identifierClass

The class that will handle request identification. Each application handle with different domains on identifying a request, so they have to provide information on who is the requester based on their domain. This class MUST have the following interface: MyRequestIdentifier#initialize(request) MyRequestIdentifier#token Where MyRequestIdentifier#token must be a UNIQUE identifier from the requester.

Returns:

  • (Class)


30
31
32
# File 'lib/nexaas/throttle/configuration.rb', line 30

def request_identifier
  @request_identifier
end

#throttleBoolean Also known as: throttleable?

Whether or not requests are throttled.

Returns:

  • (Boolean)


6
7
8
# File 'lib/nexaas/throttle/configuration.rb', line 6

def throttle
  @throttle
end

#trackBoolean Also known as: trackable?

Whether or not requests are tracked.

Returns:

  • (Boolean)


10
11
12
# File 'lib/nexaas/throttle/configuration.rb', line 10

def track
  @track
end

Instance Method Details

#check!Object



58
59
60
61
62
# File 'lib/nexaas/throttle/configuration.rb', line 58

def check!
  required_options.each do |option|
    raise ArgumentError, "You must provide a `#{option}` configuration." if send(option).blank?
  end
end