Class: Pastvu::BasicResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/pastvu/basic_response.rb

Direct Known Subclasses

BoundsResponse, Collection, InformationResponse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ BasicResponse

Returns a new instance of BasicResponse.



5
6
7
8
9
10
11
# File 'lib/pastvu/basic_response.rb', line 5

def initialize(response_body)
  @json = response_body
  if Pastvu.config.ensure_successful_responses
    @hash = self.to_hash
    raise RuntimeError, "Unexpected response from the server: #{@hash}"  unless @hash["result"]
  end
end

Instance Attribute Details

#hashObject

Returns the value of attribute hash.



3
4
5
# File 'lib/pastvu/basic_response.rb', line 3

def hash
  @hash
end

#jsonObject

Returns the value of attribute json.



3
4
5
# File 'lib/pastvu/basic_response.rb', line 3

def json
  @json
end

Instance Method Details

#to_hashObject



17
18
19
# File 'lib/pastvu/basic_response.rb', line 17

def to_hash
  @hash || Parser.to_hash(@json)
end

#to_jsonObject



13
14
15
# File 'lib/pastvu/basic_response.rb', line 13

def to_json
  @hash ? Parser.to_json(@hash) : @json
end