Golem.de API

Golem  alpha

Golem.de API > Golem > Latest.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: Latest.js 1705 2009-04-02 12:58:31Z am $
*/

if(!Golem.Api.Video) {

    Golem.Api.Video = {};

}

/**
 * Get a list of the latest videos via Golem web interface
 *
 * @class Latest
 * @namespace Golem.Api.Video
 * @extends Golem.Api
 * @constructor
 *
 * @param {Integer} maxVideos the number of latest videos
 */
Golem.Api.Video.Latest = function(maxVideos) {

    if(maxVideos) {

        this.maxVideos = maxVideos;

    }

}

/**
 * The URL of the used web service
 *
 * @property URL
 * @type {String}
 * @protected
 */
Golem.Api.Video.Latest.URL = 'http://api.golem.de/api/video/latest/';

/**
 * The type of access method for the web service
 *
 * @property TYPE
 * @type {String}
 * @protected
 */
Golem.Api.Video.Latest.TYPE = 'GET';

Golem.Api.Video.Latest.prototype = {


    /**
     * Shortcut method for traversing the video data
     *
     * <p>
     * Fetches the videos via <i>fetch()</i> first
     * and then calls <i>fnSuccess</i> for every
     * article record like <i>each()</i> does.
     * </p>
     * <p>
     * There is no way to handle errors with this method!
     * </p>
     *
     * @method fetchEach
     *
     * @param {Function} fnSuccess - Function to call for every video record
     * @param {Mixed} params - additional data to pass to the callback function
     */
    fetchEach : function(fnSuccess, params) {

        var oSelf = this;

        this.fetch(
            {
                fnSuccess : function() {

                    if(fnSuccess) {

                        oSelf.each(fnSuccess, params);

                    }

                }
            }

        );

    },

    /**
     * Fetches the list of latest videos via web service
     *
     * <p>
     * In case of a successful request, the <i>obj.fnSuccess</i>-callback function
     * will be called. The first argument for the callback method is the result
     * data of the request. The second argument will be the data provided by <i>obj.params</i>.
     * </p>
     * <p>
     * In case of a failed request, the <i>fnError</i> callback function
     * will be called. The first argument to the callback is the error code,
     * the second ist the error message.
     * </p>
     *
     * @method fetch
     *
     * @param {Object} obj - Object literal specifing the callback methods
     */
    fetch : function(obj) {

        var oSelf = this;

        Golem.Request.doRequest(Golem.Api.Video.Latest.URL + this.maxVideos + '/',
            '',
            function(result) {
                oSelf.data = result.data;

                if(obj.fnSuccess) {

                    var p = undefined;

                    if(obj.params) {

                        p = obj.params;

                    }

                    obj.fnSuccess.call(oSelf, result, p);

                }
            },
            function(errCode, errMsg) {

                oSelf.errorMessage = errMsg;
                oSelf.errorCode    = errCode;

                if(obj.fnError) {

                    var p = undefined;

                    if(obj.params) {

                        p = obj.params;

                    }

                    obj.fnError.call(oSelf, p);

                }

            }, this.timeout
        );

    },

    /**
     * Traverses through the video list.
     *
     * <p>
     * After a succesful request you can traverse
     * through the video list. You pass a callback
     * function to the method, and the method is
     * called for each video.
     * </p>
     * <p>
     * The first argument to this callback function is
     * a <i>video</i> object with the properties:
     * <ul>
     * <li><i>videoid</i> - {Integer} - The video identifier</li>
     * <li><i>title</i> - {String(255)} - The video</li>
     * <li><i>url</i> - {String} - The video URL</li>
     * </ul>
     * The second argument will be the data provided by <i>params</i>.
     * </p>
     *
     * @method each
     *
     * @param {Function} fnCallback - the callback function to call for each article
     * @param {Mixed} params - additional data passed to the callback function
     */
    each : function(fnCallback, params) {

        for(var i = 0; i < this.data.length; i++) {

            if(fnCallback) {

                var r = this.data[i];

                fnCallback.call(this, { videoid : r.videoid, title : r.title, url : r.url }, params);

            }

        }

    },

}

Golem.Api.Video.Latest.prototype.data    = Golem.Api.prototype.data;
Golem.Api.Video.Latest.prototype.getData = Golem.Api.prototype.getData;

Golem.Api.Video.Latest.prototype.errorMessage    = Golem.Api.prototype.errorMessage;
Golem.Api.Video.Latest.prototype.errorCode       = Golem.Api.prototype.errorCode;
Golem.Api.Video.Latest.prototype.getErrorMessage = Golem.Api.prototype.getErrorMessage;
Golem.Api.Video.Latest.prototype.getErrorCode    = Golem.Api.prototype.getErrorCode;

Golem.Api.Video.Latest.prototype.useTimeout = Golem.Api.prototype.useTimeout;
Golem.Api.Video.Latest.prototype.timeout    = Golem.Api.prototype.timeout;

/**
 * Indicates, that the video limit is out of the valid range
 *
 * @property ERROR_LIMIT
 * @type {Integer}
 */
Golem.Api.Video.Latest.ERROR_LIMIT = 102;

Copyright © 2010 Golem.de.