class Grenache::Http::HttpClient

Public Class Methods

new(config) click to toggle source
# File lib/grenache/http/http_client.rb, line 6
def initialize config
  @config = config
end

Public Instance Methods

request(uri, body, params = {}) click to toggle source
# File lib/grenache/http/http_client.rb, line 10
def request uri, body, params = {}
  uri = URI.parse(uri)
  options = {body: body}

  if params[:timeout]
    options[:timeout] = params[:timeout]
  else
    options[:timeout] = timeout if timeout
  end

  if pem? or p12?
    uri.scheme = "https"
  end

  if pem?
    options[:pem]          = pem
    options[:pem_password] = @config.cert_pem_password
    options[:ssl_ca_file]  = ssl_ca_file
  elsif p12?
    options[:p12]          = IO.binread @config.cert_p12
    options[:p12_password] = @config.cert_p12_password
    options[:ssl_ca_file]  = ssl_ca_file
  end

  self.class.post uri.to_s, options
end

Private Instance Methods

p12?() click to toggle source
# File lib/grenache/http/http_client.rb, line 43
def p12?
  !! @config.cert_p12
end
pem() click to toggle source
# File lib/grenache/http/http_client.rb, line 47
def pem
  cert = File.read @config.cert_pem
  key = File.read @config.key
  cert + key
end
pem?() click to toggle source
# File lib/grenache/http/http_client.rb, line 39
def pem?
  !! @config.cert_pem
end
ssl_ca_file() click to toggle source
# File lib/grenache/http/http_client.rb, line 53
def ssl_ca_file
  @config.ca
end
timeout() click to toggle source
# File lib/grenache/http/http_client.rb, line 57
def timeout
  @config.service_timeout
end