Class: HaveAPI::SpecMethods::ApiResponse

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

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ ApiResponse

Returns a new instance of ApiResponse.



40
41
42
# File 'lib/haveapi/spec/helpers.rb', line 40

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

Instance Method Details

#[](k) ⇒ Object



68
69
70
# File 'lib/haveapi/spec/helpers.rb', line 68

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

#errorsObject



64
65
66
# File 'lib/haveapi/spec/helpers.rb', line 64

def errors
  @data[:errors]
end

#failed?Boolean

Returns:



52
53
54
# File 'lib/haveapi/spec/helpers.rb', line 52

def failed?
  !ok?
end

#messageObject



60
61
62
# File 'lib/haveapi/spec/helpers.rb', line 60

def message
  @data[:message]
end

#ok?Boolean

Returns:



48
49
50
# File 'lib/haveapi/spec/helpers.rb', line 48

def ok?
  @data[:status]
end

#responseObject



56
57
58
# File 'lib/haveapi/spec/helpers.rb', line 56

def response
  @data[:response]
end

#statusObject



44
45
46
# File 'lib/haveapi/spec/helpers.rb', line 44

def status
  @data[:status]
end