Class: Fitting::Records::Spherical::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fitting/records/spherical/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, body:) ⇒ Response

Returns a new instance of Response.



9
10
11
12
# File 'lib/fitting/records/spherical/response.rb', line 9

def initialize(status:, body:)
  @status = status
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/fitting/records/spherical/response.rb', line 7

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/fitting/records/spherical/response.rb', line 7

def status
  @status
end

Class Method Details

.load(hash) ⇒ Object



31
32
33
# File 'lib/fitting/records/spherical/response.rb', line 31

def load(hash)
  new(status: hash['status'], body: hash['body'])
end

Instance Method Details

#to_hashObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fitting/records/spherical/response.rb', line 14

def to_hash
  {
    status: status,
    body: JSON.parse(body)
  }
rescue JSON::ParserError
  {
    status: status,
    body: {}
  }
end

#to_json(*_args) ⇒ Object



26
27
28
# File 'lib/fitting/records/spherical/response.rb', line 26

def to_json(*_args)
  JSON.dump(to_hash)
end