Golem.de API

Golem  alpha

Golem.de API > Golem > Api.js (source view)
Search:
 
Filters
/*
Copyright (c) 2009, Klass und Ihlenfeld Verlag GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.
    * Neither the name of the Klass und Ihlenfeld Verlag GmbH nor the names of its
      contributors may be used to endorse or promote products derived from
      this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE

$Id: Api.js 1587 2009-03-26 14:46:09Z am $
*/

if(!Golem) {
    /**
     * Base namespace for all Golem functionality
     *
     * @namespace Golem
     * @module Golem
     */
    var Golem = {};
}

/**
 * Abstract base class for API webinterface operations
 *
 * @class Api
 * @namespace Golem
 */
Golem.Api = function() {
};

Golem.Api.prototype = {

    /**
     * Storage for the video list
     *
     * @property data
     * @type {Array}
     * @protected
     */
    data : [],

    /**
     * Error message after a failed request
     *
     * @property errorMessage
     * @type {String}
     * @protected
     */
    errorMessage : '',

    /**
     * Error code after a failed request
     *
     * @property errorCode
     * @type {Integer}
     * @protected
     */
    errorCode : -1,

    /**
     * Properties for the request timeout
     *
     * @property timeout
     * @type {Object}
     * @protected
     */
    timeout : {

        /**
         * Duration of the timeout in Milliseconds
         *
         * @property timeout.duration
         * @type {Integer}
         * @protected
         */
        duration : 0,

        /**
         * Method to call in case of an timeout
         *
         * @property timeout.fn
         * @type {Function}
         * @protected
         */
        fn       : null
    },

    /**
     * Returns the data set retrieved by the request
     *
     * @method getData
     *
     * @return {Mixed} - the service specific result set
     */
    getData : function() {

        return this.data;

    },

    /**
     * Enables the timeout for the request.
     *
     * <p>
     * Because of the used JSONP technic, it is not
     * possible to determine, when a request failed.
     * So you can provide a timeout and a function to
     * call after the timeout is finished and the
     * request is not finished.
     * </p>
     *
     * <p>
     * If you call this method without any arguments,
     * the timeout will be disabled. The same effect
     * will be a timeout of <i>0</i> milliseconds.
     * </p>
     *
     * <p>
     * Be careful! If the timeout occurs, the request
     * may be still finish successfully!
     * </p>
     *
     * @method useTimeout
     *
     * @param {Integer} timeout - the timeout in milliseconds
     * @param {Function} fnTimeout - the function to call
     */
    useTimeout : function(timeout, fnTimeout) {

        if(timeout) {

            this.timeout.duration = timeout;

            if(fnTimeout) {

                this.timeout.fn       = fnTimeout;

            }

        } else {

            this.timeout.duration = 0;
            this.timeout.fn       = fnTimeout;

        }

    },

    /**
     * Returns the error code after a failed request.
     *
     * @method getErrorCode
     *
     * @return {Integer}
     */
    getErrorCode : function() {

        return this.errorCode;

    },

     /**
     * Returns the error message after a failed request.
     *
     * @method getErrorMessage
     *
     * @return {Integer}
     */
    getErrorMessage : function() {

        return this.errorMessage;

    }

}

Copyright © 2010 Golem.de.