Class: TerraformEnterprise::API::Response
- Inherits:
-
Object
- Object
- TerraformEnterprise::API::Response
- Defined in:
- lib/terraform-enterprise/client/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #has_errors? ⇒ Boolean
-
#initialize(rest_client_response) ⇒ Response
constructor
A new instance of Response.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/terraform-enterprise/client/response.rb', line 6 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/terraform-enterprise/client/response.rb', line 6 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/terraform-enterprise/client/response.rb', line 6 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/terraform-enterprise/client/response.rb', line 6 def errors @errors end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
6 7 8 |
# File 'lib/terraform-enterprise/client/response.rb', line 6 def resource @resource end |
#resources ⇒ Object (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
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 |