lib/WixClient.js
function WixActivity() {

    /**
     * Updates to the existing contact that performed this activity. The structure of this object should match the schema for Contact, with the relevant fields updated.
     * @member
     * @type {Object}
     */
    this.contactUpdate = schemaFactory(this.TYPES.CONTACT_CREATE.name);
    /**
     * Configures this Activity with a given type
     * @param {ActivityType} type the type of the Activity to create
     * @returns {WixActivity}
     */
    this.withActivityType = function(type) {
        this.activityType = type.name;
        this.activityInfo = schemaFactory(type.name);
        return this;
    };

    /**
     * Configures the activityLocationUrl of this Activity
     * @param {string} url The URL of the Activities location
     * @returns {WixActivity}
     */
    this.withLocationUrl = function(url) {
        this.activityLocationUrl = url;
        return this;
    };

    /**
     * Configures the details of this Activity
     * @param {string} summary A summary of this Activity
     * @param {string} additionalInfoUrl a link to additional information about this Activity
     * @returns {WixActivity}
     */
    this.withActivityDetails = function(summary, additionalInfoUrl) {
        if(summary !== null && summary !== undefined) {
            this.activityDetails.summary = summary;
        }
        if(additionalInfoUrl !== null && additionalInfoUrl !== undefined) {
            this.activityDetails.additionalInfoUrl = additionalInfoUrl;
        }
        return this;
    };

    var readOnlyTypes = [
        this.TYPES.CONTACT_CREATE.name
    ];
    this.isWritable = function() {
        return (readOnlyTypes.indexOf(this.activityType) == -1);
    };

    this.isValid = function() {
        //TODO provide slightly better validation
        return this.activityLocationUrl !== null
            && this.activityType !== null
            && this.activityDetails.summary !== null
            && this.createdAt !== null
            && this.activityDetails.additionalInfoUrl !== null;
    };

    /**
     * Posts the Activity to Wix.  Returns a Promise for an id
     * @param {string} sessionToken The current session token for the active Wix site visitor
     * @param {Wix} wix A Wix API object
     * @returns {Promise.<string, error>} A new id, or an error
     */
    this.post = function(sessionToken, wix) {
        return wix.Activities.postActivity(this, sessionToken);
    };

    function removeNulls(obj){
        var isArray = obj instanceof Array;
        for (var k in obj){
            if (obj[k]===null) isArray ? obj.splice(k,1) : delete obj[k];
            else if (typeof obj[k]=="object") removeNulls(obj[k]);
        }
    }

    this.toJSON = function() {
        var _this = this;
        removeNulls(_this.contactUpdate);
        removeNulls(_this.activityInfo);
        return {
            createdAt : _this.createdAt,
            activityType : _this.activityType,
            contactUpdate : _this.contactUpdate,
            activityLocationUrl : _this.activityLocationUrl,
            activityDetails : _this.activityDetails,
            activityInfo: _this.activityInfo
        };
    };
}
function WixActivity() {

    /**
     * Updates to the existing contact that performed this activity. The structure of this object should match the schema for Contact, with the relevant fields updated.
     * @member
     * @type {Object}
     */
    this.contactUpdate = schemaFactory(this.TYPES.CONTACT_CREATE.name);
    /**
     * Configures this Activity with a given type
     * @param {ActivityType} type the type of the Activity to create
     * @returns {WixActivity}
     */
    this.withActivityType = function(type) {
        this.activityType = type.name;
        this.activityInfo = schemaFactory(type.name);
        return this;
    };

    /**
     * Configures the activityLocationUrl of this Activity
     * @param {string} url The URL of the Activities location
     * @returns {WixActivity}
     */
    this.withLocationUrl = function(url) {
        this.activityLocationUrl = url;
        return this;
    };

    /**
     * Configures the details of this Activity
     * @param {string} summary A summary of this Activity
     * @param {string} additionalInfoUrl a link to additional information about this Activity
     * @returns {WixActivity}
     */
    this.withActivityDetails = function(summary, additionalInfoUrl) {
        if(summary !== null && summary !== undefined) {
            this.activityDetails.summary = summary;
        }
        if(additionalInfoUrl !== null && additionalInfoUrl !== undefined) {
            this.activityDetails.additionalInfoUrl = additionalInfoUrl;
        }
        return this;
    };

    var readOnlyTypes = [
        this.TYPES.CONTACT_CREATE.name
    ];
    this.isWritable = function() {
        return (readOnlyTypes.indexOf(this.activityType) == -1);
    };

    this.isValid = function() {
        //TODO provide slightly better validation
        return this.activityLocationUrl !== null
            && this.activityType !== null
            && this.activityDetails.summary !== null
            && this.createdAt !== null
            && this.activityDetails.additionalInfoUrl !== null;
    };

    /**
     * Posts the Activity to Wix.  Returns a Promise for an id
     * @param {string} sessionToken The current session token for the active Wix site visitor
     * @param {Wix} wix A Wix API object
     * @returns {Promise.<string, error>} A new id, or an error
     */
    this.post = function(sessionToken, wix) {
        return wix.Activities.postActivity(this, sessionToken);
    };

    function removeNulls(obj){
        var isArray = obj instanceof Array;
        for (var k in obj){
            if (obj[k]===null) isArray ? obj.splice(k,1) : delete obj[k];
            else if (typeof obj[k]=="object") removeNulls(obj[k]);
        }
    }

    this.toJSON = function() {
        var _this = this;
        removeNulls(_this.contactUpdate);
        removeNulls(_this.activityInfo);
        return {
            createdAt : _this.createdAt,
            activityType : _this.activityType,
            contactUpdate : _this.contactUpdate,
            activityLocationUrl : _this.activityLocationUrl,
            activityDetails : _this.activityDetails,
            activityInfo: _this.activityInfo
        };
    };
}
function WixActivity ( ) { /**
     * Updates to the existing contact that performed this activity. The structure of this object should match the schema for Contact, with the relevant fields updated.
     * @member
     * @type {Object}
     */ this . contactUpdate = schemaFactory ( this . TYPES . CONTACT_CREATE . name ) ; /**
     * Configures this Activity with a given type
     * @param {ActivityType} type the type of the Activity to create
     * @returns {WixActivity}
     */ this . withActivityType = function ( type ) { this . activityType = type . name ; this . activityInfo = schemaFactory ( type . name ) ; return this ; } ; /**
     * Configures the activityLocationUrl of this Activity
     * @param {string} url The URL of the Activities location
     * @returns {WixActivity}
     */ this . withLocationUrl = function ( url ) { this . activityLocationUrl = url ; return this ; } ; /**
     * Configures the details of this Activity
     * @param {string} summary A summary of this Activity
     * @param {string} additionalInfoUrl a link to additional information about this Activity
     * @returns {WixActivity}
     */ this . withActivityDetails = function ( summary , additionalInfoUrl ) { if ( summary !== null && summary !== undefined ) { this . activityDetails . summary = summary ; } if ( additionalInfoUrl !== null && additionalInfoUrl !== undefined ) { this . activityDetails . additionalInfoUrl = additionalInfoUrl ; } return this ; } ; var readOnlyTypes = [ this . TYPES . CONTACT_CREATE . name ] ; this . isWritable = function ( ) { return ( readOnlyTypes . indexOf ( this . activityType ) == - 1 ) ; } ; this . isValid = function ( ) { //TODO provide slightly better validation return this . activityLocationUrl !== null && this . activityType !== null && this . activityDetails . summary !== null && this . createdAt !== null && this . activityDetails . additionalInfoUrl !== null ; } ; /**
     * Posts the Activity to Wix.  Returns a Promise for an id
     * @param {string} sessionToken The current session token for the active Wix site visitor
     * @param {Wix} wix A Wix API object
     * @returns {Promise.<string, error>} A new id, or an error
     */ this . post = function ( sessionToken , wix ) { return wix . Activities . postActivity ( this , sessionToken ) ; } ; function removeNulls ( obj ) { var isArray = obj instanceof Array ; for ( var k in obj ) { if ( obj [ k ] === null ) isArray ? obj . splice ( k , 1 ) : delete obj [ k ] ; else if ( typeof obj [ k ] == "object" ) removeNulls ( obj [ k ] ) ; } } this . toJSON = function ( ) { var _this = this ; removeNulls ( _this . contactUpdate ) ; removeNulls ( _this . activityInfo ) ; return { createdAt : _this . createdAt , activityType : _this . activityType , contactUpdate : _this . contactUpdate , activityLocationUrl : _this . activityLocationUrl , activityDetails : _this . activityDetails , activityInfo : _this . activityInfo } ; } ; }
Represents a new Activity in the Wix ecosystem, allowing for easy construction and creation
@mixes BaseWixAPIObject
@mixes WixActivityData
@constructor
@alias WixActivity
@class
Represents a new Activity in the Wix ecosystem allowing for easy construction and creation