TigerZF
🌐Español

64.28. Zend_Service_SlideShare

El componente Zend_Service_SlideShare se usa para interactuar con los servicios web de slideshare.net para alojar presentaciones de diapositivas en línea. Con este componente, puede incrustar presentaciones de diapositivas alojadas en este sitio web dentro de un sitio web e incluso subir nuevas presentaciones a su cuenta.

64.28.1. Primeros pasos con Zend_Service_SlideShare

Para poder usar el componente Zend_Service_SlideShare primero debe crear una cuenta en los servidores de slideshare.net (puede encontrar más información aquí) con el fin de recibir una clave de API, nombre de usuario, contraseña y un valor de secreto compartido, todo lo cual se necesita para usar el componente Zend_Service_SlideShare.

Una vez que haya configurado una cuenta, puede comenzar a usar el componente Zend_Service_SlideShare creando una nueva instancia del objeto Zend_Service_SlideShare y proporcionando estos valores como se muestra a continuación:

// Create a new instance of the component
$ss = new Zend_Service_SlideShare('APIKEY',
                                  'SHAREDSECRET',
                                  'USERNAME',
                                  'PASSWORD');

64.28.2. El objeto SlideShow

Todas las presentaciones de diapositivas en el componente Zend_Service_SlideShare se representan usando el objeto Zend_Service_SlideShare_SlideShow (tanto al recuperar como al subir nuevas presentaciones de diapositivas). Como referencia se proporciona a continuación una versión en pseudocódigo de esta clase.

class Zend_Service_SlideShare_SlideShow {

    /**
     * Retrieves the location of the slide show
     */
    public function getLocation() {
        return $this->_location;
    }

    /**
     * Gets the transcript for this slide show
     */
    public function getTranscript() {
        return $this->_transcript;
    }

    /**
     * Adds a tag to the slide show
     */
    public function addTag($tag) {
        $this->_tags[] = (string)$tag;
        return $this;
    }

    /**
     * Sets the tags for the slide show
     */
    public function setTags(Array $tags) {
        $this->_tags = $tags;
        return $this;
    }

    /**
     * Gets all of the tags associated with the slide show
     */
    public function getTags() {
        return $this->_tags;
    }

    /**
     * Sets the filename on the local filesystem of the slide show
     * (for uploading a new slide show)
     */
    public function setFilename($file) {
        $this->_slideShowFilename = (string)$file;
        return $this;
    }

    /**
     * Retrieves the filename on the local filesystem of the slide show
     * which will be uploaded
     */
    public function getFilename() {
        return $this->_slideShowFilename;
    }

    /**
     * Gets the ID for the slide show
     */
    public function getId() {
        return $this->_slideShowId;
    }

    /**
     * Retrieves the HTML embed code for the slide show
     */
    public function getEmbedCode() {
        return $this->_embedCode;
    }

    /**
     * Retrieves the Thumbnail URi for the slide show
     */
    public function getThumbnailUrl() {
        return $this->_thumbnailUrl;
    }

    /**
     * Sets the title for the Slide show
     */
    public function setTitle($title) {
        $this->_title = (string)$title;
        return $this;
    }

    /**
     * Retrieves the Slide show title
     */
    public function getTitle() {
        return $this->_title;
    }

    /**
     * Sets the description for the Slide show
     */
    public function setDescription($desc) {
        $this->_description = (string)$desc;
        return $this;
    }

    /**
     * Gets the description of the slide show
     */
    public function getDescription() {
        return $this->_description;
    }

    /**
     * Gets the numeric status of the slide show on the server
     */
    public function getStatus() {
        return $this->_status;
    }

    /**
     * Gets the textual description of the status of the slide show on
     * the server
     */
    public function getStatusDescription() {
        return $this->_statusDescription;
    }

    /**
     * Gets the permanent link of the slide show
     */
    public function getPermaLink() {
        return $this->_permalink;
    }

    /**
     * Gets the number of views the slide show has received
     */
    public function getNumViews() {
        return $this->_numViews;
    }
}
[Note] Nota

La pseudo-clase anterior solo muestra los métodos que deberían usar los desarrolladores finales. Los demás métodos disponibles son internos al componente.

Al usar el componente Zend_Service_SlideShare, esta clase de datos se usará con frecuencia para explorar o añadir nuevas presentaciones de diapositivas hacia o desde el servicio web.

64.28.3. Recuperar una única presentación de diapositivas

