Class: Grenache::Http::HttpClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/grenache/http/http_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HttpClient

Returns a new instance of HttpClient.



6
7
8
# File 'lib/grenache/http/http_client.rb', line 6

def initialize config
  @config = config
end

Instance Method Details

#request(uri, body, params = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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