Class: WhatsAppNotifier::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



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

def initialize
  @provider = :web_automation
  @web_adapter = WebAdapter.new
  @web_session_path = "tmp/whatsapp_notifier/session.json"
  @bulk_base_delay_seconds = 1.0
  @bulk_jitter_seconds = 0.3
  @bulk_max_recipients = 500
  @bulk_max_attempts = 3
  @bulk_retryable_error_codes = %i[rate_limited network_error temporary_failure].freeze
  @logger = Logger.new($stdout)
  @web_automation_enabled = true
  @warn_on_risky_provider = true
  @authenticate_with = nil
  @current_user_id_resolver = -> { respond_to?(:current_user) && current_user ? current_user.id : nil }
  @parent_controller = "::ApplicationController"
end

Instance Attribute Details

#authenticate_withObject

Returns the value of attribute authenticate_with.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def authenticate_with
  @authenticate_with
end

#bulk_base_delay_secondsObject

Returns the value of attribute bulk_base_delay_seconds.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def bulk_base_delay_seconds
  @bulk_base_delay_seconds
end

#bulk_jitter_secondsObject

Returns the value of attribute bulk_jitter_seconds.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def bulk_jitter_seconds
  @bulk_jitter_seconds
end

#bulk_max_attemptsObject

Returns the value of attribute bulk_max_attempts.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def bulk_max_attempts
  @bulk_max_attempts
end

#bulk_max_recipientsObject

Returns the value of attribute bulk_max_recipients.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def bulk_max_recipients
  @bulk_max_recipients
end

#bulk_retryable_error_codesObject

Returns the value of attribute bulk_retryable_error_codes.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def bulk_retryable_error_codes
  @bulk_retryable_error_codes
end

#current_user_id_resolverObject

Returns the value of attribute current_user_id_resolver.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def current_user_id_resolver
  @current_user_id_resolver
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def logger
  @logger
end

#parent_controllerObject

Returns the value of attribute parent_controller.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def parent_controller
  @parent_controller
end

#providerObject

Returns the value of attribute provider.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def provider
  @provider
end

#warn_on_risky_providerObject

Returns the value of attribute warn_on_risky_provider.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def warn_on_risky_provider
  @warn_on_risky_provider
end

#web_adapterObject

Returns the value of attribute web_adapter.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def web_adapter
  @web_adapter
end

#web_automation_enabledObject

Returns the value of attribute web_automation_enabled.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def web_automation_enabled
  @web_automation_enabled
end

#web_session_pathObject

Returns the value of attribute web_session_path.



5
6
7
# File 'lib/whatsapp_notifier/configuration.rb', line 5

def web_session_path
  @web_session_path
end

Instance Method Details

#validate!Object

Raises:



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

def validate!
  raise ConfigurationError, "provider is required" if provider.nil?
  raise ConfigurationError, "only :web_automation provider is supported" unless provider.to_sym == :web_automation
  raise ConfigurationError, "bulk_max_recipients must be positive" if bulk_max_recipients.to_i <= 0
  raise ConfigurationError, "bulk_max_attempts must be positive" if bulk_max_attempts.to_i <= 0
  raise ConfigurationError, "web_adapter must be configured and respond to send_message, fetch_qr_code, connection_status" unless valid_web_adapter?
end