Class: RouteNGN::Response

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

Overview

TODO: validation errors are now stored in failure message’s data… we should figure out what to do with it

Constant Summary collapse

SUCCESS_RANGE =
(200..399)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Response

Returns a new instance of Response.



83
84
85
86
87
# File 'lib/routengn.rb', line 83

def initialize(raw)
  @status = raw.code.to_i
  # TODO: if it's not a success code we probably shouldn't bother parsing the JSON
  @data = JSON.parse raw.body
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



81
82
83
# File 'lib/routengn.rb', line 81

def data
  @data
end

#statusObject (readonly)

Returns the value of attribute status.



81
82
83
# File 'lib/routengn.rb', line 81

def status
  @status
end

Instance Method Details

#[](key) ⇒ Object



89
90
91
# File 'lib/routengn.rb', line 89

def [](key)
  @data[key]
end

#failure?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/routengn.rb', line 97

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/routengn.rb', line 93

def success?
  SUCCESS_RANGE.include? @status
end