Class: PostageApp::Configuration
- Inherits:
-
Object
- Object
- PostageApp::Configuration
- Defined in:
- lib/postageapp/configuration.rb
Overview
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)
Constant Summary collapse
- HOST_DEFAULT =
Constants ============================================================
'api.postageapp.com'.freeze
- SOCKS5_PORT_DEFAULT =
1080
- HTTP_PORT_DEFAULT =
80
- HTTPS_PORT_DEFAULT =
443
- SCHEME_FOR_SECURE =
{ true => 'https'.freeze, false => 'http'.freeze }.freeze
- PATH_DEFAULT =
'/'.freeze
- FRAMEWORK_DEFAULT =
'Ruby'.freeze
- ENVIRONMENT_DEFAULT =
'production'.freeze
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#framework ⇒ Object
Returns the value of attribute framework.
-
#host ⇒ Object
Returns the value of attribute host.
-
#http_open_timeout ⇒ Object
Returns the value of attribute http_open_timeout.
-
#http_read_timeout ⇒ Object
Returns the value of attribute http_read_timeout.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#port ⇒ Object
Returns the port used to make API calls.
-
#project_root ⇒ Object
Returns the value of attribute project_root.
-
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
-
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
-
#proxy_port ⇒ Object
Returns the port used to connect via SOCKS5.
-
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
-
#recipient_override ⇒ Object
Returns the value of attribute recipient_override.
-
#requests_to_resend ⇒ Object
Returns the value of attribute requests_to_resend.
-
#scheme ⇒ Object
(also: #protocol)
Returns the HTTP scheme used to make API calls.
-
#secure ⇒ Object
(also: #secure?)
Properties ===========================================================.
-
#verify_certificate ⇒ Object
(also: #verify_certificate?)
Returns the value of attribute verify_certificate.
Instance Method Summary collapse
-
#api_key ⇒ Object
Returns the API key used to make API calls.
-
#api_key=(key) ⇒ Object
Assign which API key is used to make API calls.
-
#http ⇒ Object
Returns a connection aimed at the API endpoint.
-
#initialize ⇒ Configuration
constructor
Instance Methods =====================================================.
- #port_default? ⇒ Boolean
- #proxy? ⇒ Boolean
-
#url ⇒ Object
Returns the endpoint URL to make API calls.
Constructor Details
#initialize ⇒ Configuration
Instance Methods =====================================================
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/postageapp/configuration.rb', line 87 def initialize @secure = true @verify_certificate = true @host = ENV['POSTAGEAPP_HOST'] || HOST_DEFAULT @proxy_port = SOCKS5_PORT_DEFAULT @http_open_timeout = 5 @http_read_timeout = 10 @requests_to_resend = %w[ send_message ] @framework = FRAMEWORK_DEFAULT @environment = ENVIRONMENT_DEFAULT end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
82 83 84 |
# File 'lib/postageapp/configuration.rb', line 82 def environment @environment end |
#framework ⇒ Object
Returns the value of attribute framework.
81 82 83 |
# File 'lib/postageapp/configuration.rb', line 81 def framework @framework end |
#host ⇒ Object
Returns the value of attribute host.
68 69 70 |
# File 'lib/postageapp/configuration.rb', line 68 def host @host end |
#http_open_timeout ⇒ Object
Returns the value of attribute http_open_timeout.
76 77 78 |
# File 'lib/postageapp/configuration.rb', line 76 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
Returns the value of attribute http_read_timeout.
77 78 79 |
# File 'lib/postageapp/configuration.rb', line 77 def http_read_timeout @http_read_timeout end |
#logger ⇒ Object
Returns the value of attribute logger.
83 84 85 |
# File 'lib/postageapp/configuration.rb', line 83 def logger @logger end |
#port ⇒ Object
Returns the port used to make API calls
140 141 142 |
# File 'lib/postageapp/configuration.rb', line 140 def port @port ||= (self.secure? ? HTTPS_PORT_DEFAULT : HTTP_PORT_DEFAULT) end |
#project_root ⇒ Object
Returns the value of attribute project_root.
80 81 82 |
# File 'lib/postageapp/configuration.rb', line 80 def project_root @project_root end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
70 71 72 |
# File 'lib/postageapp/configuration.rb', line 70 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
73 74 75 |
# File 'lib/postageapp/configuration.rb', line 73 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
Returns the port used to connect via SOCKS5
145 146 147 |
# File 'lib/postageapp/configuration.rb', line 145 def proxy_port @proxy_port ||= SOCKS5_PORT_DEFAULT end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
72 73 74 |
# File 'lib/postageapp/configuration.rb', line 72 def proxy_user @proxy_user end |
#recipient_override ⇒ Object
Returns the value of attribute recipient_override.
78 79 80 |
# File 'lib/postageapp/configuration.rb', line 78 def recipient_override @recipient_override end |
#requests_to_resend ⇒ Object
Returns the value of attribute requests_to_resend.
79 80 81 |
# File 'lib/postageapp/configuration.rb', line 79 def requests_to_resend @requests_to_resend end |
#scheme ⇒ Object Also known as: protocol
Returns the HTTP scheme used to make API calls
132 133 134 |
# File 'lib/postageapp/configuration.rb', line 132 def scheme @scheme ||= SCHEME_FOR_SECURE[self.secure?] end |
#secure ⇒ Object Also known as: secure?
Properties ===========================================================
66 67 68 |
# File 'lib/postageapp/configuration.rb', line 66 def secure @secure end |
#verify_certificate ⇒ Object Also known as: verify_certificate?
Returns the value of attribute verify_certificate.
75 76 77 |
# File 'lib/postageapp/configuration.rb', line 75 def verify_certificate @verify_certificate end |
Instance Method Details
#api_key ⇒ Object
Returns the API key used to make API calls. Can be specified as the ‘POSTAGEAPP_API_KEY` environment variable.
127 128 129 |
# File 'lib/postageapp/configuration.rb', line 127 def api_key @api_key ||= ENV['POSTAGEAPP_API_KEY'] end |
#api_key=(key) ⇒ Object
Assign which API key is used to make API calls. Can also be specified using the ‘POSTAGEAPP_API_KEY` environment variable.
121 122 123 |
# File 'lib/postageapp/configuration.rb', line 121 def api_key=(key) @api_key = key end |
#http ⇒ Object
Returns a connection aimed at the API endpoint
159 160 161 |
# File 'lib/postageapp/configuration.rb', line 159 def http PostageApp::HTTP.connect(self) end |
#port_default? ⇒ Boolean
107 108 109 110 111 112 113 |
# File 'lib/postageapp/configuration.rb', line 107 def port_default? if (self.secure?) self.port == HTTPS_PORT_DEFAULT else self.port == HTTP_PORT_DEFAULT end end |
#proxy? ⇒ Boolean
115 116 117 |
# File 'lib/postageapp/configuration.rb', line 115 def proxy? self.proxy_host and self.proxy_host.match(/\A\S+\z/) end |
#url ⇒ Object
Returns the endpoint URL to make API calls
150 151 152 153 154 155 156 |
# File 'lib/postageapp/configuration.rb', line 150 def url '%s://%s%s' % [ self.scheme, self.host, self.port_default? ? '' : (':%d' % self.port) ] end |