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) :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

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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

#environmentObject

Returns the value of attribute environment.



60
61
62
# File 'lib/postageapp/configuration.rb', line 60

def environment
  @environment
end

#frameworkObject

Returns the value of attribute framework.



59
60
61
# File 'lib/postageapp/configuration.rb', line 59

def framework
  @framework
end

#hostObject

Returns the value of attribute host.



48
49
50
# File 'lib/postageapp/configuration.rb', line 48

def host
  @host
end

#http_open_timeoutObject

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_timeoutObject

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

#loggerObject

Returns the value of attribute logger.



61
62
63
# File 'lib/postageapp/configuration.rb', line 61

def logger
  @logger
end

#portObject

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_rootObject

Returns the value of attribute project_root.



58
59
60
# File 'lib/postageapp/configuration.rb', line 58

def project_root
  @project_root
end

#protocolObject

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_hostObject

Returns the value of attribute proxy_host.



50
51
52
# File 'lib/postageapp/configuration.rb', line 50

def proxy_host
  @proxy_host
end

#proxy_passObject

Returns the value of attribute proxy_pass.



53
54
55
# File 'lib/postageapp/configuration.rb', line 53

def proxy_pass
  @proxy_pass
end

#proxy_portObject

Returns the value of attribute proxy_port.



51
52
53
# File 'lib/postageapp/configuration.rb', line 51

def proxy_port
  @proxy_port
end

#proxy_userObject

Returns the value of attribute proxy_user.



52
53
54
# File 'lib/postageapp/configuration.rb', line 52

def proxy_user
  @proxy_user
end

#recipient_overrideObject

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_resendObject

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

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

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

#httpObject

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

#urlObject

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