Class: HaveAPI::Spec::ApiResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/spec/api_response.rb

Overview

This class wraps raw reply from the API and provides a more friendly interface.

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ ApiResponse

Returns a new instance of ApiResponse.



5
6
7
# File 'lib/haveapi/spec/api_response.rb', line 5

def initialize(body)
  @data = JSON.parse(body, symbolize_names: true)
end

Instance Method Details

#[](k) ⇒ Object



37
38
39
# File 'lib/haveapi/spec/api_response.rb', line 37

def [](k)
  @data[:response][k]
end

#envelopeObject



9
10
11
# File 'lib/haveapi/spec/api_response.rb', line 9

def envelope
  @data
end

#errorsObject



33
34
35
# File 'lib/haveapi/spec/api_response.rb', line 33

def errors
  @data[:errors]
end

#failed?Boolean

Returns:



21
22
23
# File 'lib/haveapi/spec/api_response.rb', line 21

def failed?
  !ok?
end

#messageObject



29
30
31
# File 'lib/haveapi/spec/api_response.rb', line 29

def message
  @data[:message]
end

#ok?Boolean

Returns:



17
18
19
# File 'lib/haveapi/spec/api_response.rb', line 17

def ok?
  @data[:status]
end

#responseObject



25
26
27
# File 'lib/haveapi/spec/api_response.rb', line 25

def response
  @data[:response]
end

#statusObject



13
14
15
# File 'lib/haveapi/spec/api_response.rb', line 13

def status
  @data[:status]
end