Class: Ovh::Http2sms::Configuration
- Inherits:
-
Object
- Object
- Ovh::Http2sms::Configuration
- Defined in:
- lib/ovh/http2sms/configuration.rb
Overview
Configuration class for OVH HTTP2SMS gem
Constant Summary collapse
- ENV_PREFIX =
Environment variable prefix
"OVH_SMS_"- DEFAULTS =
Default values
{ default_content_type: "application/json", timeout: 15, default_country_code: "33", raise_on_length_error: true, api_endpoint: "https://www.ovh.com/cgi-bin/sms/http2sms.cgi" }.freeze
Instance Attribute Summary collapse
-
#account ⇒ String?
SMS account identifier (ex: sms-xx11111-1).
-
#after_request_callbacks ⇒ Array<Proc>
readonly
Callbacks executed after each request.
-
#api_endpoint ⇒ String
API endpoint URL.
-
#before_request_callbacks ⇒ Array<Proc>
readonly
Callbacks executed before each request.
-
#default_content_type ⇒ String
Default response content type.
-
#default_country_code ⇒ String
Default country code for phone number formatting.
-
#default_sender ⇒ String?
Default sender name.
-
#logger ⇒ Logger?
Optional logger for debugging.
-
#login ⇒ String?
SMS user login.
-
#on_failure_callbacks ⇒ Array<Proc>
readonly
Callbacks executed on failed delivery.
-
#on_success_callbacks ⇒ Array<Proc>
readonly
Callbacks executed on successful delivery.
-
#password ⇒ String?
SMS user password.
-
#raise_on_length_error ⇒ Boolean
Whether to raise errors on message length violations.
-
#timeout ⇒ Integer
HTTP request timeout in seconds.
Instance Method Summary collapse
-
#after_request {|Response| ... } ⇒ void
Register a callback to be executed after each request.
-
#before_request {|Hash| ... } ⇒ void
Register a callback to be executed before each request.
- #blank?(value) ⇒ Boolean
- #build_validation_error_message(missing) ⇒ Object
- #find_missing_credentials ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#initialize_dup(other) ⇒ Object
Ensure callbacks are properly duplicated.
-
#on_failure {|Response| ... } ⇒ void
Register a callback to be executed on failed delivery.
-
#on_success {|Response| ... } ⇒ void
Register a callback to be executed on successful delivery.
-
#reset! ⇒ void
Reset configuration to defaults and environment variables.
-
#valid? ⇒ Boolean
Check if the configuration is valid for making API requests.
-
#validate! ⇒ void
Validate configuration and raise error if invalid.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
73 74 75 |
# File 'lib/ovh/http2sms/configuration.rb', line 73 def initialize reset! end |
Instance Attribute Details
#account ⇒ String?
Returns SMS account identifier (ex: sms-xx11111-1).
20 21 22 |
# File 'lib/ovh/http2sms/configuration.rb', line 20 def account @account end |
#after_request_callbacks ⇒ Array<Proc> (readonly)
Returns Callbacks executed after each request.
53 54 55 |
# File 'lib/ovh/http2sms/configuration.rb', line 53 def after_request_callbacks @after_request_callbacks end |
#api_endpoint ⇒ String
Returns API endpoint URL.
47 48 49 |
# File 'lib/ovh/http2sms/configuration.rb', line 47 def api_endpoint @api_endpoint end |
#before_request_callbacks ⇒ Array<Proc> (readonly)
Returns Callbacks executed before each request.
50 51 52 |
# File 'lib/ovh/http2sms/configuration.rb', line 50 def before_request_callbacks @before_request_callbacks end |
#default_content_type ⇒ String
Returns Default response content type.
32 33 34 |
# File 'lib/ovh/http2sms/configuration.rb', line 32 def default_content_type @default_content_type end |
#default_country_code ⇒ String
Returns Default country code for phone number formatting.
41 42 43 |
# File 'lib/ovh/http2sms/configuration.rb', line 41 def default_country_code @default_country_code end |
#default_sender ⇒ String?
Returns Default sender name.
29 30 31 |
# File 'lib/ovh/http2sms/configuration.rb', line 29 def default_sender @default_sender end |
#logger ⇒ Logger?
Returns Optional logger for debugging.
38 39 40 |
# File 'lib/ovh/http2sms/configuration.rb', line 38 def logger @logger end |
#login ⇒ String?
Returns SMS user login.
23 24 25 |
# File 'lib/ovh/http2sms/configuration.rb', line 23 def login @login end |
#on_failure_callbacks ⇒ Array<Proc> (readonly)
Returns Callbacks executed on failed delivery.
59 60 61 |
# File 'lib/ovh/http2sms/configuration.rb', line 59 def on_failure_callbacks @on_failure_callbacks end |
#on_success_callbacks ⇒ Array<Proc> (readonly)
Returns Callbacks executed on successful delivery.
56 57 58 |
# File 'lib/ovh/http2sms/configuration.rb', line 56 def on_success_callbacks @on_success_callbacks end |
#password ⇒ String?
Returns SMS user password.
26 27 28 |
# File 'lib/ovh/http2sms/configuration.rb', line 26 def password @password end |
#raise_on_length_error ⇒ Boolean
Returns Whether to raise errors on message length violations.
44 45 46 |
# File 'lib/ovh/http2sms/configuration.rb', line 44 def raise_on_length_error @raise_on_length_error end |
#timeout ⇒ Integer
Returns HTTP request timeout in seconds.
35 36 37 |
# File 'lib/ovh/http2sms/configuration.rb', line 35 def timeout @timeout end |
Instance Method Details
#after_request {|Response| ... } ⇒ void
This method returns an undefined value.
Register a callback to be executed after each request
134 135 136 |
# File 'lib/ovh/http2sms/configuration.rb', line 134 def after_request(&block) @after_request_callbacks << block if block_given? end |
#before_request {|Hash| ... } ⇒ void
This method returns an undefined value.
Register a callback to be executed before each request
121 122 123 |
# File 'lib/ovh/http2sms/configuration.rb', line 121 def before_request(&block) @before_request_callbacks << block if block_given? end |
#blank?(value) ⇒ Boolean
193 194 195 |
# File 'lib/ovh/http2sms/configuration.rb', line 193 def blank?(value) value.nil? || value.empty? end |
#build_validation_error_message(missing) ⇒ Object
197 198 199 200 201 |
# File 'lib/ovh/http2sms/configuration.rb', line 197 def (missing) env_vars = missing.map { |m| "#{ENV_PREFIX}#{m.upcase}" }.join(", ") "Missing required configuration: #{missing.join(", ")}. " \ "Set via Ovh::Http2sms.configure block or environment variables (#{env_vars})" end |
#find_missing_credentials ⇒ Object
185 186 187 188 189 190 191 |
# File 'lib/ovh/http2sms/configuration.rb', line 185 def find_missing_credentials missing = [] missing << "account" if blank?(account) missing << "login" if blank?(login) missing << "password" if blank?(password) missing end |
#initialize_dup(other) ⇒ Object
Ensure callbacks are properly duplicated
78 79 80 81 82 83 84 |
# File 'lib/ovh/http2sms/configuration.rb', line 78 def initialize_dup(other) super @before_request_callbacks = other.before_request_callbacks.dup @after_request_callbacks = other.after_request_callbacks.dup @on_success_callbacks = other.on_success_callbacks.dup @on_failure_callbacks = other.on_failure_callbacks.dup end |
#on_failure {|Response| ... } ⇒ void
This method returns an undefined value.
Register a callback to be executed on failed delivery
161 162 163 |
# File 'lib/ovh/http2sms/configuration.rb', line 161 def on_failure(&block) @on_failure_callbacks << block if block_given? end |
#on_success {|Response| ... } ⇒ void
This method returns an undefined value.
Register a callback to be executed on successful delivery
148 149 150 |
# File 'lib/ovh/http2sms/configuration.rb', line 148 def on_success(&block) @on_success_callbacks << block if block_given? end |
#reset! ⇒ void
This method returns an undefined value.
Reset configuration to defaults and environment variables
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/ovh/http2sms/configuration.rb', line 89 def reset! # Set defaults DEFAULTS.each do |key, value| send("#{key}=", value) end # Clear credentials self.account = nil self.login = nil self.password = nil self.default_sender = nil self.logger = nil # Reset callbacks @before_request_callbacks = [] @after_request_callbacks = [] @on_success_callbacks = [] @on_failure_callbacks = [] # Load from environment variables load_from_env end |
#valid? ⇒ Boolean
Check if the configuration is valid for making API requests
168 169 170 171 172 |
# File 'lib/ovh/http2sms/configuration.rb', line 168 def valid? !account.nil? && !account.empty? && !login.nil? && !login.empty? && !password.nil? && !password.empty? end |
#validate! ⇒ void
This method returns an undefined value.
Validate configuration and raise error if invalid
178 179 180 181 182 183 |
# File 'lib/ovh/http2sms/configuration.rb', line 178 def validate! missing = find_missing_credentials return if missing.empty? raise ConfigurationError, (missing) end |