Class Index | File Index

Classes


Class KiiAppAdminContext

represents the app admin context

This class must not referred from code accessible from browser. This class is intended to be used by server side code like Node.js. If you use this class in code accessible by browser, your application client id and client secret could be stolen. Attacker will be act as application admin and all the data in your application will be suffered. Application administrator context. Entities obtained from this class will be manipulated by application admin.
Defined in: KiiSDK.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Method Summary
Method Attributes Method Name and Description
 
Creates a reference to a bucket operated by app admin.
 
Creates a reference to a encrypted bucket operated by app admin.
 
findUserByEmail(email, callbacks)
Find registered KiiUser with the email.
 
findUserByPhone(phone, callbacks)
Find registered KiiUser with the phone.
 
findUserByUsername(username, callbacks)
Find registered KiiUser with the user name.
 
Get access token published for app admin.
 
groupWithID(String)
Creates a reference to a group operated by app admin using group's ID.
 
groupWithName(String)
Creates a reference to a group operated by app admin.
 
groupWithURI(String)
Creates a reference to a group operated by app admin using group's URI.
 
listTopics(callbacks, paginationKey)
Gets a list of topics in app scope
 
loadThingWithThingID(thingID, callbacks)
Load thing with thing ID by app admin.
 
loadThingWithVendorThingID(vendorThingID, callbacks)
Load thing with vendor thing ID by app admin.
 
