Class: Evervault::Http::RequestHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/evervault/http/request_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request:, config:, cert:) ⇒ RequestHandler

Returns a new instance of RequestHandler.



13
14
15
16
17
# File 'lib/evervault/http/request_handler.rb', line 13

def initialize(request:, config:, cert:)
  @request = request
  @config = config
  @cert = cert
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/evervault/http/request_handler.rb', line 11

def config
  @config
end

Instance Method Details

#delete(path) ⇒ Object



31
32
33
34
35
# File 'lib/evervault/http/request_handler.rb', line 31

def delete(path)
  @cert.setup if @cert.is_certificate_expired
  resp = @request.execute(:delete, build_url(path))
  parse_json_body(resp.body)
end

#get(path) ⇒ Object



19
20
21
22
23
# File 'lib/evervault/http/request_handler.rb', line 19

def get(path)
  @cert.setup if @cert.is_certificate_expired
  resp = @request.execute(:get, build_url(path))
  parse_json_body(resp.body)
end

#post(path, body, basic_auth = false, error_map = Evervault::Errors::LegacyErrorMap) ⇒ Object



37
38
39
40
41
# File 'lib/evervault/http/request_handler.rb', line 37

def post(path, body, basic_auth = false, error_map = Evervault::Errors::LegacyErrorMap)
  @cert.setup if @cert.is_certificate_expired
  resp = @request.execute(:post, build_url(path), body, basic_auth, error_map)
  parse_json_body(resp.body) unless resp.body.empty?
end

#put(path, body) ⇒ Object



25
26
27
28
29
# File 'lib/evervault/http/request_handler.rb', line 25

def put(path, body)
  @cert.setup if @cert.is_certificate_expired
  resp = @request.execute(:put, build_url(path), body)
  parse_json_body(resp.body)
end