Options
All
  • Public
  • Public/Protected
  • All
Menu

Class KiiObject

Represents a KiiObject object

Hierarchy

  • KiiObject

Implements

Index

Methods

  • Delete the object from the server

    example
    let obj = . . .; // a KiiObject
    obj.delete().then(theDeletedObject => {
    // do something
    }).catch(error => {
    // do something with the error response
    });

    Returns Promise<KiiObject>

    return promise object.

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

  • Delete the object body from the server. If the KiiObject has not saved on the cloud or deleted or exist but does not have body object, request will be failed. If succeeded, The object body content type will be nullified.

    example
    let obj = . . .; // a KiiObject
    obj.deleteBody().then(theDeletedObject => {
    // do something
    }).catch(error => {
    // do something with the error response
    });

    Returns Promise<KiiObject>

    return promise object.

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

  • downloadBody(): Promise<Blob>
  • Download body data of this object. If the KiiObject has not saved on the cloud or deleted or exist but does not have body object, request will be failed.

    NOTE: this requires XMLHttpRequest Level 2, FileReader and Blob supports. Do not use it in server code.

    example
    let myObject = KiiObject.objectWithURI('put existing object uri here');
    myObject.downloadBody().then(bodyBlob => {
    // Obtaind body contents as bodyBlob.
    // content-type managed in Kii Cloud can be obtained from type attr.
    let contentType = bodyBlob.type;
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<Blob>

    return promise object.
    NOTE: Promise will not handle progress event. Please pass callbacks with progress function to handle progress.

    • fulfill callback function: function(bodyBlob). bodyBlob is the returned body blob object.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiObject instance which this method was called on.
      • error.message

  • get(key: string): any
  • Gets the value associated with the given key

    example
    let obj = . . .; // a KiiObject
    let score = obj.get("score");

    Parameters

    • key: string

      The key to retrieve

    Returns any

  • getBodyContentType(): string
  • getCreated(): number
  • Get the server's creation date of this object

    Returns number

  • getGeoPoint(key: string): undefined | null | KiiGeoPoint
  • Gets the geo point associated with the given key.

    Parameters

    • key: string

      The key of the geo point to retrieve.

    Returns undefined | null | KiiGeoPoint

    KiiGeoPoint tied to the key. undefined if no exists.

  • getID(): undefined | string
  • Get Id of the object or null if the object ID hasn't been assigned.

    Returns undefined | string

  • getKeys(): string[]
  • Gets the array object that contains all keys of custom field. The array of keys from local cache will be returned. To get the latest array of keys from cloud, calling refresh() is necessary prior calling this method. The returned array object does not include reserved keys such as _created, _modified, etc.

    example
    let obj = . . .; // a KiiObject
    for(let key of obj.keys()) {
    }

    Returns string[]

    keys An array of all keys of custom field.

  • getModified(): number
  • Get the modified date of the given object, assigned by the server

    Returns number

  • getObjectType(): null | string
  • Get the application-defined type name of the object

    Returns null | string

  • getUUID(): undefined | string
  • Get the UUID of the given object, assigned by the server

    Returns undefined | string

  • moveBody(targetObjectUri: string): Promise<[KiiObject, string]>
  • Move KiiObject body from an object to another object.

    example
    let targetObject = ...; // Target KiiObject
    let targetObjectUri = targetObject.objectURI();
    sourceObject.moveBody(targetObjectUri).then(params => {
    let theSrcObject = params[0];
    let theTgtObjectUri = params[1];
    // Do something with the objects
    }).catch(error => {
    // Do something with the error response
    });

    Parameters

    • targetObjectUri: string

      A KiiObject URI which KiiObject body is moved to.

    Returns Promise<[KiiObject, string]>

    return promise object.

    • fulfill callback function: function(params). params is Array instance.
      • params[0] is the source KiiObject instance which this method was called on.
      • params[1] is the target targetObjectUri String.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the source KiiObject instance which this method was called on.
      • error.targetObjectUri is the targetObjectUri String.
      • error.message

  • Get the ACL handle for this file

    Any KiiACLEntry objects added or revoked from this ACL object will be appended to/removed from the server on ACL save.

    example
    let obj = . . .; // a KiiObject
    let acl = obj.objectACL();

    Returns KiiACL

    A KiiACL object associated with this KiiObject

  • objectURI(): null | string
  • Get a specifically formatted string referencing the object

    The object must exist in the cloud (have a valid UUID).

    example
    let obj = . . .; // a KiiObject
    let uri = obj.objectURI();

    Returns null | string

    A URI string based on the current object. null if a URI couldn't be generated.

  • ublish object body. Publish object body and obtain public URL links to the body. It doesn't expires. If the KiiObject has not saved on the cloud or deleted or exist but does not have body object, request will be failed.

    example
    let myObject = KiiObject.objectWithURI('put existing object uri here');
    myObject.publishBody().then(publishedUrl => {
    // ex.) You can show publishedUrl in the view.
    }).catch(error => {
    // Handle error.
    });

    Returns Promise<[KiiObject, string]>

    return promise object.

    • fulfill callback function: function(publishedUrl). publishedUrl is the published url string.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiObject instance which this method was called on.
      • error.message

  • publishBodyExpiresAt(expiresAt: number): Promise<[KiiObject, string]>
  • Publish object body with expiration date. Publish object body and obtain public URL links to the body. Expires at specified date If the KiiObject has not saved on the cloud or deleted or exist but does not have body object, request will be failed.

    example
    let myObject = KiiObject.objectWithURI('put existing object uri here');
    let expiresAt = new Date(2014, 11, 24);
    myObject.publishBodyExpiresAt(expiresAt).then(publishedUrl => {
    // ex.) You can show publishedUrl in the view.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • expiresAt: number

      expiration date. should specify future date.

    Returns Promise<[KiiObject, string]>

    return promise object.

    • fulfill callback function: function(publishedUrl). publishedUrl is the published url string.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiObject instance which this method was called on.
      • error.message

  • publishBodyExpiresIn(expiresIn: number): Promise<[KiiObject, string]>
  • Publish object body with expiration duration. Publish object body and obtain public URL links to the body. Expires in specified duration If the KiiObject has not saved on the cloud or deleted or exist but does not have body object, request will be failed.

    example
    let myObject = KiiObject.objectWithURI('put existing object uri here');
    let expiresIn = 60 * 60; // Expires in 1 hour.
    myObject.publishBodyExpiresIn(expiresIn).then(publishedUrl => {
    // ex.) You can show publishedUrl in the view.
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • expiresIn: number

      duration in seconds. greater than 0.

    Returns Promise<[KiiObject, string]>

    return promise object.

    • fulfill callback function: function(publishedUrl). publishedUrl is the published url string.
    • reject callback function: function(error). error is an Error instance.
      • error.target is the KiiObject instance which this method was called on.
      • error.message

  • Updates the local object's data with the user data on the server

    The object must exist on the server. Local data will be overwritten.

    example
    let obj = . . .; // a KiiObject
    obj.refresh().then(theRefreshedObject => {
    // do something with the refreshed object
    }).catch(error => {
    // do something with the error response
    });

    Returns Promise<KiiObject>

    return promise object.

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

  • remove(key: string): void
  • Removes a pair of key/value from this object. This pair is also removed from server when saveAllFields() is succeeded.

    example
    let obj = . . .; // a KiiObject
    obj.remove("score");

    Parameters

    • key: string

      The key to be removed

    Returns void

  • save(overwrite?: boolean): Promise<KiiObject>
  • Create or update the KiiObject on KiiCloud.

    When call this method for the object that has not saved on cloud, will send all fields. Call this method for the object that has saved on cloud, Update only updated fields. Do not send fields that has not updated locally. To send all fields regardless of updates, call KiiObject.saveAllFields.

    example
    let obj = . . .; // a KiiObject
    obj.save().then(theSavedObject => {
    // do something with the saved object
    }).catch(error => {
    // do something with the error response
    });

    Parameters

    • overwrite: boolean = true
      • If overwrite is true:
        • If a KiiObject with the same ID exists in cloud, the local copy will overwrite the remote copy, even if the remote copy is newer.
      • Otherwise:
        • If a KiiObject with the same ID exists in cloud and the remote copy is newer, save will fail.

    Returns Promise<KiiObject>

    return promise object.

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

  • saveAllFields(overwrite?: boolean): Promise<KiiObject>
  • Create or update the KiiObject on KiiCloud.

    When call this method for the object that has not saved on cloud, will send all fields. Call this method for the object that has saved on cloud, Update all field of this object.

    example
    let obj = . . .; // a KiiObject
    obj.saveAllFields().then(theSavedObject => {
    // do something with the saved object
    }).catch(error => {
    // do something with the error response
    });

    Parameters

    • overwrite: boolean = true
      • If overwrite is true:
        • If a KiiObject with the same ID exists in cloud, the local copy will overwrite the remote copy, even if the remote copy is newer.
      • Otherwise:
        • If a KiiObject with the same ID exists in cloud and the remote copy is newer, save will fail.

    Returns Promise<KiiObject>

    return promise object.

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

  • set(key: string, value: any): void
  • Sets a key/value pair to a KiiObject

    If the key already exists, its value will be written over.

    NOTE: Before involving floating point value, please consider using integer instead. For example, use percentage, permil, ppm, etc.
    The reason is:

    • Will dramatically improve the performance of bucket query.
    • Bucket query does not support the mixed result of integer and floating point. ex.) If you use same key for integer and floating point and inquire object with the integer value, objects which has floating point value with the key would not be evaluated in the query. (and vice versa)
    example
    let obj = . . .; // a KiiObject
    obj.set("score", 4298);

    Parameters

    • key: string

      The key to set. if null, empty string or string prefixed with '_' is specified, silently ignored and have no effect. We don't check if actual type is String or not. If non-string type is specified, it will be encoded as key by JSON.stringify()

    • value: any

      The value to be set. Object must be JSON-encodable type (dictionary, array, string, number, boolean) We don't check actual type of the value. It will be encoded as value by JSON.stringify()

    Returns void

  • Set Geo point to this object with the specified key.

    Parameters

    • key: string

      The key to set.

    • point: KiiGeoPoint

      KiiGeoPoint to be tied to the specified key.

    Returns void

  • uploadBody(srcDataBlob: Blob): Promise<KiiObject>
  • Upload body data of this object. If the KiiObject has not saved on the cloud or deleted, request will be failed.

    NOTE: this requires XMLHttpRequest Level 2, FileReader and Blob supports. Do not use it in server code.

    example
    let myObject = Kii.bucketWithName('myBucket').createObject();
    myObject.save().then(obj => {
    let srcData = new Blob(['Hello Blob'], {type: 'text/plain'});
    obj.uploadBody(srcData).then(obj => { // fullfill callback function
    // Upload succeeded.
    }).catch(error => { // reject callback function
    // Handle error.
    });
    }).catch(error => {
    // Handle error.
    });

    Parameters

    • srcDataBlob: Blob

      data to be uploaded. type is used to determin content-type managed in Kii Cloud. If type was not specified in the Blob, 'application/octet-stream' will be used.

    Returns Promise<KiiObject>

    return promise object.
    NOTE: Promise will not handle progress event. Please pass callbacks with progress function to handle progress.

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

  • isValidObjectID(objectID: string): boolean
  • Check if given ID is valid for object ID. Valid pattern: ^[a-zA-Z0-9-_\.]{2,100}$

    Parameters

    • objectID: string

      objectID to be checked.

    Returns boolean

    true if given ID is valid, false otherwise.

  • Generate a new KiiObject based on a given URI

    example
    let group = KiiObject.objectWithURI("kiicloud://myuri");
    

    Parameters

    Returns KiiObject

    A new KiiObject with its parameters filled in from the URI

Generated using TypeDoc