Class zebkit.io.Service <zebkit.io>

A remote service connector class. It is supposed the class has to be extended with different protocols like RPC, JSON etc. The typical pattern of connecting to a remote service is shown below:

   // create service connector that has two methods "a()" and "b(param1)"
   var service = new zebkit.io.Service("http://myservice.com", [
       "a", "b"
   ]);

   // call the methods of the remote service
   service.a();
   service.b(10);

Also the methods of a remote service can be called asynchronously. In this case a callback method has to be passed as the last argument of called remote methods:

   // create service connector that has two methods "a()" and "b(param1)"
   var service = new zebkit.io.Service("http://myservice.com", [
       "a", "b"
   ]);

   // call "b" method from the remote service asynchronously
   service.b(10, function(res) {
       // handle a result of the remote method execution here
       ...
   });

Ideally any specific remote service extension of "zebkit.io.Service" class has to implement two methods:

   - **encode** to say how the given remote method with passed parameters have
   to be transformed into a concrete service side protocol (JSON, XML, etc)
   - **decode** to say how the specific service response has to be converted into
   JavaScript object
Constructor:
zebkit.io.Service (url, methods)

Parameters:
  • url <String>

    an URL of remote service

  • methods <Array>

    a list of methods names the remote service provides



protected <Object> decode (name)

Transforms the given remote method response to a JavaScript object.


Parameters:
  • name <String>

    a remote method name


Returns: <Object>

a result of the remote method calling as a JavaScript object

protected <String> encode (name, args)

Transforms the given remote method execution with the specified parameters to service specific protocol.


Parameters:
  • name <String>

    a remote method name

  • args <Array>

    an passed to the remote method arguments


Returns: <String>

a remote service specific encoded string

private static <Function> invoke (clazz, url, a)

Build invoke method that calls a service method.


Parameters:
Returns: <Function>

a wrapped method to call RPC method with

protected <zebkit.DoIt> send (url, data)

Send the given data to the given url and return a response. Callback function can be passed for asynchronous result handling.


Parameters:
Returns: <zebkit.DoIt>

a result


public <Array> methods

Remote service methods names

public <String> url

Remote service url