Class: SlackMsgr::Configuration

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

Overview

Configuration class handling config variables set on launch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verification_token: nil, client_secret: nil, signing_secret: nil, legacy_token: nil, access_tokens: {}, set_default_token: nil) ⇒ Configuration

rubocop:disable Metrics/ParameterLists



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slack_msgr/configuration.rb', line 13

def initialize( # rubocop:disable Metrics/ParameterLists
  verification_token: nil,
  client_secret: nil,
  signing_secret: nil,
  legacy_token: nil,
  access_tokens: {},
  set_default_token: nil
)
  @verification_token = verification_token
  @client_secret      = client_secret
  @signing_secret     = signing_secret
  @legacy_token       = legacy_token
  @access_tokens      = access_tokens
  @set_default_token  = set_default_token
end

Instance Attribute Details

#access_tokensObject

Returns the value of attribute access_tokens.



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

def access_tokens
  @access_tokens
end

#client_secretObject

Returns the value of attribute client_secret.



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

def client_secret
  @client_secret
end

#legacy_tokenObject

Returns the value of attribute legacy_token.



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

def legacy_token
  @legacy_token
end

#set_default_tokenObject

Returns the value of attribute set_default_token.



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

def set_default_token
  @set_default_token
end

#signing_secretObject

Returns the value of attribute signing_secret.



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

def signing_secret
  @signing_secret
end

#verification_tokenObject

Returns the value of attribute verification_token.



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

def verification_token
  @verification_token
end

Instance Method Details

#clear!Object



29
30
31
32
33
34
35
36
37
# File 'lib/slack_msgr/configuration.rb', line 29

def clear!
  @verification_token = nil
  @client_secret      = nil
  @signing_secret     = nil
  @legacy_token       = nil
  @access_tokens      = {}
  @set_default_token  = nil
  @default_token      = nil
end

#default_tokenObject



39
40
41
# File 'lib/slack_msgr/configuration.rb', line 39

def default_token
  @default_token ||= initialize_default_token
end

#initialize_default_tokenObject



43
44
45
46
47
# File 'lib/slack_msgr/configuration.rb', line 43

def initialize_default_token
  return unless access_tokens&.first

  access_tokens[set_default_token] || access_tokens.first[1]
end

#oauth_access_token(given_token) ⇒ Object



49
50
51
52
53
# File 'lib/slack_msgr/configuration.rb', line 49

def oauth_access_token(given_token)
  token = access_tokens[given_token] || default_token
  ErrorHandling.raise(:configuration_error) unless token
  token
end