Method: LaunchdarklyApiHelperClass#ld_request

Defined in:
lib/launchdarkly_api_helper/launchdarkly_api_helper_class.rb

#ld_request(http_method, request_url, request_body = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/launchdarkly_api_helper/launchdarkly_api_helper_class.rb', line 26

def ld_request(http_method, request_url, request_body = nil)
  url = URI(request_url)
  https = Net::HTTP.new(url.host, url.port)
  https.use_ssl = true
  request = REQUEST_CLASSES[http_method]['method'].new(url)
  request['Authorization'] = @access_token
  request['Content-Type'] = 'application/json'
  request['LD-API-Version'] = 'beta'
  case http_method
  when :get, :patch, :post
    request.body = convert_to_json(request_body) unless http_method == :get
    https.request(request)
  when :delete
    return https.request(request)
  else
    raise StandardError, "Undefined HTTP method #{http_method} found"
  end
  response = https.request(request)
  @response = parse_json(response.read_body)
end