class Datumfactory::Util::HTTP
Constants
- ERRORS
- HEADERS
Attributes
config[R]
Public Class Methods
new(config)
click to toggle source
# File lib/datumfactory/util/http.rb, line 33 def initialize(config) @config = config end
Public Instance Methods
get(endpoint)
click to toggle source
# File lib/datumfactory/util/http.rb, line 37 def get(endpoint) response = http_connection.get(endpoint) debug { format('http method=GET path=%s code=%d', endpoint.dump, response.code) } response end
post(endpoint, payload, headers = nil)
click to toggle source
# File lib/datumfactory/util/http.rb, line 43 def post(endpoint, payload, headers = nil) response = http_connection.post(endpoint, compress(payload.to_json), http_headers(headers)) debug { format('http method=POST path=%s code=%d', endpoint.dump, response.code) } response end
Private Instance Methods
compress(string, level = Zlib::DEFAULT_COMPRESSION)
click to toggle source
# File lib/datumfactory/util/http.rb, line 84 def compress(string, level = Zlib::DEFAULT_COMPRESSION) Zlib::Deflate.deflate(string, level) end
http_connection()
click to toggle source
# File lib/datumfactory/util/http.rb, line 53 def http_connection setup_http_connection end
http_headers(headers = nil)
click to toggle source
# File lib/datumfactory/util/http.rb, line 57 def http_headers(headers = nil) {}.tap do |hash| hash.merge!(HEADERS) hash.merge!({ 'X-API-Key' => config[:api_key].to_s }) hash.merge!(headers) if headers end end
setup_http_connection()
click to toggle source
# File lib/datumfactory/util/http.rb, line 65 def setup_http_connection http_class = Net::HTTP::Proxy(config[:'connection.proxy_host'], config[:'connection.proxy_port'], config[:'connection.proxy_user'], config[:'connection.proxy_pass']) http = http_class.new(config[:'connection.host'], config.connection_port) http.read_timeout = config[:'connection.http_read_timeout'] http.open_timeout = config[:'connection.http_open_timeout'] if config[:'connection.secure'] http.use_ssl = true http.ca_file = config.ca_bundle_path http.verify_mode = OpenSSL::SSL::VERIFY_PEER else http.use_ssl = false end http end