Class: Fitting::Records::Spherical::Response
- Inherits:
-
Object
- Object
- Fitting::Records::Spherical::Response
- Defined in:
- lib/fitting/records/spherical/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(status:, body:, content_type:) ⇒ Response
constructor
A new instance of Response.
- #to_hash ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(status:, body:, content_type:) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/fitting/records/spherical/response.rb', line 9 def initialize(status:, body:, content_type:) @status = status @body = body @content_type = content_type end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/fitting/records/spherical/response.rb', line 7 def body @body end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/fitting/records/spherical/response.rb', line 7 def status @status end |
Instance Method Details
#to_hash ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fitting/records/spherical/response.rb', line 15 def to_hash begin parse_body = JSON.parse(body) rescue JSON::ParserError parse_body = {} end if @content_type == nil || @content_type == '' { status: status, content_type: 'application/json', body: parse_body } else ct = @content_type.split("; ") { status: status, content_type: ct.first, body: parse_body } end end |
#to_json(*_args) ⇒ Object
38 39 40 |
# File 'lib/fitting/records/spherical/response.rb', line 38 def to_json(*_args) JSON.dump(to_hash) end |