objectWithURI(String)
Creates a reference to an object operated by app admin using object`s URI.
 
registerGroupWithOwnerAndID(groupID, groupName, user, members, callbacks)
Register new group own by specified user on Kii Cloud with specified ID.
 
registerOwnerWithThingID(thingID, owner, callbacks)
Register user/group as owner of specified thing by app admin.
 
registerOwnerWithVendorThingID(vendorThingID, owner, callbacks)
Register user/group as owner of specified thing by app admin.
 
registerThing(fields, callbacks)
Register thing by app admin.
 
thingWithID(String)
Creates a reference to a thing operated by app admin.
 
topicWithName(topicName)
Creates a reference to a topic operated by app admin
 
userWithID(String)
Creates a reference to a user operated by app admin.
Class Detail
KiiAppAdminContext()
Method Detail
{KiiBucket} bucketWithName(String)
Creates a reference to a bucket operated by app admin.

The bucket will be created/accessed within this app's scope
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var bucket = adminContext.bucketWithName("myBucket");
              // KiiBucket operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
bucketName The name of the bucket the app should create/access
Returns:
{KiiBucket} A working KiiBucket object

{KiiBucket} encryptedBucketWithName(String)
Creates a reference to a encrypted bucket operated by app admin.

The bucket will be created/accessed within this app's scope
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var bucket = adminContext.encryptedBucketWithName("myBucket");
              // KiiBucket operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
bucketName The name of the bucket the app should create/access
Returns:
{KiiBucket} A working KiiBucket object

{Promise} findUserByEmail(email, callbacks)
Find registered KiiUser with the email.
If there are no user registers with the specified email or if there are but not verified email yet, callbacks.failure or reject callback of promise will be called.
If the email is null or empty, callbacks.failure or reject callback of promise will be callded.

Note:
  // example to use callbacks directly
  Kii.authenticateAsAppAdmin("client-id", "client-secret", {
      success: function(adminContext) {
          adminContext.findUserByEmail("user_to_find@example.com", {
              success: function(adminContext, theMatchedUser) {
                  // Do something with the found user
              },
              failure: function(adminContext, anErrorString) {
                  // Do something with the error response
              }
          });
      },
      failure: function(errorString, errorCode) {
          // Auth failed.
      }
  });
  
  // example to use Promise
  Kii.authenticateAsAppAdmin("client-id", "client-secret").then(
      function(adminContext) {
          adminContext.findUserByEmail("user_to_find@example.com").then(
              function(params) { // fullfill callback function
                  var adminContext = params[0];
                  var theMatchedUser = params[1];
                  // Do something with the found user
              },
              function(error) { // reject callback function
                  var adminContext = error.target;
                  var anErrorString = error.message;
                  // Do something with the error response
              }
          );
      },
      function(error) {
        // Auth failed.
      }
  );
Parameters:
{String} email
The email to find KiiUser who owns it.
Don't add prefix of "EMAIL:" described in REST API documentation. SDK will take care of it.
{Object} callbacks Optional
An object with callback methods defined. This argument is mandatory and can't be omitted.
{Method} callbacks.success
The callback method to call on a successful finding request.
{Method} callbacks.failure
The callback method to call on a failed finding request.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a KiiAppAdminContext instance which this method was called on.
    • params[1] is a found KiiUser instance.
  • reject callback function: function(error). error is an Error instance.
    • error.target is a KiiAppAdminContext instance which this method was called on.
    • error.message

{Promise} findUserByPhone(phone, callbacks)
Find registered KiiUser with the phone.
If there are no user registers with the specified phone or if there are but not verified phone yet, callbacks.failure or reject callback of promise will be called.
If the phone is null or empty, callbacks.failure or reject callback of promise will be called.

Note:
  // example to use callbacks directly
  Kii.authenticateAsAppAdmin("client-id", "client-secret", {
      success: function(adminContext) {
          adminContext.findUserByPhone("phone_number_to_find", {
              success: function(adminContext, theMatchedUser) {
                  // Do something with the found user
              },
              failure: function(adminContext, anErrorString) {
                  // Do something with the error response
              }
          });
      },
      failure: function(errorString, errorCode) {
          // Auth failed.
      }
  });
  
  // example to use Promise
  Kii.authenticateAsAppAdmin("client-id", "client-secret").then(
      function(adminContext) {
          adminContext.findUserByPhone("phone_number_to_find").then(
              function(params) { // fullfill callback function
                  var adminContext = params[0];
                  var theMatchedUser = params[1];
                  // Do something with the found user
              },
              function(error) { // reject callback function
                  var adminContext = error.target;
                  var anErrorString = error.message;
                  // Do something with the error response
              }
          );
      },
      function(error) {
        // Auth failed.
      }
  );
Parameters:
{String} phone
The phone number to find KiiUser who owns it.
Don't add prefix of "PHONE:" described in REST API documentation. SDK will take care of it.
{Object} callbacks Optional
An object with callback methods defined. This argument is mandatory and can't be omitted.
{Method} callbacks.success
The callback method to call on a successful finding request.
{Method} callbacks.failure
The callback method to call on a failed finding request.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a KiiAppAdminContext instance which this method was called on.
    • params[1] is a found KiiUser instance.
  • reject callback function: function(error). error is an Error instance.
    • error.target is a KiiAppAdminContext instance which this method was called on.
    • error.message

{Promise} findUserByUsername(username, callbacks)
Find registered KiiUser with the user name.
If there are no user registers with the specified user name, callbacks.failure or reject callback of promise will be called.
If the user name is null or empty, callbacks.failure or reject callback of promise will be called.

Note:
  // example to use callbacks directly
  Kii.authenticateAsAppAdmin("client-id", "client-secret", {
      success: function(adminContext) {
          adminContext.findUserByUsername("user_name_to_find", {
              success: function(adminContext, theMatchedUser) {
                  // Do something with the found user
              },
              failure: function(adminContext, anErrorString) {
                  // Do something with the error response
              }
          });
      },
      failure: function(errorString, errorCode) {
          // Auth failed.
      }
  });
  // example to use Promise
  Kii.authenticateAsAppAdmin("client-id", "client-secret").then(
      function(adminContext) {
          adminContext.findUserByUsername("user_name_to_find").then(
              function(params) { // fullfill callback function
                  var adminContext = params[0];
                  var theMatchedUser = params[1];
                  // Do something with the found user
              },
              function(error) { // reject callback function
                  var adminContext = error.target;
                  var anErrorString = error.message;
                  // Do something with the error response
              }
          );
      },
      function(error) {
        // Auth failed.
      }
  );
Parameters:
{String} username
The user name to find KiiUser who owns it.
Don't add prefix of "LOGIN_NAME:" described in REST API documentation. SDK will take care of it.
{Object} callbacks Optional
An object with callback methods defined. This argument is mandatory and can't be omitted.
{Method} callbacks.success
The callback method to call on a successful finding request.
{Method} callbacks.failure
The callback method to call on a failed finding request.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is Array instance.
    • params[0] is a KiiAppAdminContext instance which this method was called on.
    • params[1] is a found KiiUser instance.
  • reject callback function: function(error). error is an Error instance.
    • error.target is a KiiAppAdminContext instance which this method was called on.
    • error.message

{String} getAccessToken()
Get access token published for app admin.
Returns:
{String} access token published for app admin.

{KiiGroup} groupWithID(String)
Creates a reference to a group operated by app admin using group's ID.

Note: Returned instance from this API can operate existing KiiGroup.
If you want to create a new KiiGroup, please use KiiAppAdminContext#groupWithName.
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var groupID = "0123456789abcdefghijklmno";
              var group = adminContext.groupWithID(groupID);
              // KiiGroup operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
group ID.
Throws:
{InvalidArgumentException}
Thrown if passed groupID is null or empty.
Returns:
{KiiGroup} A working KiiGroup object

{KiiGroup} groupWithName(String)
Creates a reference to a group operated by app admin.

Note: Returned instance from this API can not operate existing KiiGroup.
If you want to operate existing KiiGroup, please use KiiAppAdminContext#groupWithURI or KiiAppAdminContext#groupWithID.
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var group = adminContext.groupWithName("newGroup");
              // KiiGroup operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
group name.
Returns:
{KiiGroup} A working KiiGroup object

{KiiGroup} groupWithURI(String)
Creates a reference to a group operated by app admin using group's URI.

Note: Returned instance from this API can operate existing KiiGroup.
If you want to create a new KiiGroup, please use KiiAppAdminContext#groupWithName.
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var groupUri = ...; // KiiGroup's URI
              var group = adminContext.groupWithURI(groupUri);
              // KiiGroup operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
group URI.
Throws:
{InvalidURIException}
Thrown if the URI is null, empty or does not have correct format.
Returns:
{KiiGroup} A working KiiGroup object

{Promise} listTopics(callbacks, paginationKey)
Gets a list of topics in app scope
  // example to use callbacks directly
  // Assume you already have adminContext instance.
  adminContext.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
  // Assume you already have adminContext instance.
  adminContext.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) {
              adminContext.listTopics(null, nextPaginationKey).then(
                  function(params) {...},
                  function(error) {...}
              );
          }
      },
      function(error) {
          // do something with the error response
      }
  );
Parameters:
{Object} callbacks
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
You can specify the pagination key with the nextPaginationKey passed by callbacks.success. 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.target is a KiiAppAdminContext instance which this method was called on.
    • error.message

{Promise} loadThingWithThingID(thingID, callbacks)
Load thing with thing ID by app admin. Method interface is same as KiiThing#loadWithThingID(). Please refer to KiiThing document for details.
  // example to use callbacks directly
  // Assume you already have adminContext instance.
  adminContext.loadThingWithThingID("thing-xxxx-yyyy",{
      success: function(thing) {
          // Load succeeded.
          // Operation using thing instance in the parameter
          // is authored by app admin.
      },
      failure: function(error) {
          // Handle error.
      }
  });
  
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.loadThingWithThingID("thing-xxxx-yyyy").then(
      function(thing) {
          // Load succeeded.
          // Operation using thing instance in the parameter
          // is authored by app admin.
      },
      function(error) {
          // Handle error.
      }
  );
Parameters:
{String} thingID
registered thing id.
{Object} callbacks Optional
object holds callback functions.
{Function} callbacks.success
callback called when operation succeeded.
{Function} callbacks.failure
callback called when operation failed.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
  • reject callback function: function(error). error is an Error instance.
    • error.message

{Promise} loadThingWithVendorThingID(vendorThingID, callbacks)
Load thing with vendor thing ID by app admin. Method interface is same as KiiThing#loadWithVendorThingID(). Please refer to KiiThing document for details.
  // example to use callbacks directly
  // Assume you already have adminContext instance.
  adminContext.loadThingWithVendorThingID("thing-xxxx-yyyy",{
      success: function(thing) {
          // Load succeeded.
          // Operation using thing instance in the parameter
          // is authored by app admin.
      },
      failure: function(error) {
          // Handle error.
      }
  });
  
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.loadThingWithVendorThingID("thing-xxxx-yyyy").then(
      function(thing) {
          // Load succeeded.
          // Operation using thing instance in the parameter
          // is authored by app admin.
      },
      function(error) {
          // Handle error.
      }
  );
Parameters:
{String} vendorThingID
registered vendor thing id.
{Object} callbacks Optional
object holds callback functions.
{Function} callbacks.success
callback called when operation succeeded.
{Function} callbacks.failure
callback called when operation failed.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
  • reject callback function: function(error). error is an Error instance.
    • error.message

{KiiObject} objectWithURI(String)
Creates a reference to an object operated by app admin using object`s URI.
Parameters:
String
object URI.
Throws:
{InvalidURIException}
If the URI is null, empty or does not have correct format.
Returns:
{KiiObject} A working KiiObject instance

