Last Update 10.11.16
The DoubleDutch Javascript SDK offers the ability to load a webpage (in the DoubleDutch Events app) and communicate back and forth with the native app. This is useful in understanding the context under which the webpage was loaded.
For example, Javascript may be used to change the experience of the webpage based on the logged in user, the current event, etc.
To see in action, please refer to the following: http://jsfiddle.net/adamliechty/xsxdS/
Technical Reference
Embedding
To embed the JS SDK in an existing (or new webpage), first add script tag reference to the HEAD section of the page:
<script src="https://cdn.rawgit.com/doubledutch/sdk/master/DDEventsSDK.js"></script>
All bug fixes will be automatically reflected in the script at that URL, and will be backwards compatible.
When this script is loaded and not running within the context of the DoubleDutch Events mobile application, no side effects will be observed.
API Documentation
DD.Events.onReady (callback)
Description:
Call this method to subscribe to an event which will fire when the JS SDK has been loaded within the context of the DoubleDutch Events mobile application. When called not in the context of the mobile application, this method will never call the callback.
Parameters:
Name |
Type |
Example |
callback |
function(void) -> void |
DD.Events.onReady(function() { alert(‘ready’) }) |
DD.Events.getCurrentUserAsync(callback)
Description:
Call this method to asynchronously fetch a JSON representation of the currently logged in user.
Parameters:
Name |
Type |
Example |
callback |
function(user) -> void |
DD.Events.getCurrentUserAsync(function(user) { alert(JSON.stringify(user)) })
Alerts:
{
|
DD.Events.getCurrentEventAsync(callback)
Description:
Call this method to asynchronously fetch a JSON representation of the currently selected event information.
Parameters:
Name |
Type |
Example |
callback |
function(event) -> void |
DD.Events.getCurrentEventAsync(function(event) { alert(JSON.stringify(event)) })
Alerts:
{ } |
DD.Events.getSignedAPIAsync(urlFragment, postBody, callback)
Description:
Call this method to sign a url fragment to be used in an API call to the DoubleDutch endpoint.
Parameters:
Name |
Type |
Example |
---|---|---|
urlFragment |
string |
/users/?count=20 |
postBody |
string |
{ "key": "value" } |
callback |
function(signedUrl, authHeader) -> void |
DD.Events.getSignedAPIAsync("/users/?count=20", "", function(signedUrl, authHeader) { $.get(signedUrl,{ headers: { ‘Authorization‘: authHeader } }).then(function(json) { }) }) |
Comments
0 comments
Please sign in to leave a comment.