Class: TerraformEnterprise::API::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/terraform-enterprise/client/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_client_response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/terraform-enterprise/client/response.rb', line 7

def initialize(rest_client_response)
  @code = rest_client_response.code
  @body = parse(rest_client_response.body)
  @data = (@body.is_a?(Hash) && @body['data']) ? @body['data'] : @body
  if @data.is_a?(Hash)
    @resource = TerraformEnterprise::API::Resource.new(@data) 
  end
  if @data.is_a?(Array) && @data.all?{|a| a.is_a?(Hash)}
    @resources = @data.map do |item|
      TerraformEnterprise::API::Resource.new(item)
    end
  end
  if has_errors?
    @errors = @body['errors']
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def errors
  @errors
end

#resourceObject (readonly)

Returns the value of attribute resource.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def resource
  @resource
end

#resourcesObject (readonly)

Returns the value of attribute resources.



6
7
8
# File 'lib/terraform-enterprise/client/response.rb', line 6

def resources
  @resources
end

Instance Method Details

#has_errors?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/terraform-enterprise/client/response.rb', line 24

def has_errors?
  @body.is_a?(Hash) && @body['errors'] && @body['errors'].is_a?(Array)
end