Class: LightrateClient::ConsumeTokensRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/lightrate_client/types.rb

Overview

Request types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(application_id:, operation: nil, path: nil, http_method: nil, user_identifier:, tokens_requested:, tokens_requested_for_default_bucket_match: nil, timestamp: nil) ⇒ ConsumeTokensRequest

Returns a new instance of ConsumeTokensRequest.



8
9
10
11
12
13
14
15
16
17
# File 'lib/lightrate_client/types.rb', line 8

def initialize(application_id:, operation: nil, path: nil, http_method: nil, user_identifier:, tokens_requested:, tokens_requested_for_default_bucket_match: nil, timestamp: nil)
  @application_id = application_id
  @operation = operation
  @path = path
  @http_method = http_method
  @user_identifier = user_identifier
  @tokens_requested = tokens_requested
  @tokens_requested_for_default_bucket_match = tokens_requested_for_default_bucket_match
  @timestamp = timestamp || Time.now
end

Instance Attribute Details

#application_idObject

Returns the value of attribute application_id.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def application_id
  @application_id
end

#http_methodObject

Returns the value of attribute http_method.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def http_method
  @http_method
end

#operationObject

Returns the value of attribute operation.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def operation
  @operation
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def path
  @path
end

#timestampObject

Returns the value of attribute timestamp.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def timestamp
  @timestamp
end

#tokens_requestedObject

Returns the value of attribute tokens_requested.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def tokens_requested
  @tokens_requested
end

#tokens_requested_for_default_bucket_matchObject

Returns the value of attribute tokens_requested_for_default_bucket_match.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def tokens_requested_for_default_bucket_match
  @tokens_requested_for_default_bucket_match
end

#user_identifierObject

Returns the value of attribute user_identifier.



6
7
8
# File 'lib/lightrate_client/types.rb', line 6

def user_identifier
  @user_identifier
end

Instance Method Details

#to_hObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lightrate_client/types.rb', line 19

def to_h
  {
    applicationId: @application_id,
    operation: @operation,
    path: @path,
    httpMethod: @http_method,
    userIdentifier: @user_identifier,
    tokensRequested: @tokens_requested,
    tokensRequestedForDefaultBucketMatch: @tokens_requested_for_default_bucket_match,
    timestamp: @timestamp
  }.compact
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/lightrate_client/types.rb', line 32

def valid?
  return false if @application_id.nil? || @application_id.empty?
  return false if @user_identifier.nil? || @user_identifier.empty?
  return false if @tokens_requested.nil? || @tokens_requested <= 0
  return false if @operation.nil? && @path.nil?
  return false if @operation && @path
  return false if @path && @http_method.nil?

  true
end