Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KiiThing

note

KiiThing does not support removal of fields from Server.

property

{Object} fields of this thing. For details refer to KiiThing.register

Hierarchy

  • KiiThing

Implements

Index

Properties

fields: null | ThingFields = null

Methods

  • bucketWithName(bucketName: string): KiiBucket
  • Instantiate bucket belongs to this thing.

    Parameters

    • bucketName: string

      name of the bucket.

    Returns KiiBucket

    bucket instance.

  • Delete registered thing in Kii Cloud.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    It will delete bucket, topic which belongs to this thing, entity belongs to the bucket/topic and all ownership information of thing. This operation can not be reverted. Please carefully use this.

    example
    // assume thing is already registered.
    thing.deleteThing().then(thing => {
    // Delete succeeded.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • Disable the thing.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own Thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    After succeeded, access token published for thing is disabled. In a result, only the app administrator and owners of thing can access the thing. Used when user lost the thing and avoid using by unknown users. It doesn't throw error when the thing is already disabled.

    example
    // assume thing is already registered.
    thing.disable().then(thing => {
    // Disable succeeded.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • Enable the thing.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own Thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    After succeeded, If thing is registered with "persistentToken" option, token should be recovered (Access token which is used before disabling can be available). Otherwise, it does not recovered. It doesn't throw error when the thing is already enabled.

    example
    // assume thing is already registered.
    thing.enable().then(thing => {
    // Disable succeeded.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • Creates a reference to a encrypted bucket for this thing

    The bucket will be created/accessed within this thing's scope

    example
    let thing = . . .; // a KiiThing
    let bucket = thing.encryptedBucketWithName("myBucket");

    Parameters

    • bucketName: string

      The name of the bucket the user should create/access

    Returns KiiEncryptedBucket

    A working KiiEncryptedBucket object

  • getAccessToken(): string
  • Get access token of this thing.

    Returns string

    access token of this thing.

  • getCreated(): null | Date
  • Get created time of this thing.

    Returns null | Date

    created time of this thing.

  • getDisabled(): boolean
  • Get disabled status of this thing.

    Returns boolean

    true if thing is disabled, false otherwise.

  • getOnlineStatusModifiedAt(): null | Date
  • Get online status modified date of the thing.

    Returns null | Date

    online status modified time of this thing. The date will be null initially until the thing is connected for the first time.

  • getThingID(): null | string
  • getVendorThingID(): undefined | string
  • Get vendor thing ID.

    Returns undefined | string

    vendor thing id

  • isOnline(): null | boolean
  • Get online status of the thing.

    Returns null | boolean

    true if the thing is online, false otherwise. The return value will be null initially until the thing is connected for the first time.

  • isOwner<T>(owner: T): Promise<[KiiThing, T, boolean]>
  • Check if user/ group is owner of the thing.
    This API is authorized by owner of thing.
    Need user login before execute this API.
    To let users to own Thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing/user is already registered.
    let user = KiiUser.userWithURI("kiicloud://users/xxxyyyy");
    thing.isOwner(user).then(params => {
    let thing = params[0];
    let user = params[1];
    let isOwner = params[2];
    if (isOwner) {
    // user is owner of the thing.
    } else {
    // user is not owner of the thing.
    }
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • owner: T

      whether the instance is owner of thing or not.

    Returns Promise<[KiiThing, T, boolean]>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is the KiiThing instance which this method was called on.
      • params[1] is a KiiUser/KiiGroup instance.
      • params[2] is Boolean value, true is the user/group is owner of the thing, otherwise false.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • listTopics(paginationKey?: string): Promise<[KiiTopic[], null | string]>
  • Gets a list of topics in this thing scope

    example
    let thing = . . .; // a KiiThing
    thing.listTopics().then(params => {
    let topicList = params[0];
    let nextPaginationKey = params[1];
    // do something with the result
    for (let i = 0; i < topicList.length; i++) {
    let topic = topicList[i];
    }
    if (nextPaginationKey != null) {
    thing.listTopics(null, nextPaginationKey)
    .then(params => {...})
    .catch(error => {...});
    }
    }).catch(error => {
    // do something with the error response
    });

    Parameters

    • paginationKey: string = ""

    Returns Promise<[KiiTopic[], null | string]>

    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 the KiiThing instance which this method was called on.
      • error.message

  • Retrieve the latest thing information from KiiCloud.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing is already registered.
    thing.refresh().then(thing => {
    // Refresh succeeded.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • registerOwner<T>(owner: T): Promise<[KiiThing, T]>
  • Register user/group as owner of this thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    deprecated

    Use KiiThing.registerOwnerWithPassword instead.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    thing.registerOwner(group).then(params => {
    // Register owner succeeded.
    let thing = params[0];
    let group = params[1];
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • owner: T

      to be registered as owner.

    Returns Promise<[KiiThing, T]>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is the KiiThing instance which this method was called on.
      • params[1] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • registerOwnerWithPassword<T>(owner: T, password: string): Promise<[KiiThing, T]>
  • Register user/group as owner of this thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    thing.registerOwnerWithPassword(group, "Thing password").then(params => {
    // Register owner succeeded.
    let thing = params[0];
    let group = params[1];
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • owner: T

      to be registered as owner.

    • password: string

    Returns Promise<[KiiThing, T]>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is the KiiThing instance which this method was called on.
      • params[1] is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • topicWithName(topicName: string): KiiTopic
  • Instantiate topic belongs to this thing.

    Parameters

    • topicName: string

      name of the topic. Must be a not empty string.

    Returns KiiTopic

    topic instance.

  • unregisterOwner<T>(owner: T): Promise<[KiiThing, T]>
  • Remove ownership of thing from specified user/group.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    thing.unregisterOwner(group).then(params => {
    // Unregister owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • owner: T

      to be unregistered.

    Returns Promise<[KiiThing, T]>

    return promise object.

    • fulfill callback function: function(params). params is an Array instance.
      • params[0] is the KiiThing instance which this method was called on.
      • params[1] is a KiiUser/KiiGroup instance which had ownership of the thing removed.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • Update registered thing information in Kii Cloud
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    see

    KiiThing.register

    example
    // assume thing is already registered.
    thing.fields._stringField1 = "new string value";
    thing.fields.customObject = {
    "customField1" : "abcd",
    "customField2" : 123
    };
    thing.update().then(thing => {
    // Update succeeded.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • updatePassword(newPassword: string): Promise<KiiThing>
  • Updates thing password. This method can be used only by app admin.

    example
    // assume thing is already registered and you had an adminContext.
    adminContext.thingWithID(thing.getThingID()).updatePassword("new password").then(thing => {
    // Update succeeded.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • newPassword: string

      new password

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiThing instance which this method was called on.
      • error.message

  • Perform a query to get the owned things.

    The query will be executed against the server, returning a result set.

    Parameters

    Returns Promise<KiiThingQueryResult>

    return promise object.

    • fulfill callback function: function(result). result is KiiThingQueryResult instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Load thing with thing id given by Kii Cloud.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own Thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    thing id can be obtained by getThingID

    example
    KiiThing.loadWithVendorThingID("thing-xxxx-yyyy").then(thing => {
    // Load succeeded.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Load thing with given vendor thing id.
    This API is authorized by owner of thing.
    Need user login who owns this thing before execute this API.
    To let users to own Thing, please call KiiThing.registerOwner
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    KiiThing.loadWithVendorThingID("thing-xxxx-yyyy").then(thing => {
    // Load succeeded.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • Register thing in KiiCloud.
    This API doesnt require users login Anonymous user can register thing.
    Propertis started with '' in the fields is reserved by Kii Cloud.
    Those properties are indexed in Kii Cloud storage.
    Properties not started with '
    ' is custom properties defined by developer.
    Custom properties are not indexed in KiiCloud storage.
    Following properties are readonly and ignored on creation/update of thing.
    '_thingID', '_created', '_accessToken'
    Following properties are readonly after creation and will be ignored on update of thing.
    '_vendorThingID', 'password'
    As Property prefixed with '
    ' is reserved by Kii Cloud, properties other than ones described in the parameter secion and '_layoutPosition' are ignored on creation/update of thing.
    Those ignored properties won't be removed from fields object passed as argument. However it won't be reflected to fields object property of created/updated Thing.

    example
    KiiThing.register(
    {
    _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(thing => {
    // Register Thing succeeded.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    Returns Promise<KiiThing>

    return promise object.

    • fulfill callback function: function(thing). thing is a KiiThing instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • registerOwnerWithThingID<T>(thingID: string, owner: T, app?: KiiApplication): Promise<T>
  • Register user/group as owner of specified thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    deprecated

    Use KiiThing.registerOwnerWithThingIDAndPassword instead.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    KiiThing.registerOwnerWithThingID("th.xxxx-yyyy-zzzz", group).then(params => {
    // Register owner succeeded.
    let group = params[0];
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • thingID: string

      The ID of thing

    • owner: T

      instance of KiiUser/KiiGroup to be registered as owner.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<T>

    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

  • registerOwnerWithThingIDAndPassword<T>(thingID: string, owner: T, password: string, app?: KiiApplication): Promise<T>
  • Register user/group as owner of specified thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    KiiThing.registerOwnerWithThingIDAndPassword("th.xxxx-yyyy-zzzz", group, "Thing password").then(owner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • thingID: string

      The ID of thing

    • owner: T

      instance of KiiUser/KiiGroup to be registered as owner.

    • password: string
    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(owner).
      • owner is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

  • registerOwnerWithVendorThingID<T>(vendorThingID: string, owner: T, app?: KiiApplication): Promise<T>
  • Register user/group as owner of specified thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    deprecated

    Use KiiThing.registerOwnerWithVendorThingIDAndPassword instead.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    KiiThing.registerOwnerWithVendorThingID("xxxx-yyyy-zzzz", group).then(group => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • vendorThingID: string

      The vendor thing ID of thing

    • owner: T

      instance of KiiUser/KiiGroup to be registered as owner.

    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<T>

    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

  • registerOwnerWithVendorThingIDAndPassword<T>(vendorThingID: string, owner: T, password: string, app?: KiiApplication): Promise<T>
  • Register user/group as owner of specified thing.
    Need user login before execute this API.
    Note: if you obtain thing instance from KiiAppAdminContext, API is authorized by app admin.

    example
    // assume thing/group is already registered.
    let group = KiiGroup.groupWithURI("kiicloud://groups/xxxyyyy");
    KiiThing.registerOwnerWithVendorThingIDAndPassword("xxxx-yyyy-zzzz", group, "Thing password").then(owner => {
    // Register owner succeeded.
    }).catch(error => {
    // Handle error.
    });

    Type parameters

    Parameters

    • vendorThingID: string

      The vendor thing ID of thing

    • owner: T

      instance of KiiUser/KiiGroup to be registered as owner.

    • password: string
    • app: KiiApplication = KiiApplication.globalApp

      KiiApplication instance. When omitted, KiiApplication.globalApp is used.

    Returns Promise<T>

    return promise object.

    • fulfill callback function: function(owner).
      • owner is a KiiUser/KiiGroup instance.
    • reject callback function: function(error). error is an Error instance.
      • error.message

Generated using TypeDoc