{Promise} registerGroupWithOwnerAndID(groupID, groupName, user, members, callbacks)
Register new group own by specified user on Kii Cloud with specified ID. This method can be used only by app admin.

If the group that has specified id already exists, registration will be failed.
  // example to use callbacks directly
  Kii.authenticateAsAppAdmin("client-id", "client-secret", {
      success: function(adminContext) {
          var members = [];
          members.push(KiiUser.userWithID("Member User Id"));
          adminContext.registerGroupWithOwnerAndID("Group ID", "Group Name", "Owner User ID", members, {
              success: function(theSavedGroup) {
                  // do something with the saved group
              },
              failure: function(theGroup, anErrorString, addMembersArray, removeMembersArray) {
                  // do something with the error response
              }
          });
      },
      failure: function(errorString, errorCode) {
          // auth failed.
      }
  });
  // example to use Promise
  Kii.authenticateAsAppAdmin("client-id", "client-secret").then(
      function(adminContext) {
          var members = [];
          members.push(KiiUser.userWithID("Member User Id"));
          return adminContext.registerGroupWithOwnerAndID("Group ID", "Group Name", "Owner User ID", members);
      }
  ).then(
      function(group) {
          // do something with the saved group
      }
  );
Parameters:
{String} groupID
ID of the KiiGroup
{String} groupName
Name of the KiiGroup
{String} user
id of owner
{Array} members
An array of KiiUser objects to add to the group
callbacks
Returns:
{Promise} return promise object.
  • fulfill callback function: function(theSavedGroup). theSavedGroup is KiiGroup instance.
  • reject callback function: function(error). error is an Error instance.
    • error.target is the KiiGroup instance which this method was called on.
    • error.message
    • error.addMembersArray is array of KiiUser to be added as memebers of this group.
    • error.removeMembersArray is array of KiiUser to be removed from the memebers list of this group.