El uso más sencillo del componente Zend_Service_SlideShare es la recuperación de una única presentación de diapositivas mediante el ID de presentación proporcionado por la aplicación slideshare.net, y se realiza llamando al método getSlideShow() de un objeto Zend_Service_SlideShare y usando el objeto Zend_Service_SlideShare_SlideShow resultante como se muestra.

// Create a new instance of the component
$ss = new Zend_Service_SlideShare('APIKEY',
                                  'SHAREDSECRET',
                                  'USERNAME',
                                  'PASSWORD');

$slideshow = $ss->getSlideShow(123456);

print "Slide Show Title: {$slideshow->getTitle()}<br/>\n";
print "Number of views: {$slideshow->getNumViews()}<br/>\n";

64.28.4. Recuperar grupos de presentaciones de diapositivas

Si no conoce el ID específico de una presentación de diapositivas que le interesa recuperar, puede recuperar grupos de presentaciones de diapositivas usando uno de tres métodos:

  • Presentaciones de diapositivas de una cuenta específica

    Puede recuperar presentaciones de diapositivas de una cuenta específica usando el método getSlideShowsByUsername() y proporcionando el nombre de usuario del cual deben recuperarse las presentaciones

  • Presentaciones de diapositivas que contienen etiquetas específicas

    Puede recuperar presentaciones de diapositivas que contengan una o más etiquetas específicas usando el método getSlideShowsByTag() y proporcionando una o más etiquetas que la presentación de diapositivas debe tener asignadas para poder ser recuperada

  • Presentaciones de diapositivas por grupo

    Puede recuperar presentaciones de diapositivas que sean miembros de un grupo específico usando el método getSlideShowsByGroup() y proporcionando el nombre del grupo al que la presentación de diapositivas debe pertenecer para poder ser recuperada

Para cada uno de los métodos anteriores de recuperación de múltiples presentaciones de diapositivas se usa un enfoque similar. A continuación se muestra un ejemplo del uso de cada método:

// Create a new instance of the component
$ss = new Zend_Service_SlideShare('APIKEY',
                                  'SHAREDSECRET',
                                  'USERNAME',
                                  'PASSWORD');

$starting_offset = 0;
$limit = 10;

// Retrieve the first 10 of each type
$ss_user = $ss->getSlideShowsByUser('username', $starting_offset, $limit);
$ss_tags = $ss->getSlideShowsByTag('zend', $starting_offset, $limit);
$ss_group = $ss->getSlideShowsByGroup('mygroup', $starting_offset, $limit);

// Iterate over the slide shows
foreach($ss_user as $slideshow) {
   print "Slide Show Title: {$slideshow->getTitle}<br/>\n";
}

64.28.5. Políticas de caché de Zend_Service_SlideShare

Por defecto, Zend_Service_SlideShare almacenará en caché automáticamente en el sistema de archivos (ruta por defecto /tmp) cualquier solicitud realizada al servicio web durante 12 horas. Si desea cambiar este comportamiento, debe proporcionar su propio objeto Zend_Cache usando el método setCacheObject() como se muestra:

$frontendOptions = array(
                        'lifetime' => 7200,
                        'automatic_serialization' => true);
$backendOptions  = array(
                        'cache_dir' => '/webtmp/');

$cache = Zend_Cache::factory('Core',
                             'File',
                             $frontendOptions,
                             $backendOptions);

$ss = new Zend_Service_SlideShare('APIKEY',
                                  'SHAREDSECRET',
                                  'USERNAME',
                                  'PASSWORD');
$ss->setCacheObject($cache);

$ss_user = $ss->getSlideShowsByUser('username', $starting_offset, $limit);

64.28.6. Cambiar el comportamiento del cliente HTTP

Si por cualquier motivo desea cambiar el comportamiento del cliente HTTP al realizar la solicitud al servicio web, puede hacerlo creando su propia instancia del objeto Zend_Http_Client (ver Zend_Http). Esto es útil, por ejemplo, cuando es deseable establecer el tiempo de espera de la conexión a un valor distinto del predeterminado, como se muestra:

$client = new Zend_Http_Client();
$client->setConfig(array('timeout' => 5));

$ss = new Zend_Service_SlideShare('APIKEY',
                                  'SHAREDSECRET',
                                  'USERNAME',
                                  'PASSWORD');
$ss->setHttpClient($client);
$ss_user = $ss->getSlideShowsByUser('username', $starting_offset, $limit);