Class: PostageApp::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#environmentObject

Returns the value of attribute environment.



82
83
84
# File 'lib/postageapp/configuration.rb', line 82

def environment
  @environment
end

#frameworkObject

Returns the value of attribute framework.



81
82
83
# File 'lib/postageapp/configuration.rb', line 81

def framework
  @framework
end

#hostObject

Returns the value of attribute host.



68
69
70
# File 'lib/postageapp/configuration.rb', line 68

def host
  @host
end

#http_open_timeoutObject

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_timeoutObject

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

#loggerObject

Returns the value of attribute logger.



83
84
85
# File 'lib/postageapp/configuration.rb', line 83

def logger
  @logger
end

#portObject

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_rootObject

Returns the value of attribute project_root.



80
81
82
# File 'lib/postageapp/configuration.rb', line 80

def project_root
  @project_root
end

#proxy_hostObject

Returns the value of attribute proxy_host.



70
71
72
# File 'lib/postageapp/configuration.rb', line 70

def proxy_host
  @proxy_host
end

#proxy_passObject

Returns the value of attribute proxy_pass.



73
74
75
# File 'lib/postageapp/configuration.rb', line 73

def proxy_pass
  @proxy_pass
end

#proxy_portObject

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_userObject

Returns the value of attribute proxy_user.



72
73
74
# File 'lib/postageapp/configuration.rb', line 72

def proxy_user
  @proxy_user
end

#recipient_overrideObject

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_resendObject

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

#schemeObject 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

#secureObject Also known as: secure?

Properties ===========================================================



66
67
68
# File 'lib/postageapp/configuration.rb', line 66

def secure
  @secure
end

#verify_certificateObject 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_keyObject

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

#httpObject

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

Returns:

  • (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

Returns:

  • (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

#urlObject

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