{Promise} registerOwnerWithThingID(thingID, owner, callbacks)
Register user/group as owner of specified thing by app admin.
  // example to use callbacks directly
  // assume thing/group is already registered.
  var group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.registerOwnerWithThingID("th.xxxx-yyyy-zzzz", group, {
      success: function(group) {
          // Register owner succeeded.
      },
      failure: function(error) {
          // Handle error.
      }
  });
  
  // example to use Promise
  // assume thing/group is already registered.
  var group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.registerOwnerWithThingID("th.xxxx-yyyy-zzzz", group).then(
      function(params) {
          // Register owner succeeded.
          var group = params[0];
      },
      function(error) {
          // Handle error.
      }
  );
Parameters:
{String} thingID
The ID of thing
{KiiUser or KiiGroup} owner
instnce of KiiUser/KiiGroup to be registered as owner.
{Object} callbacks Optional
object holds callback functions.
{Function} callbacks.success
callback called when operation succeeded.
1st argument: user/group object registered as owner.
{Function} callbacks.failure
callback called when operation failed.
argument is Error object.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is an Array instance.
    • params[0] is a KiiUser/KiiGroup instance.
  • reject callback function: function(error). error is an Error instance.
    • error.message

{Promise} registerOwnerWithVendorThingID(vendorThingID, owner, callbacks)
Register user/group as owner of specified thing by app admin.
  // example to use callbacks directly
  // assume thing/group is already registered.
  var group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.registerOwnerWithVendorThingID("xxxx-yyyy-zzzz", group, {
      success: function(group) {
          // Register owner succeeded.
      },
      failure: function(error) {
          // Handle error.
      }
  });
  
  // example to use Promise
  // assume thing/group is already registered.
  var group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.registerOwnerWithVendorThingID("xxxx-yyyy-zzzz", group).then(
      function(group) {
          // Register owner succeeded.
      },
      function(error) {
          // Handle error.
      }
  );
