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) :protocol - 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)
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.
-
#protocol ⇒ Object
Returns the HTTP protocol used to make API calls.
-
#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 value of attribute proxy_port.
-
#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.
-
#secure ⇒ Object
(also: #secure?)
Returns the value of attribute secure.
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 properly configured Net::HTTP connection.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#url ⇒ Object
Returns the endpoint URL to make API calls.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/postageapp/configuration.rb', line 63 def initialize @secure = true @host = 'api.postageapp.com' @http_open_timeout = 5 @http_read_timeout = 10 @requests_to_resend = %w[ send_message ] @framework = 'Ruby' @environment = 'production' end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
60 61 62 |
# File 'lib/postageapp/configuration.rb', line 60 def environment @environment end |
#framework ⇒ Object
Returns the value of attribute framework.
59 60 61 |
# File 'lib/postageapp/configuration.rb', line 59 def framework @framework end |
#host ⇒ Object
Returns the value of attribute host.
48 49 50 |
# File 'lib/postageapp/configuration.rb', line 48 def host @host end |
#http_open_timeout ⇒ Object
Returns the value of attribute http_open_timeout.
54 55 56 |
# File 'lib/postageapp/configuration.rb', line 54 def http_open_timeout @http_open_timeout end |
#http_read_timeout ⇒ Object
Returns the value of attribute http_read_timeout.
55 56 57 |
# File 'lib/postageapp/configuration.rb', line 55 def http_read_timeout @http_read_timeout end |
#logger ⇒ Object
Returns the value of attribute logger.
61 62 63 |
# File 'lib/postageapp/configuration.rb', line 61 def logger @logger end |
#port ⇒ Object
Returns the port used to make API calls
97 98 99 |
# File 'lib/postageapp/configuration.rb', line 97 def port @port ||= (secure? ? 443 : 80) end |
#project_root ⇒ Object
Returns the value of attribute project_root.
58 59 60 |
# File 'lib/postageapp/configuration.rb', line 58 def project_root @project_root end |
#protocol ⇒ Object
Returns the HTTP protocol used to make API calls
92 93 94 |
# File 'lib/postageapp/configuration.rb', line 92 def protocol @protocol ||= (secure? ? 'https' : 'http') end |
#proxy_host ⇒ Object
Returns the value of attribute proxy_host.
50 51 52 |
# File 'lib/postageapp/configuration.rb', line 50 def proxy_host @proxy_host end |
#proxy_pass ⇒ Object
Returns the value of attribute proxy_pass.
53 54 55 |
# File 'lib/postageapp/configuration.rb', line 53 def proxy_pass @proxy_pass end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
51 52 53 |
# File 'lib/postageapp/configuration.rb', line 51 def proxy_port @proxy_port end |
#proxy_user ⇒ Object
Returns the value of attribute proxy_user.
52 53 54 |
# File 'lib/postageapp/configuration.rb', line 52 def proxy_user @proxy_user end |
#recipient_override ⇒ Object
Returns the value of attribute recipient_override.
56 57 58 |
# File 'lib/postageapp/configuration.rb', line 56 def recipient_override @recipient_override end |
#requests_to_resend ⇒ Object
Returns the value of attribute requests_to_resend.
57 58 59 |
# File 'lib/postageapp/configuration.rb', line 57 def requests_to_resend @requests_to_resend end |
#secure ⇒ Object Also known as: secure?
Returns the value of attribute secure.
46 47 48 |
# File 'lib/postageapp/configuration.rb', line 46 def secure @secure 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.
87 88 89 |
# File 'lib/postageapp/configuration.rb', line 87 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.
81 82 83 |
# File 'lib/postageapp/configuration.rb', line 81 def api_key=(key) @api_key = key end |
#http ⇒ Object
Returns a properly configured Net::HTTP connection
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/postageapp/configuration.rb', line 107 def http http = Net::HTTP::Proxy( self.proxy_host, self.proxy_port, self.proxy_user, self.proxy_pass ).new(self.host, self.port) http.read_timeout = self.http_read_timeout http.open_timeout = self.http_open_timeout http.use_ssl = self.secure? http end |
#url ⇒ Object
Returns the endpoint URL to make API calls
102 103 104 |
# File 'lib/postageapp/configuration.rb', line 102 def url "#{self.protocol}://#{self.host}:#{self.port}" end |