Class Kii
The main SDK class
Defined in: KiiSDK.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Kii()
|
Method Attributes | Method Name and Description |
---|---|
<static> |
Kii.authenticateAsAppAdmin(clientId, clientSecret, callbacks)
Authenticate as app admin.
|
<static> |
Kii.authenticateAsThing(vendorThingID, password, callbacks)
Authenticate as Thing.
|
<static> |
Kii.authenticateAsThingWithToken(thingID, token, callbacks)
Create a KiiThingContext reference
This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. |
<static> |
Kii.bucketWithName(String)
Creates a reference to a bucket for this app
The bucket will be created/accessed within this app's scope |
<static> |
Kii.encryptedBucketWithName(String)
Creates a reference to a encrypted bucket for this app
The bucket will be created/accessed within this app's scope |
<static> |
Kii.getAccessTokenExpiration()
Returns access token lifetime in seconds.
|
<static> |
Kii.getAppID()
Retrieve the current app ID
|
<static> |
Kii.getAppKey()
Retrieve the current app key
|
<static> |
Kii.getBuildNumber()
Kii SDK Build Number
|
<static> |
Kii.getSDKVersion()
Kii SDK Version Number
|
<static> |
Kii.groupWithName(groupName)
Creates a reference to a group with the given name
|
<static> |
Kii.groupWithNameAndMembers(groupName, members)
Creates a reference to a group with the given name and a list of default members
|
<static> |
Kii.initialize(String, String)
Initialize the Kii SDK
Should be the first Kii SDK action your application makes.
|
<static> |
Kii.initializeWithSite(String, String, KiiSite)
Initialize the Kii SDK with a specific URL
Should be the first Kii SDK action your application makes.
|
<static> |
Kii.listTopics(callbacks, paginationKey)
Gets a list of topics in app scope
|
<static> |
Kii.serverCodeEntry(entryName, version, environmentVersion)
Instantiate KiiServerCodeEntry.
|
<static> |
Kii.serverCodeEntryWithVersion(entryName, version)
|
<static> |
Kii.setAccessTokenExpiration(expiresIn)
Set the access token lifetime in seconds.
|
<static> |
Kii.topicWithName(topicName)
Instantiate topic belongs to application.
|
Method Detail
<static>
{Promise}
Kii.authenticateAsAppAdmin(clientId, clientSecret, callbacks)
Authenticate as app admin.
This api call must not placed on code which can be accessed by browser. This api is intended to be used by server side code like Node.js. If you use this api in code accessible by browser, your application id and application secret could be stolen. Attacker will be act as appadmin and all the data in your application will be suffered.
This api call must not placed on code which can be accessed by browser. This api is intended to be used by server side code like Node.js. If you use this api in code accessible by browser, your application id and application secret could be stolen. Attacker will be act as appadmin and all the data in your application will be suffered.
// example to use callbacks directly Kii.authenticateAsAppAdmin("your client id", "your client secret", { success: function(adminContext) { // adminContext : KiiAppAdminContext instance // Operate entities with adminContext. }, failure: function(error, statusCode) { // Authentication failed. } ); // example to use Promise Kii.authenticateAsAppAdmin("your client id", "your client secret").then( function(adminContext) { // fulfill callback function // adminContext : KiiAppAdminContext instance // Operate entities with adminContext. }, function(error) { // reject callback function // Authentication failed. var errorString = error.message; } );
- Parameters:
- {String} clientId
- assigned to your application.
- {String} clientSecret
- assigned to your application.
- {Object} callbacks Optional
- The callback methods called when authentication succeeded/failed.
- {Method} callbacks.success
- The callback method called when authentication succeeded.
- {Method} callbacks.failure
- The callback method called when authentication failed.
- Returns:
- {Promise} return promise object.
- fulfill callback function: function(adminContext). adminContext is a KiiAppAdminContext instance.
- reject callback function: function(error). error is an Error instance.
- error.message
<static>
{Promise}
Kii.authenticateAsThing(vendorThingID, password, callbacks)
Authenticate as Thing.
This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.
This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.
// example to use callbacks directly Kii.authenticateAsThing("vendor thing id", "password of this thing", { success: function(thingAuthContext) { // thingAuthContext : KiiThingContext instance // Operate entities with thingAuthContext. }, failure: function(error) { // Authentication failed. } ); // example to use Promise Kii.authenticateAsThing("vendor thing id", "password of this thing").then( function(thingAuthContext) { // fulfill callback function // thingAuthContext : KiiThingContext instance // Operate entities with thingAuthContext. }, function(error) { // reject callback function // Authentication failed. var errorString = error.message; } );
- Parameters:
- {String} vendorThingID
- vendorThingID of a registered Thing.
- {String} password
- password for the registered Thing.
- {Object} callbacks Optional
- The callback methods called when authentication succeeded/failed.
- {Method} callbacks.success
- The callback method called when authentication succeeded.
- {Method} callbacks.failure
- The callback method called when authentication failed.
- Returns:
- {Promise} return promise object.
- fulfill callback function: function(thingAuthContext). thingAuthContext is a KiiThingContext instance.
- reject callback function: function(error). error is an Error instance.
- error.message
<static>
{Promise}
Kii.authenticateAsThingWithToken(thingID, token, callbacks)
Create a KiiThingContext reference
This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.
This api is intended to be used in a Thing device, where the user credentials or app admin context is not configured. This Thing must be already registered in Kii Cloud.
// example to use callbacks directly Kii.authenticateAsThingWithToken("thing_id", "thing_token", { success: function(thingContext) { // thingContext : KiiThingContext instance // Operate entities with thingContext. }, failure: function(error) { // Creation failed. } ); // example to use Promise Kii.authenticateAsThingWithToken("thing_id", "thing_token").then( function(thingContext) { // fulfill callback function // thingContext : KiiThingContext instance // Operate entities with thingContext. }, function(error) { // reject callback function // Creation failed. var errorString = error.message; } );
- Parameters:
- {String} thingID
- thingID of a registered Thing.
- {String} token
- token for the registered Thing.
- {Object} callbacks Optional
- The callback methods called when creation succeeded/failed.
- {Method} callbacks.success
- The callback method called when creation succeeded.
- {Method} callbacks.failure
- The callback method called when creation failed.
- Returns:
- {Promise} return promise object.
- fulfill callback function: function(thingContext). thingContext is a KiiThingContext instance.
- reject callback function: function(error). error is an Error instance.
- error.message
<static>
{KiiBucket}
Kii.bucketWithName(String)
Creates a reference to a bucket for this app
The bucket will be created/accessed within this app's scope
The bucket will be created/accessed within this app's scope
var bucket = Kii.bucketWithName("myBucket");
- Parameters:
- String
- bucketName The name of the bucket the app should create/access
- Returns:
- {KiiBucket} A working KiiBucket object
<static>
{KiiEncryptedBucket}
Kii.encryptedBucketWithName(String)
Creates a reference to a encrypted bucket for this app
The bucket will be created/accessed within this app's scope
The bucket will be created/accessed within this app's scope
var bucket = Kii.encryptedBucketWithName("myBucket");
- Parameters:
- String
- bucketName The name of the bucket the app should create/access
- Returns:
- {KiiEncryptedBucket} A working KiiEncryptedBucket object
<static>
Kii.getAccessTokenExpiration()
Returns access token lifetime in seconds.
If access token lifetime has not set explicitly by Kii.setAccessTokenExpiration(expiresIn), returns 0.
- Throws:
- {IllegalStateException}
- If Kii has not been initialized
- Returns:
- access token lifetime in seconds.
<static>
{String}
Kii.getAppID()
Retrieve the current app ID
- Returns:
- {String} The current app ID
<static>
{String}
Kii.getAppKey()
Retrieve the current app key
- Returns:
- {String} The current app key
<static>
{String}
Kii.getBuildNumber()
Kii SDK Build Number
- Returns:
- {String} current build number of the SDK
<static>
{String}
Kii.getSDKVersion()
Kii SDK Version Number
- Returns:
- {String} current version number of the SDK
<static>
{KiiGroup}
Kii.groupWithName(groupName)
Creates a reference to a group with the given name
var group = new Kii.groupWithName("myGroup");
- Parameters:
- {String} groupName
- An application-specific group name
- Returns:
- {KiiGroup} A new KiiGroup reference
<static>
{KiiGroup}
Kii.groupWithNameAndMembers(groupName, members)
Creates a reference to a group with the given name and a list of default members
var group = new KiiGroup.groupWithName("myGroup", members);
- Parameters:
- {String} groupName
- An application-specific group name
- {Array} members
- An array of KiiUser objects to add to the group
- Returns:
- {KiiGroup} A new KiiGroup reference
<static>
Kii.initialize(String, String)
Initialize the Kii SDK
Should be the first Kii SDK action your application makes.
Kii.initialize("my-app-id", "my-app-key");
- Parameters:
- String
- appID The application ID found in your Kii developer console
- String
- appKey The application key found in your Kii developer console
<static>
Kii.initializeWithSite(String, String, KiiSite)
Initialize the Kii SDK with a specific URL
Should be the first Kii SDK action your application makes.
Kii.initializeWithSite("my-app-id", "my-app-key", KiiSite.JP);
- Parameters:
- String
- appID The application ID found in your Kii developer console
- String
- appKey The application key found in your Kii developer console
- KiiSite
- site Can be one of the constants KiiSite.US, KiiSite.JP, KiiSite.SG depending on your location.
<static>
{Promise}
Kii.listTopics(callbacks, paginationKey)
Gets a list of topics in app scope
// example to use callbacks directly Kii.listTopics({ success: function(topicList, nextPaginationKey) { // do something with the result for(var i=0; i<topicList.length; i++){ var topic = topicList[i]; } if (nextPaginationKey != null) { Kii.listTopics({ success: function(topicList, nextPaginationKey) {...}, failure: function(anErrorString) {...} }, nextPaginationKey); } }, failure: function(anErrorString) { // do something with the error response } }); // example to use promise Kii.listTopics().then( function(params) { var topicList = params[0]; var nextPaginationKey = params[1]; // do something with the result for(var i=0; i<topicList.length; i++){ var topic = topicList[i]; } if (nextPaginationKey != null) { Kii.listTopics(null, nextPaginationKey).then( function(params) {...}, function(error) {...} ); } }, function(error) { // do something with the error response } );
- Parameters:
- {Object} callbacks Optional
- An object with callback methods defined
- {Method} callbacks.success
- The callback method to call on a successful list request
- {Method} callbacks.failure
- The callback method to call on a failed list request
- {String} paginationKey Optional
- You can specify the pagination key with the nextPaginationKey passed by callbacks.success or fullfill callback of promise. If empty string or no string object is provided, this API regards no paginationKey specified.
- Returns:
- {Promise} return promise object.
- fulfill callback function: function(params). params is Array instance.
- params[0] is array of KiiTopic instances.
- params[1] is string of nextPaginationKey.
- reject callback function: function(error). error is an Error instance.
- error.message
- fulfill callback function: function(params). params is Array instance.
<static>
{KiiServerCodeEntry}
Kii.serverCodeEntry(entryName, version, environmentVersion)
Instantiate KiiServerCodeEntry.
var entry = Kii.serverCodeEntryWithVersion("main", "gulsdf6ful8jvf8uq6fe7vjy6", KiiServerCodeEnvironmentVersion.V0);
- Parameters:
- {String} entryName
- Name of the entry.
- {String} version Optional
- Version of the entry.
- {KiiServerCodeEnvironmentVersion} environmentVersion Optional
- Version of the Node.js. Currently, supported versions are 0 and 6.
- Throws:
- {InvalidArgumentException}
- Thrown in the following cases:
- entryName or version is not type of string
- entryName or version is empty string
- entryName is invalid string. Valid entryName pattern is "[a-zA-Z][_a-zA-Z0-9]*$".
- Returns:
- {KiiServerCodeEntry} KiiServerCodeEntry instance.
<static>
{KiiServerCodeEntry}
Kii.serverCodeEntryWithVersion(entryName, version)
var entry = Kii.serverCodeEntryWithVersion("main", "gulsdf6ful8jvf8uq6fe7vjy6");
- Parameters:
- {String} entryName
- Name of the entry.
- {String} version
- Version of the entry.
- Deprecated:
- Use Kii.serverCodeEntry instead. Instantiate serverCodeEntryWithVersion with specified entry name and version.
- Throws:
- {InvalidArgumentException}
- Thrown in the following cases:
- entryName or version is not type of string
- entryName or version is empty string
- entryName is invalid string. Valid entryName pattern is "[a-zA-Z][_a-zA-Z0-9]*$".
- Returns:
- {KiiServerCodeEntry} KiiServerCodeEntry instance.
<static>
Kii.setAccessTokenExpiration(expiresIn)
Set the access token lifetime in seconds.
If you don't call this method or call it with 0, token won't be expired.
Call this method if you like the access token to be expired
after a certain period. Once called, token retrieved
by each future authentication will have the specified lifetime.
Note that, it will not update the lifetime of token received prior
calling this method. Once expired, you have to login again to renew the token.
Kii.setAccessTokenExpiration(3600);
- Parameters:
- expiresIn
- The life time of access token in seconds.
- Throws:
- {InvalidArgumentException}
- If specified expiresIn is negative.
- {IllegalStateException}
- If Kii has not been initialized
<static>
{KiiTopic}
Kii.topicWithName(topicName)
Instantiate topic belongs to application.
- Parameters:
- {String} topicName
- name of the topic. Must be a not empty string.
- Returns:
- {KiiTopic} topic instance.