JS API

JS API methods are used majorly for realization of payments for services and products in applications (more about billing system of «Wamba» you can find in a corresponding section), and also for sending messages from an application. Messages can be sent by server API methods as well, however we recommend that you use JS API. In future JS API methods for sending messages may have less restrictions and more opportunities, than similar API methods.

  • Flash-applications - in all Flash-applications JS API is available on default, without any additional settings and library calls;
  • Iframe-applications - to use in Iframe-applications library must be connected:
<script type="text/javascript" src="http://js.aplatform.ru/v2.js" ></script>
Minimal application sixe: width - 600px, height — 100px.

1. JS API initialization:

mamba.init(success, fail)

Is responsible for api initialization.

mamba.init(function () {
    // Апи готов!
    }, function () {
    // К сожалению, использовать апи не получится :(
    });

2. General structure of method calls:

mamba.method(name, [param1, param2, ...], [params])

Calls method name with parameters.

3. List of JS API methods available at the moment:

setup (params)

Call examples:

mamba.method('setup', {
    hideOverlay: false
    });

There is one setting available at the moment — hideOverlay, shows whether it is needed to hide application field when opening a layer or not. It is recommended to set false for non-flash applications.

dimensions

By this method in e.data the following information may be obtained:

  • offsetLeft
  • offsetTop
  • scrollTop
  • width
  • height
mamba.method('dimensions');
    mamba.on('dimensions', function (e) {
    console.log('dimensions' + ' width:' + e.data.width +	' height:'
    + e.data.height + ' offsetLeft:' + e.data.offsetLeft + ' offsetTop:'
    + e.data.offsetTop + ' scrollTop:' + e.data.scrollTop);
    });

resize (width, height)

Deprecated: resizeWindow (width, height)

Call example:

mamba.method('resize', "100%", 2500);

pay (amount, extra)

Deprecated: openPaymentLayer (aid, amount, extra)

Call example:

mamba.method('pay', 300, 'from_id_23124234');

message (message, extra, [oids])

Deprecated: openContactRequestLayer (message, extra),

mamba.method('message','text','extra');

Deprecated: openDirectContactRequestLayer (message, extra, oids),

mamba.method('message','text','extra','[12345,54321]');

4. Method call of server API

mamba.api([name], [options], [callback])

Makes a call to Wamba api. Data returned are similar to data from server calls to api.aplatform.ru

It is not required to specify sid and app_id.

mamba.api({
    method: 'anketa.getInfo',
    logins: '',
    blocks: 'location,favour',
    ids_only: false,
    oids: '123456'
    }, function(err, data) {
    console.log(err, data);
    });

5. Application events

mamba.on(event, callback)

Subscribes to application events.

Console events:

  • resize
  • scroll
  • dimensions

All the events return e.data, which contain all the data about console sizes and offsets.

mamba.on('resize', function (e) {
    console.log('resize' + ' width:' + e.data.width + ' height:' +
    e.data.height + ' offsetLeft:' + e.data.offsetLeft + ' offsetTop:' +
    e.data.offsetTop + ' scrollTop:' + e.data.scrollTop);
    });

Payment layer events:

  • paymentCancel
  • paymentSuccess
  • paymentFail

Message layer events:

  • messageComplete
    Returned data: {"sended":"173963215,173963894,173966805,173957289","limit":95}
    sended - list of profile id, which receive messages,
    limit - remaining limit of messages
  • messageCancel

mamba.off(event, callback)

Unsubscribes from application events.