Class: TerraformEnterprise::API::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/terraform_enterprise/api/request.rb

Overview

A wrapper for HTTP JSON-API requests to provide convenience request method wrappers.

Constant Summary collapse

DEFAULT_DEBUG =
false
DEFAULT_HOST =
'https://app.terraform.io'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Request

Returns a new instance of Request.



11
12
13
14
15
# File 'lib/terraform_enterprise/api/request.rb', line 11

def initialize(options = {})
  @host    = options[:host] || DEFAULT_HOST
  @token   = options[:token]
  @debug   = options[:debug] || DEFAULT_DEBUG
end

Instance Method Details

#delete(*path) ⇒ Object



22
23
24
25
# File 'lib/terraform_enterprise/api/request.rb', line 22

def delete(*path)
  data = path.pop if path.last.is_a?(Hash)
  request(:delete, path, data)
end

#get(*path) ⇒ Object



17
18
19
20
# File 'lib/terraform_enterprise/api/request.rb', line 17

def get(*path)
  data = path.pop if path.last.is_a?(Hash)
  request(:get, path, data)
end

#patch(*path) ⇒ Object



37
38
39
40
# File 'lib/terraform_enterprise/api/request.rb', line 37

def patch(*path)
  data = path.pop if path.last.is_a?(Hash)
  request(:patch, path, data)
end

#post(*path) ⇒ Object



27
28
29
30
# File 'lib/terraform_enterprise/api/request.rb', line 27

def post(*path)
  data = path.pop if path.last.is_a?(Hash)
  request(:post, path, data)
end

#put(*path) ⇒ Object



32
33
34
35
# File 'lib/terraform_enterprise/api/request.rb', line 32

def put(*path)
  data = path.pop if path.last.is_a?(Hash)
  request(:put, path, data)
end

#request(method, path, data = {}, extra_headers = {}) ⇒ Object



42
43
44
45
46
47
# File 'lib/terraform_enterprise/api/request.rb', line 42

def request(method, path, data = {}, extra_headers = {})
  request_options = define_request(method, path, data, extra_headers)
  response        = execute(request_options)
  debug(request_options, response, data) if @debug
  TerraformEnterprise::API::Response.new(response)
end