Class: PostageApp::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/postageapp/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



55
56
57
58
59
60
61
62
63
# File 'lib/postageapp/configuration.rb', line 55

def initialize
  @secure = true
  @host = 'api.postageapp.com'
  @http_open_timeout = 5
  @http_read_timeout = 10
  @requests_to_resend = %w( send_message )
  @framework = 'undefined framework'
  @environment = 'production'
end

Instance Attribute Details

#environmentObject

Environment gem is running in



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

def environment
  @environment
end

#frameworkObject

The framework PostageApp gem runs in



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

def framework
  @framework
end

#hostObject

The host to connect to (default: ‘api.postageapp.com’)



10
11
12
# File 'lib/postageapp/configuration.rb', line 10

def host
  @host
end

#http_open_timeoutObject

The HTTP open timeout in seconds (defaults to 2).



29
30
31
# File 'lib/postageapp/configuration.rb', line 29

def http_open_timeout
  @http_open_timeout
end

#http_read_timeoutObject

The HTTP read timeout in seconds (defaults to 5).



32
33
34
# File 'lib/postageapp/configuration.rb', line 32

def http_read_timeout
  @http_read_timeout
end

#loggerObject

The logger used by this gem



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

def logger
  @logger
end

#portObject

Returns the port used to make API calls



85
86
87
# File 'lib/postageapp/configuration.rb', line 85

def port
  @port ||= (secure? ? 443 : 80)
end

#project_rootObject

The file path of the project. This is where logs and failed requests can be stored



44
45
46
# File 'lib/postageapp/configuration.rb', line 44

def project_root
  @project_root
end

#protocolObject

Returns the HTTP protocol used to make API calls



7
8
9
# File 'lib/postageapp/configuration.rb', line 7

def protocol
  @protocol
end

#proxy_hostObject

The hostname of the proxy server (if using a proxy)



17
18
19
# File 'lib/postageapp/configuration.rb', line 17

def proxy_host
  @proxy_host
end

#proxy_passObject

The password for the proxy server (if using proxy)



26
27
28
# File 'lib/postageapp/configuration.rb', line 26

def proxy_pass
  @proxy_pass
end

#proxy_portObject

The port of the proxy server (if using proxy)



20
21
22
# File 'lib/postageapp/configuration.rb', line 20

def proxy_port
  @proxy_port
end

#proxy_userObject

The username for the proxy server (if using proxy)



23
24
25
# File 'lib/postageapp/configuration.rb', line 23

def proxy_user
  @proxy_user
end

#recipient_overrideObject

The email address that all send_message method should address all messages while overriding original addresses



36
37
38
# File 'lib/postageapp/configuration.rb', line 36

def recipient_override
  @recipient_override
end

#requests_to_resendObject

A list of API method names payloads of which are captured and resent in case of service unavailability



40
41
42
# File 'lib/postageapp/configuration.rb', line 40

def requests_to_resend
  @requests_to_resend
end

#secureObject Also known as: secure?

true for https, false for http connections (default: is true)



3
4
5
# File 'lib/postageapp/configuration.rb', line 3

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.



75
76
77
# File 'lib/postageapp/configuration.rb', line 75

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.



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

def api_key=(key)
  @api_key = key
end

#httpObject

Returns a properly config



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/postageapp/configuration.rb', line 95

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



90
91
92
# File 'lib/postageapp/configuration.rb', line 90

def url
  "#{self.protocol}://#{self.host}:#{self.port}"
end