SyncEngine AJAX API provides ability for HTML/javascript based application to control SyncEngine using AJAX calls. It is implemented as a plain JavaScript library which doesn’t require to use any side libraries or frameworks.
It is just for SyncEngine control and at the moment it doesn't provide any methods to read or manipulate stored objects. |
Rhodes API samples has SyncEngine AJAX API demo code.
<!DOCTYPE html> <html> <head><title>SyncEngine AJAX API sample</title> <script src="/public/js/syncengine.js" type="text/javascript"></script> <script type="text/javascript"> function put(msg, container) { document.getElementById(container).innerHTML = msg; } api = window.Rho.syncengine; </script> </head> <body> API functions tests: <ul> <li> <a href="#" onclick="api.set_syncserver('http://some.server.url', function(res){put(res, 'result_set_syncserver');}); return false;"> set_syncserver('http://rhodes-samples-server.heroku.com/application')</a> <span id="result_set_syncserver"></span> </li> <li> <a href="#" onclick="api.set_pollinterval(60, function(res){put(res, 'result_set_pollinterval');}); return false;"> set_pollinterval(60)</a> <span id="result_set_pollinterval"></span> </li> <li> <a href="#" onclick="api.get_pollinterval(function(res){put(res, 'result_get_pollinterval');}); return false;"> get_pollinterval()</a> <span id="result_get_pollinterval"></span> </li> <li> <a href="#" onclick="api.login('abc', '123', function(result){alert(result);} ,function(res){put(res, 'result_login');}); return false;"> login('abc', '123', '')</a> <span id="result_login"></span> </li> <li> <a href="#" onclick="api.logged_in(function(res){put(res, 'result_logged_in');}); return false;"> logged_in()</a> <span id="result_logged_in"></span> </li> <li> <a href="#" onclick="api.logout(function(res){put(res, 'result_logout');}); return false;"> logout()</a> <span id="result_logout"></span> </li> <li> <a href="#" onclick="api.dosync(false, '', function(res){put(res, 'result_dosync');}); return false;"> dosync()</a> <span id="result_dosync"></span> </li> <li> <a href="#" onclick="api.dosync_source('Metadata', false, '', function(res){put(res, 'result_dosync_source');}); return false;"> dosync_source('Metadata')</a> <span id="result_dosync_source"></span> </li> <li> <a href="#" onclick="api.is_syncing(function(res){put(res, 'result_is_syncing');}); return false;"> is_syncing()</a> <span id="result_is_syncing"></span> </li> <li> <a href="#" onclick="api.stop_sync(function(res){put(res, 'result_stop_sync');}); return false;"> stop_sync()</a> <span id="result_stop_sync"></span> </li> </ul> </body> </html>
All API methods are defined in the Rho.syncengine namespace. Each method is accessible in JavaScript as window.Rho.syncengine.method_name. Each API method receives callback functions as two last parameters, those are:
success - Success handler function. Parameters are:
error - Error and timeout handler function. Parameters are:
They are the same for every API method and will not be explained for each method description.
set_threaded_mode(/*boolean*/ threaded, /*function*/ success, /*function*/ error);
Where:
enable_status_popup(/*boolean*/ enable, /*function*/ success, /*function*/ error);
Where:
set_ssl_verify_peer(/*boolean*/ verify, /*function*/ success, /*function*/ error);
Where:
It register device on push server for push notifications. Have no control parameters, just result handlers. :::cplusplus register_push(/function/ success, /function/ error);
set_syncserver(/*string*/ syncserver, /*function*/ success, /*function*/ error);
Where:
set_pollinterval(/*number*/ interval, /*function*/ success, /*function*/ error);
Where:
get_pollinterval(/*function*/ success, /*function*/ error);
Where:
set_pagesize(/*number*/ size, /*function*/ success, /*function*/ error);
Where:
get_pagesize(/*function*/ success, /*function*/ error);
Where:
This method make it possible to set handler function to watch for changes in exact object during synchronization process. :::cplusplus set_objectnotify(/function/ notify, /function/ success, /function/ error); Where:
This method cleans all object notifications. :::cplusplus clean_objectnotify(/function/ success, /function/ error);
This method makes user logged in. :::cplusplus login(/string/ login, /string/ password, /function/ callback, /function/ success, /function/ error) Where:
This methods checks if user is logged in. :::cplusplus logged_in(/function/ success, /function/ error); Where:
This method makes user logged out. :::cplusplus logout(/function/ success, /function/ error);
This method runs synchronization for all sources. :::cplusplus dosync(/bool/ show_status_popup, /string/ query_params, /function/ success, /function/ error); Where:
This method runs synchronization for exact named source. :::cplusplus dosync_source(/string/ srcName, /bool/ show_status_popup, /string/ query_params, /function/ success, /function/ error); Where:
This methods checks if synchronization still in a progress. :::cplusplus is_syncing(/function/ success, /function/ error); Where:
This method stops synchronization process. :::cplusplus stop_sync(/function/ success, /function/ error);