Class: UCEngine::Client
- Inherits:
-
Object
- Object
- UCEngine::Client
- Includes:
- NetHttpRequest, NetHttpResponse
- Defined in:
- lib/em-ucengine/client.rb,
lib/em-ucengine/errors.rb,
lib/em-ucengine/client_nethttp.rb
Direct Known Subclasses
Defined Under Namespace
Classes: HttpError, Session, UCError
Instance Method Summary collapse
-
#connect(user, password, metadata = nil, &block) ⇒ Object
Connect to U.C.Engine.
-
#create_user(data) ⇒ Object
Create a user.
-
#initialize(host = "localhost", port = 5280, api_root = "/api", api_version = "0.6") ⇒ Client
constructor
Create a new U.C.Engine client.
-
#time(&block) ⇒ Object
Get server time.
-
#url(path) ⇒ Object
Format url to api.
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
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
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
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
25 26 27 |
# File 'lib/em-ucengine/client.rb', line 25 def url(path) URI.escape("http://#{@host}:#{@port}#{@root}/#{@version}#{path}") end |