Class: GwtRpc::Response

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

Defined Under Namespace

Classes: Reader

Instance Method Summary collapse

Constructor Details

#initialize(client, raw_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
# File 'lib/gwt_rpc/response.rb', line 6

def initialize(client, raw_response)
  @client       = client
  @raw_response = raw_response
  
  raise GwtRpc::Error::NoResponse.new("Error: no response to request") if @raw_response.code == 0
  raise GwtRpc::Error::ServerError.new("Error: status code #{@raw_response.code} not 200; body is #{@raw_response.body}") if @raw_response.code != 200
  raise GwtRpc::Error::ServerError.new("Error: #{@raw_response.body}") if @raw_response.body !~ /^\/\/OK/
end

Instance Method Details

#contentObject



15
16
17
18
# File 'lib/gwt_rpc/response.rb', line 15

def content
  json_body = @raw_response.body.sub(/^\/\/OK/,'')
  GwtRpc::Response::Reader.new(@client, json_body).read_object
end