class PostageApp::Configuration
Advanced Options
:port - The port to make HTTP/HTTPS requests (default based on secure option) :scheme - Set to either `http` or `https` (default based on secure option) :requests_to_resend - List of API calls that should be replayed if they fail.
(default: send_message)
Constants
- CONFIG_PARAMS
- HTTPS_PORT_DEFAULT
- HTTP_PORT_DEFAULT
- SCHEME_FOR_SECURE
- SOCKS5_PORT_DEFAULT
Constants ============================================================¶ ↑
Public Class Methods
new()
click to toggle source
Instance Methods =====================================================¶ ↑
# File lib/postageapp/configuration.rb, line 268 def initialize credentials = self.rails_credentials CONFIG_PARAMS.each do |param, config| value = ( config[:sources]&.map { |s| credentials[s] }&.compact&.first || config[:env_vars]&.map { |v| ENV[v] }&.compact&.first ) if (value) if (config[:parse]) instance_variable_set(config[:ivar], config[:parse].call(value)) else instance_variable_set(config[:ivar], value) end else case (config[:default]) when Proc instance_variable_set(config[:ivar], config[:default].call) else instance_variable_set(config[:ivar], config[:default]) end end end end
Public Instance Methods
http()
click to toggle source
Returns a connection aimed at the API endpoint
# File lib/postageapp/configuration.rb, line 315 def http PostageApp::HTTP.connect(self) end
port_default?()
click to toggle source
Returns true if the port used for the API is the default port, otherwise false. 80 for HTTP, 443 for HTTPS.
# File lib/postageapp/configuration.rb, line 296 def port_default? self.port == (self.secure? ? HTTPS_PORT_DEFAULT : HTTP_PORT_DEFAULT) end
proxy?()
click to toggle source
Returns true if a proxy is defined, otherwise false.
# File lib/postageapp/configuration.rb, line 301 def proxy? self.proxy_host and self.proxy_host.match(/\A\S+\z/) end
url()
click to toggle source
Returns the endpoint URL to make API calls
# File lib/postageapp/configuration.rb, line 306 def url '%s://%s%s' % [ self.scheme, self.host, self.port_default? ? '' : (':%d' % self.port) ] end
Protected Instance Methods
rails_credentials()
click to toggle source
# File lib/postageapp/configuration.rb, line 320 def rails_credentials if (PostageApp::Env.rails_with_encrypted_credentials?) Rails.application.credentials.postageapp end or { } end