Class: TerraformEnterprise::API::Response
- Inherits:
-
Object
- Object
- TerraformEnterprise::API::Response
- Includes:
- TerraformEnterprise::API
- Defined in:
- lib/terraform_enterprise/api/response.rb
Overview
Wrapps the JSON-API HTTP response for easy access to data and resources
Constant Summary
Constants included from TerraformEnterprise::API
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
- #errors? ⇒ Boolean
-
#initialize(rest_client_response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(rest_client_response) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/terraform_enterprise/api/response.rb', line 10 def initialize(rest_client_response) @code = rest_client_response.code @body = parse(rest_client_response.body) return unless @body.is_a?(Hash) @data = @body['data'] || @body @errors = @body['errors'] || [] @resource = Resource.new(@body) if @data.is_a?(Hash) @resources = @data.map { |row| Resource.new('data' => row) } if @data.is_a?(Array) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def errors @errors end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def resource @resource end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
9 10 11 |
# File 'lib/terraform_enterprise/api/response.rb', line 9 def resources @resources end |
Instance Method Details
#errors? ⇒ Boolean
22 23 24 |
# File 'lib/terraform_enterprise/api/response.rb', line 22 def errors? @body.is_a?(Hash) && @body['errors'] && @body['errors'].is_a?(Array) end |
#success? ⇒ Boolean
26 27 28 |
# File 'lib/terraform_enterprise/api/response.rb', line 26 def success? @code.between?(200, 299) end |