Class: UCEngine::Client

Inherits:
Object
  • Object
show all
Includes:
NetHttpRequest, NetHttpResponse
Defined in:
lib/em-ucengine/client.rb,
lib/em-ucengine/errors.rb,
lib/em-ucengine/client_nethttp.rb

Direct Known Subclasses

EventMachine::UCEngine::Client

Defined Under Namespace

Classes: HttpError, Session, UCError

Instance Method Summary collapse

Methods included from NetHttpRequest

#delete, #get, #json_post, #post

Methods included from NetHttpResponse

#answer, #answer_bool, #answer_connect

Constructor Details

#initialize(host = "localhost", port = 5280, api_root = "/api", api_version = "0.6") ⇒ Client

Create a new U.C.Engine client

Parameters:

  • Host (String)

    of the U.C.Engine instance

  • Port (Number)

    of the U.C.Engine instance

  • Entry (String)

    point of the API

  • Version (String)

    of U.C.Engine API



15
16
17
18
19
20
# File 'lib/em-ucengine/client.rb', line 15

def initialize(host="localhost", port=5280, api_root="/api", api_version="0.6")
  @host = host
  @port = port
  @root = api_root
  @version = api_version
end

Instance Method Details

#connect(user, password, metadata = nil, &block) ⇒ Object

Connect to U.C.Engine

Parameters:

  • User (String)

    name

  • Password (String)
  • Metadata (Hash)

    of the user



39
40
41
42
43
44
# File 'lib/em-ucengine/client.rb', line 39

def connect(user, password, =nil, &block)
  body = { "name" => user, "credential" => password }
  body["metadata"] =  if 
  req = post(url("/presence"), {}, body)
  answer_connect(req, &block)
end

#create_user(data) ⇒ Object

Create a user

Parameters:

  • data (Hash)


49
50
51
52
# File 'lib/em-ucengine/client.rb', line 49

def create_user(data)
  # FIXME: for now users can't be created with metadata.
  answer post("/user", data), &block
end

#time(&block) ⇒ Object

Get server time



30
31
32
# File 'lib/em-ucengine/client.rb', line 30

def time(&block)
  Session.new(self, nil, nil).time &block
end

#url(path) ⇒ Object

Format url to api

Parameters:

  • Path (String)

    of the method



25
26
27
# File 'lib/em-ucengine/client.rb', line 25

def url(path)
  URI.escape("http://#{@host}:#{@port}#{@root}/#{@version}#{path}")
end