Class: Fastbeans::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(call_data, raw_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/fastbeans/response.rb', line 6

def initialize(call_data, raw_response)
  @call_data = call_data
  @raw_response = raw_response
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/fastbeans/response.rb', line 11

def error?
  @raw_response.is_a?(Hash) and @raw_response.has_key?("fastbeans-error")
end

#payloadObject



15
16
17
18
19
20
21
# File 'lib/fastbeans/response.rb', line 15

def payload
  unless error?
    @raw_response
  else
    raise to_exception
  end
end

#to_exceptionObject



23
24
25
26
# File 'lib/fastbeans/response.rb', line 23

def to_exception
  name = @raw_response["fastbeans-error"].underscore.classify
  Fastbeans.exception(name).new(@raw_response["error-information"])
end