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.



134
135
136
137
138
# File 'lib/routengn.rb', line 134

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.



132
133
134
# File 'lib/routengn.rb', line 132

def data
  @data
end

#statusObject (readonly)

Returns the value of attribute status.



132
133
134
# File 'lib/routengn.rb', line 132

def status
  @status
end

Instance Method Details

#[](key) ⇒ Object



140
141
142
# File 'lib/routengn.rb', line 140

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

#failure?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/routengn.rb', line 148

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/routengn.rb', line 144

def success?
  SUCCESS_RANGE.include? @status
end