Golem.de API

Golem  alpha

Golem.de API > Golem > Meta.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: Meta.js 2116 2009-07-21 14:42:05Z am $
*/

if(!Golem.Api.Video) {

    Golem.Api.Video = {};

}

/**
 * Fetches the meta data of a video  via Golem.de web interface
 *
 * @class Meta
 * @namespace Golem.Api.Video
 * @extends Golem.Api
 * @constructor
 *
 * @param {Integer} idVideo - Video identifier
 */
Golem.Api.Video.Meta = function(idVideo) {

    if(idVideo) {

        this.idVideo = idVideo;

    }

}

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

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

Golem.Api.Video.Meta.prototype = {

    /**
     * The video identifier
     *
     * @property idVideo
     * @type {Integer}
     * @protected
     */
    idVideo : null,

    /**
     * Marks the video data is populated
     *
     * @property fetchDone
     * @type {Boolean}
     * @protected
     */
    fetchDone : false,

    /**
     * Fetches the video meta data 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>obj.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) {

        if(null == this.idVideo) {

            return false;

        }

        var oSelf = this;

        Golem.Request.doRequest(Golem.Api.Video.Meta.URL+this.idVideo+'/',
            '',
            function(result) {

                oSelf.data      = result.data;
                oSelf.fetchDone = true;

                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, oSelf.errorCode, oSelf.errorMessage, p);

                }

            }, this.timeout
        );

        return true;
    },
    
    /** 
     * Returns the value of the meta data.
     *
     * <p>
     * Available values are:
     * <ul>
     * <li><i>videoid</i> - {Integer} - The video identifier</li>
     * <li><i>embeddedcode</i> - {String} - The HTML code for the embedded videoplayer</li>
     * <li><i>pageurl</i> - {String} - The URL of the video specific page on Golem.de</li>
     * <li><i>title</i> - {String} - The title of the video</li>
     * <li><i>playtime</i> - {Float} - The duration of the video in seconds</li>
     * <li><i>medium</i> - {Object} - The data for the video in regular quality
     *     <ul>
     *      <li><i>videourl</i> - {String} - The URL to the video file</li>
     *      <li><i>width</i> - {Integer} - The video width in pixel</li>
     *      <li><i>height</i> - {Integer} - The video height in pixel</li>
     *      <li><i>size</i> - {Integer} - The filesize of the video in bytes</li>
     *      <li><i>mimetype</i> - {String} - The mimetype of the video file</li>
     *      <li><i>image</i> - {Object} - The teaser image for the video
     *          <ul>
     *              <li><i>url</i> - {String} - The image URL</li>
     *              <li><i>width</i> - {Integer} - The image width in pixel</li>
     *              <li><i>height</i> - {Integer} - The image height in pixel</li>
     *          </ul>
     *      </li>
     *     </ul>
     * </li>
     * <li><i>high</i> - {Object} - The data for the video in high quality (Optional)
     *     <ul>
     *      <li><i>videourl</i> - {String} - The URL to the video file</li>
     *      <li><i>width</i> - {Integer} - The video width in pixel</li>
     *      <li><i>height</i> - {Integer} - The video height in pixel</li>
     *      <li><i>size</i> - {Integer} - The filesize of the video in bytes</li>
     *      <li><i>mimetype</i> - {String} - The mimetype of the video file</li>
     *      <li><i>image</i> - {Object} - The teaser image for the video
     *          <ul>
     *              <li><i>url</i> - {String} - The image URL</li>
     *              <li><i>width</i> - {Integer} - The image width in pixel</li>
     *              <li><i>height</i> - {Integer} - The image height in pixel</li>
     *          </ul>
     *      </li>
     *     </ul>
     * </li>
     * <li><i>apple</i> - {Object} - The data for the video encoded for special devices (Optional)
     *     <ul>
     *      <li><i>videourl</i> - {String} - The URL to the video file</li>
     *      <li><i>width</i> - {Integer} - The video width in pixel</li>
     *      <li><i>height</i> - {Integer} - The video height in pixel</li>
     *      <li><i>size</i> - {Integer} - The filesize of the video in bytes</li>
     *      <li><i>mimetype</i> - {String} - The mimetype of the video file</li>
     *      <li><i>image</i> - {Object} - The teaser image for the video
     *          <ul>
     *              <li><i>url</i> - {String} - The image URL</li>
     *              <li><i>width</i> - {Integer} - The image width in pixel</li>
     *              <li><i>height</i> - {Integer} - The image height in pixel</li>
     *          </ul>
     *      </li>
     *     </ul>
     * </li>
     * </ul>
     * </p>
     *
     * <p>
     * If you ask for a keyword, that does not exists, the method returns 
     * <i>undefined</i>
     * </p>
     *
     * @method getValue
     *
     * @param {String} key - one of the value names
     *
     * @return {Mixed} the value or <i>undefined</i>
     */
    getValue : function(key) {
      
        if(!this.fetchDone || !this.data[key]) {
            return undefined;
        }

        return this.data[key];
    }

}

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

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

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

/**
 * Indicates a missing or invalid video identifier
 *
 * @property ERROR_INVALID_IDENTIFER
 * @type {Integer}
 */
Golem.Api.Video.Meta.ERROR_INVALID_IDENTIFIER = 32;

Copyright © 2010 Golem.de.