Exemple #1
0
 /**
  * Uploads the specified Slide show the the server
  *
  * @param Zend\Service\SlideShare\SlideShow $ss The slide show object representing the slide show to upload
  * @param boolean $makeSourcePublic Determines if the slide show's source file is public or not upon upload
  * @throws \Zend\Service\SlideShare\Exception
  * @return Zend\Service\SlideShare\SlideShow The passed Slide show object, with the new assigned ID provided
  */
 public function uploadSlideShow(SlideShow $ss, $makeSourcePublic = true)
 {
     $timestamp = time();
     $params = array('api_key' => $this->getApiKey(), 'ts' => $timestamp, 'hash' => sha1($this->getSharedSecret() . $timestamp), 'username' => $this->getUserName(), 'password' => $this->getPassword(), 'slideshow_title' => $ss->getTitle(), 'make_src_public' => $makeSourcePublic ? 'Y' : 'N');
     $description = $ss->getDescription();
     $tags = $ss->getTags();
     $filename = $ss->getFilename();
     if (!file_exists($filename) || !is_readable($filename)) {
         throw new Exception\InvalidArgumentException("Specified Slideshow for upload not found or unreadable");
     }
     if (!empty($description)) {
         $params['slideshow_description'] = $description;
     } else {
         $params['slideshow_description'] = "";
     }
     if (!empty($tags)) {
         $tmp = array();
         foreach ($tags as $tag) {
             $tmp[] = "\"{$tag}\"";
         }
         $params['slideshow_tags'] = implode(' ', $tmp);
     } else {
         $params['slideshow_tags'] = "";
     }
     $client = $this->getHttpClient();
     $client->setUri(self::SERVICE_UPLOAD_URI);
     $client->setParameterPost($params);
     $client->setFileUpload($filename, "slideshow_srcfile");
     try {
         $response = $client->request('POST');
     } catch (Client\Exception $e) {
         throw new Client\Exception\RuntimeException("Service Request Failed: {$e->getMessage()}", 0, $e);
     }
     $sxe = simplexml_load_string($response->getBody());
     if ($sxe->getName() == "SlideShareServiceError") {
         $message = (string) $sxe->Message[0];
         list($code, $error_str) = explode(':', $message);
         throw new Exception\RuntimeException(trim($error_str), $code);
     }
     if (!$sxe->getName() == "SlideShowUploaded") {
         throw new Exception\RuntimeException("Unknown XML Respons Received");
     }
     $ss->setId((int) (string) $sxe->SlideShowID);
     return $ss;
 }
    public function testSlideShowObj()
    {
        $ss = new SlideShare\SlideShow();

        $ss->setDescription("Foo");
        $ss->setEmbedCode("Bar");
        $ss->setFilename("Baz");
        $ss->setId(123);
        $ss->setLocation("Somewhere");
        $ss->setNumViews(4432);
        $ss->setPermaLink("nowhere");
        $ss->setStatus(124);
        $ss->setStatusDescription("Boo");
        $ss->setTags(array('bar', 'baz'));
        $ss->addTag('fon');
        $ss->setThumbnailUrl('asdf');
        $ss->setTitle('title');
        $ss->setTranscript('none');

        $this->assertEquals($ss->getDescription(), "Foo");
        $this->assertEquals($ss->getEmbedCode(), "Bar");
        $this->assertEquals($ss->getFilename(), "Baz");
        $this->assertEquals($ss->getId(), 123);
        $this->assertEquals($ss->getLocation(), "Somewhere");
        $this->assertEquals($ss->getNumViews(), 4432);
        $this->assertEquals($ss->getPermaLink(), "nowhere");
        $this->assertEquals($ss->getStatus(), 124);
        $this->assertEquals($ss->getStatusDescription(), "Boo");
        $this->assertEquals($ss->getTags(), array('bar', 'baz', 'fon'));
        $this->assertEquals($ss->getThumbnailUrl(), "asdf");
        $this->assertEquals($ss->getTitle(), "title");
        $this->assertEquals($ss->getTranscript(), "none");

    }