Class: Firstclasspostcodes::Configuration
- Inherits:
-
Object
- Object
- Firstclasspostcodes::Configuration
- Defined in:
- lib/firstclasspostcodes/configuration.rb
Instance Attribute Summary collapse
-
#api_key ⇒ String
Defines API keys used with API Key authentications.
-
#base_path ⇒ Object
Defines url base path.
-
#cert_file ⇒ Object
TLS/SSL setting Client certificate file (for client certificate).
-
#content ⇒ Object
Defines the content type requested and returned.
-
#debug ⇒ true, false
Set this to enable/disable debugging.
-
#host ⇒ Object
Defines url host.
-
#key_file ⇒ Object
TLS/SSL setting Client private key file (for client certificate).
-
#logger ⇒ #debug
Defines the logger used for debugging.
-
#protocol ⇒ Object
Defines HTTP protocol to be used.
-
#ssl_ca_cert ⇒ String
TLS/SSL setting Set this to customize the certificate file to verify the peer.
-
#timeout ⇒ Object
The time limit for HTTP request in seconds.
-
#verify_ssl ⇒ true, false
TLS/SSL setting Set this to false to skip verifying SSL certificate when calling API from https server.
-
#verify_ssl_host ⇒ true, false
TLS/SSL setting Set this to false to skip verifying SSL host name Default to true.
Class Method Summary collapse
-
.default ⇒ Object
The default Configuration object.
Instance Method Summary collapse
- #base_url ⇒ Object
- #configure {|_self| ... } ⇒ Object
- #debug? ⇒ Boolean
- #geo_json? ⇒ Boolean
-
#initialize {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
- #to_request_params ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/firstclasspostcodes/configuration.rb', line 77 def initialize @api_key = nil @debug = false @host = "api.firstclasspostcodes.com" @content = "json" @protocol = "https" @base_path = "/data" @timeout = 30 @verify_ssl = true @verify_ssl_host = true @cert_file = nil @key_file = nil @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT) yield(self) if block_given? end |
Instance Attribute Details
#api_key ⇒ String
Defines API keys used with API Key authentications.
11 12 13 |
# File 'lib/firstclasspostcodes/configuration.rb', line 11 def api_key @api_key end |
#base_path ⇒ Object
Defines url base path
23 24 25 |
# File 'lib/firstclasspostcodes/configuration.rb', line 23 def base_path @base_path end |
#cert_file ⇒ Object
TLS/SSL setting Client certificate file (for client certificate)
71 72 73 |
# File 'lib/firstclasspostcodes/configuration.rb', line 71 def cert_file @cert_file end |
#content ⇒ Object
Defines the content type requested and returned
17 18 19 |
# File 'lib/firstclasspostcodes/configuration.rb', line 17 def content @content end |
#debug ⇒ true, false
Set this to enable/disable debugging. When enabled (set to true), HTTP request/response details will be logged with ‘logger.debug` (see the `logger` attribute). Default to false.
36 37 38 |
# File 'lib/firstclasspostcodes/configuration.rb', line 36 def debug @debug end |
#host ⇒ Object
Defines url host
14 15 16 |
# File 'lib/firstclasspostcodes/configuration.rb', line 14 def host @host end |
#key_file ⇒ Object
TLS/SSL setting Client private key file (for client certificate)
75 76 77 |
# File 'lib/firstclasspostcodes/configuration.rb', line 75 def key_file @key_file end |
#logger ⇒ #debug
Defines the logger used for debugging. Default to ‘Rails.logger` (when in Rails) or logging to STDOUT.
29 30 31 |
# File 'lib/firstclasspostcodes/configuration.rb', line 29 def logger @logger end |
#protocol ⇒ Object
Defines HTTP protocol to be used
20 21 22 |
# File 'lib/firstclasspostcodes/configuration.rb', line 20 def protocol @protocol end |
#ssl_ca_cert ⇒ String
TLS/SSL setting Set this to customize the certificate file to verify the peer.
github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
67 68 69 |
# File 'lib/firstclasspostcodes/configuration.rb', line 67 def ssl_ca_cert @ssl_ca_cert end |
#timeout ⇒ Object
The time limit for HTTP request in seconds. Default to 0 (never times out).
40 41 42 |
# File 'lib/firstclasspostcodes/configuration.rb', line 40 def timeout @timeout end |
#verify_ssl ⇒ true, false
Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
TLS/SSL setting Set this to false to skip verifying SSL certificate when calling API from https server. Default to true.
49 50 51 |
# File 'lib/firstclasspostcodes/configuration.rb', line 49 def verify_ssl @verify_ssl end |
#verify_ssl_host ⇒ true, false
Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
TLS/SSL setting Set this to false to skip verifying SSL host name Default to true.
58 59 60 |
# File 'lib/firstclasspostcodes/configuration.rb', line 58 def verify_ssl_host @verify_ssl_host end |
Class Method Details
.default ⇒ Object
The default Configuration object.
94 95 96 |
# File 'lib/firstclasspostcodes/configuration.rb', line 94 def self.default @default ||= Configuration.new end |
Instance Method Details
#base_url ⇒ Object
132 133 134 135 |
# File 'lib/firstclasspostcodes/configuration.rb', line 132 def base_url path = [host, base_path].join("/").gsub(%r{/+}, "/") "#{protocol}://#{path}".sub(%r{/+\z}, "") end |
#configure {|_self| ... } ⇒ Object
98 99 100 |
# File 'lib/firstclasspostcodes/configuration.rb', line 98 def configure yield(self) if block_given? end |
#debug? ⇒ Boolean
102 103 104 |
# File 'lib/firstclasspostcodes/configuration.rb', line 102 def debug? debug end |
#geo_json? ⇒ Boolean
106 107 108 |
# File 'lib/firstclasspostcodes/configuration.rb', line 106 def geo_json? content == "geo+json" end |
#to_request_params ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/firstclasspostcodes/configuration.rb', line 137 def to_request_params params = { headers: { 'x-api-key': api_key, accept: "application/#{content}; q=1.0, application/json; q=0.5", }, timeout: timeout, ssl_verifypeer: verify_ssl, ssl_verifyhost: verify_ssl_host ? 2 : 0, sslcert: cert_file, sslkey: key_file, verbose: debug, } params[:cainfo] = ssl_ca_cert if ssl_ca_cert params end |