Class: TelegramWorkflow::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_workflow/config.rb

Constant Summary collapse

REQUIRED_PARAMS =
%i(session_store start_action api_token)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/telegram_workflow/config.rb', line 29

def initialize
  @client = TelegramWorkflow::Client
  @webhook_params = {}

  if defined?(Rails)
    @session_store = Rails.cache
    @logger = Rails.logger
  else
    @session_store = TelegramWorkflow::Stores::InMemory.new
    @logger = Logger.new(STDOUT)
  end
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def api_token
  @api_token
end

#clientObject

Returns the value of attribute client.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def client
  @client
end

#loggerObject

Returns the value of attribute logger.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def logger
  @logger
end

#session_storeObject

Returns the value of attribute session_store.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def session_store
  @session_store
end

#start_actionObject

Returns the value of attribute start_action.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def start_action
  @start_action
end

#webhook_paramsObject

Returns the value of attribute webhook_params.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def webhook_params
  @webhook_params
end

#webhook_urlObject

Returns the value of attribute webhook_url.



24
25
26
# File 'lib/telegram_workflow/config.rb', line 24

def webhook_url
  @webhook_url
end

Instance Method Details

#tagged_logger?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/telegram_workflow/config.rb', line 42

def tagged_logger?
  @tagged_logger ||= @logger.respond_to?(:tagged)
end

#verify!Object



46
47
48
49
50
51
52
# File 'lib/telegram_workflow/config.rb', line 46

def verify!
  blank_params = REQUIRED_PARAMS.select { |p| send(p).nil? }

  if blank_params.any?
    raise TelegramWorkflow::Errors::MissingConfiguration, blank_params
  end
end