Module: UCEngine::NetHttpResponse

Included in:
Client, Client::Session
Defined in:
lib/em-ucengine/client_nethttp.rb

Instance Method Summary collapse

Instance Method Details

#answer(req) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/em-ucengine/client_nethttp.rb', line 10

def answer(req)
  if req.kind_of?(Net::HTTPServerError)
    raise UCEngine::Client::HttpError.new(req.code, req.body)
  end

  data = JSON.parse(req.body)
  if data['error']
    raise UCEngine::Client::UCError.new(req.code, data['error'])
  end

  data['result']
end

#answer_bool(req, &block) ⇒ Object



23
24
25
26
# File 'lib/em-ucengine/client_nethttp.rb', line 23

def answer_bool(req, &block)
  result = answer(req)
  result == "true"
end

#answer_connect(req) ⇒ Object



28
29
30
31
# File 'lib/em-ucengine/client_nethttp.rb', line 28

def answer_connect(req)
  credentials = answer(req)
  UCEngine::Client::Session.new(self, credentials['uid'], credentials['sid'])
end