Parameters:
{String} vendorThingID
The vendor thing ID of thing
{KiiUser or KiiGroup} owner
instance of KiiUser/KiiGroupd to be registered as owner.
{Object} callbacks Optional
object holds callback functions.
{Function} callbacks.success
callback called when operation succeeded.
1st argument: user/group object registered as owner.
{Function} callbacks.failure
callback called when operation failed.
argument is Error object.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(params). params is an Array instance.
    • params[0] is a KiiUser/KiiGroup instance.
  • reject callback function: function(error). error is an Error instance.
    • error.message

{Promise} registerThing(fields, callbacks)
Register thing by app admin. Method interface is same as KiiThing#register(). Please refer to KiiThing document for details.
  // example to use callbacks directly
  // Assume you already have adminContext instance.
  adminContext.registerThing(
      {
          _vendorThingID: "thing-XXXX-YYYY-ZZZZZ",
          _password: "thing-password",
          _thingType: "thermometer",
          yourCustomObj: // Arbitrary key can be used.
          { // Object, Array, Number, String can be used. Should be compatible with JSON.
              yourCustomKey1: "value",
              yourCustomKey2: 100
          }
      },
      {
          success: function(thing) {
              // Register Thing succeeded.
              // Operation using thing instance in the parameter
              // is authored by app admin.
          },
          failure: function(error) {
              // Handle error.
          }
      }
  );
  
  // example to use Promise
  // Assume you already have adminContext instance.
  adminContext.registerThing(
      {
          _vendorThingID: "thing-XXXX-YYYY-ZZZZZ",
          _password: "thing-password",
          _thingType: "thermometer",
          yourCustomObj: // Arbitrary key can be used.
          { // Object, Array, Number, String can be used. Should be compatible with JSON.
              yourCustomKey1: "value",
              yourCustomKey2: 100
          }
      }
  ).then(
      function(thing) {
          // Register Thing succeeded.
          // Operation using thing instance in the parameter
          // is authored by app admin.
      },
      function(error) {
          // Handle error.
      }
  );
Parameters:
{Object} fields
of the thing to be registered. Please refer to KiiThing#register() for the details of fields.
{Object} callbacks Optional
object holds callback functions.
{Function} callbacks.success
callback called when operation succeeded.
{Function} callbacks.failure
callback called when operation failed.
Returns:
{Promise} return promise object.
  • fulfill callback function: function(thing). thing is KiiThing instance with adminToken.
  • reject callback function: function(error). error is an Error instance.
    • error.message

{KiiThing} thingWithID(String)
Creates a reference to a thing operated by app admin.
      // Assume you already have adminContext instance.
      adminContext.thingWithID(thingID);
Parameters:
String
thing id.
Returns:
{KiiThing} A working KiiThing object

{KiiTopic} topicWithName(topicName)
Creates a reference to a topic operated by app admin
Parameters:
{String} topicName
name of the topic. Must be a not empty string.
Returns:
{KiiTopic} topic instance.

{KiiUser} userWithID(String)
Creates a reference to a user operated by app admin.
      Kii.authenticateAsAppAdmin("client-id", "client-secret", {
          success: function(adminContext) {
              var user = adminContext.userWithID("userid");
              // KiiUser operation by app admin is available now.
          },
          failure: function(errorString, errorCode) {
              // auth failed.
          }
      });
Parameters:
String
user id.
Returns:
{KiiUser} A working KiiUser object

Documentation generated by JsDoc Toolkit 2.4.0 on Fri Jan 19 2018 06:50:59 GMT-0000 (UTC)