Example #1
0
 public function isAuthenticated()
 {
     $client = parent::getHttpClient();
     if ($client->getClientLoginToken() || $client->getAuthSubToken()) {
         return true;
     }
     return false;
 }
Example #2
0
 public function save($dryRun = false, $uri = null, $className = null, $extraHeaders = array())
 {
     if ($dryRun == true) {
         $editLink = $this->getEditLink();
         if ($uri == null && $editLink !== null) {
             $uri = $editLink->getHref() . '?dry-run=true';
         }
         if ($uri === null) {
             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
             throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
         }
         $service = new Zend_Gdata_App($this->getHttpClient());
         return $service->updateEntry($this, $uri, $className, $extraHeaders);
     } else {
         parent::save($uri, $className, $extraHeaders);
     }
 }
 public function testNormalAuthorShouldHaveNoExtensionElements()
 {
     $this->author->name = new Zend_Gdata_App_Extension_Name('Jeff Scudder');
     $this->assertEquals($this->author->name->text, 'Jeff Scudder');
     $this->assertEquals(count($this->author->extensionElements), 0);
     $newAuthor = new Zend_Gdata_App_Extension_Author();
     $newAuthor->transferFromXML($this->author->saveXML());
     $this->assertEquals(count($newAuthor->extensionElements), 0);
     $newAuthor->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
     $this->assertEquals(count($newAuthor->extensionElements), 1);
     $this->assertEquals($newAuthor->name->text, 'Jeff Scudder');
     /* try constructing using magic factory */
     $app = new Zend_Gdata_App();
     $newAuthor2 = $app->newAuthor();
     $newAuthor2->transferFromXML($newAuthor->saveXML());
     $this->assertEquals(count($newAuthor2->extensionElements), 1);
     $this->assertEquals($newAuthor2->name->text, 'Jeff Scudder');
 }
Example #4
0
 public function testNormalCategoryShouldHaveNoExtensionElements()
 {
     $this->category->scheme = 'http://schemas.google.com/g/2005#kind';
     $this->assertEquals($this->category->scheme, 'http://schemas.google.com/g/2005#kind');
     $this->assertEquals(count($this->category->extensionElements), 0);
     $newCategory = new Zend_Gdata_App_Extension_Category();
     $newCategory->transferFromXML($this->category->saveXML());
     $this->assertEquals(0, count($newCategory->extensionElements));
     $newCategory->extensionElements = array(new Zend_Gdata_App_Extension_Element('foo', 'atom', null, 'bar'));
     $this->assertEquals(count($newCategory->extensionElements), 1);
     $this->assertEquals($newCategory->scheme, 'http://schemas.google.com/g/2005#kind');
     /* try constructing using magic factory */
     $app = new Zend_Gdata_App();
     $newCategory2 = $app->newCategory();
     $newCategory2->transferFromXML($newCategory->saveXML());
     $this->assertEquals(count($newCategory2->extensionElements), 1);
     $this->assertEquals($newCategory2->scheme, 'http://schemas.google.com/g/2005#kind');
 }
Example #5
0
 /**
  * Imports a feed located at $uri.
  *
  * @param  string $uri
  * @param  Zend_Http_Client $client The client used for communication
  * @param  string $className The class which is used as the return type
  * @throws Zend_Gdata_App_Exception
  * @return string|Zend_Gdata_App_Feed Returns string only if the object
  *                                    mapping has been disabled explicitly
  *                                    by passing false to the
  *                                    useObjectMapping() function.
  */
 public static function import($uri, $client = null, $className = 'Zend_Gdata_App_Feed')
 {
     $app = new Zend_Gdata_App($client);
     $requestData = $app->prepareRequest('GET', $uri);
     $response = $app->performHttpRequest($requestData['method'], $requestData['url']);
     $feedContent = $response->getBody();
     if (!$this->_useObjectMapping) {
         return $feedContent;
     }
     $feed = self::importString($feedContent, $className);
     if ($client != null) {
         $feed->setHttpClient($client);
     }
     return $feed;
 }
Example #6
0
   /**
     * Retrieve the previous set of results from this feed.
     *
     * @throws Zend_Gdata_App_Exception
     * @return mixed|null Returns the previous set of results as a feed of
     *          the same class as this feed, or null if no results exist.
     */
    public function getPreviousFeed()
    {
        $previousLink = $this->getPreviousLink();
        if (!$previousLink) {
            require_once 'Zend/Gdata/App/HttpException.php';
            throw new Zend_Gdata_App_Exception('No link to previous set ' .
            'of results found.');
        }
        $previousLinkHref = $previousLink->getHref();
        $service = new Zend_Gdata_App($this->getHttpClient());

        return $service->getFeed($previousLinkHref, get_class($this));
    }
Example #7
0
 /**
  * Deletes this entry to the server using the referenced
  * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
  * entry's link collection.
  *
  * @return void
  * @throws Zend_Gdata_App_Exception
  */
 public function delete()
 {
     $service = new Zend_Gdata_App($this->getHttpClient());
     $service->delete($this);
 }
Example #8
0
 /**
  * Retreive entry object
  *
  * @param mixed $location The location as string or Zend_Gdata_Query
  * @return Zend_Gdata_Feed
  */
 public function getEntry($location, $className = 'Zend_Gdata_Entry')
 {
     if (is_string($location)) {
         $uri = $location;
     } elseif ($location instanceof Zend_Gdata_Query) {
         $uri = $location->getQueryUrl();
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the location as either a string URI ' . 'or a child of Zend_Gdata_Query');
     }
     return parent::getEntry($uri, $className);
 }
 /**
  * @group ZF-10243
  */
 public function testStaticImportWithoutUsingObjectMapping()
 {
     $this->adapter->setResponse($this->httpEntrySample);
     $feed = Zend_Gdata_App::import('http://www.example.com', $this->client, 'Zend_Gdata_App_Feed', false);
     $this->assertContains('<id>12345678901234567890</id>', $feed);
 }
Example #10
0
 /**
  * DELETE entry with client object
  *
  * @param mixed $data The Zend_Gdata_App_Entry or URL to delete
  * @return void
  * @throws Zend_Gdata_App_Exception
  * @throws Zend_Gdata_App_HttpException
  * @throws Zend_Gdata_App_InvalidArgumentException
  */
 public function delete($data, $remainingRedirects = null)
 {
     require_once 'Zend/Http/Client/Exception.php';
     if ($remainingRedirects === null) {
         $remainingRedirects = self::getMaxRedirects();
     }
     if (is_string($data)) {
         $uri = $data;
     } elseif ($data instanceof Zend_Gdata_App_Entry) {
         $editLink = $data->getEditLink();
         if ($editLink != null) {
             $uri = $editLink->getHref();
         }
     } else {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify the data to post as either a string or a child of Zend_Gdata_App_Entry');
     }
     if ($uri === null) {
         require_once 'Zend/Gdata/App/InvalidArgumentException.php';
         throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
     }
     $this->_httpClient->resetParameters();
     $this->_httpClient->setHeaders('x-http-method-override', null);
     $this->_httpClient->setUri($uri);
     $this->_httpClient->setConfig(array('maxredirects' => 0));
     try {
         if (Zend_Gdata_App::getHttpMethodOverride()) {
             $this->_httpClient->setHeaders(array('X-HTTP-Method-Override: DELETE'));
             $this->_httpClient->setRawData('');
             $response = $this->_httpClient->request('POST');
         } else {
             $response = $this->_httpClient->request('DELETE');
         }
     } catch (Zend_Http_Client_Exception $e) {
         require_once 'Zend/Gdata/App/HttpException.php';
         throw new Zend_Gdata_App_HttpException($e->getMessage(), $e);
     }
     if ($response->isRedirect()) {
         if ($remainingRedirects > 0) {
             $newUri = $response->getHeader('Location');
             $response = $this->delete($newUri, $remainingRedirects - 1);
         } else {
             require_once 'Zend/Gdata/App/HttpException.php';
             throw new Zend_Gdata_App_HttpException('No more redirects allowed', null, $response);
         }
     }
     if (!$response->isSuccessful()) {
         require_once 'Zend/Gdata/App/HttpException.php';
         $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
         $exception->setResponse($response);
         throw $exception;
     }
     return $response;
 }
Example #11
0
 public function testSetAndGetHttpMethodOverride()
 {
     Zend_Gdata_App::setHttpMethodOverride(true);
     $this->assertEquals(true, Zend_Gdata_App::getHttpMethodOverride());
 }
Example #12
0
 /**
  * Toggle using POST instead of PUT and DELETE HTTP methods
  *
  * Some feed implementations do not accept PUT and DELETE HTTP
  * methods, or they can't be used because of proxies or other
  * measures. This allows turning on using POST where PUT and
  * DELETE would normally be used; in addition, an
  * X-Method-Override header will be sent with a value of PUT or
  * DELETE as appropriate.
  *
  * @param  boolean $override Whether to override PUT and DELETE with POST.
  * @return void
  */
 public static function setHttpMethodOverride($override = true)
 {
     self::$_httpMethodOverride = $override;
 }
Example #13
0
 /**
  * Performs a HTTP request using the specified method.
  * 
  * Overrides the definition in the parent (Zend_Gdata_App)
  * and uses the Zend_Gdata_HttpClient functionality
  * to filter the HTTP requests and responses.
  *  
  * @param string $method The HTTP method for the request -
  *                       'GET', 'POST', 'PUT', 'DELETE'
  * @param string $url The URL to which this request is being performed,
  *                    or null if found in $data
  * @param array $headers An associative array of HTTP headers
  *                       for this request
  * @param string $body The body of the HTTP request
  * @param string $contentType The value for the content type of the
  *                            request body
  * @param int $remainingRedirects Number of redirects to follow
  *                                if requests results in one
  * @return Zend_Http_Response The response object
  */
 public function performHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null, $remainingRedirects = null)
 {
     if ($this->_httpClient instanceof Zend_Gdata_HttpClient) {
         $filterResult = $this->_httpClient->filterHttpRequest($method, $url, $headers, $body, $contentType);
         $method = $filterResult['method'];
         $url = $filterResult['url'];
         $body = $filterResult['body'];
         $headers = $filterResult['headers'];
         $contentType = $filterResult['contentType'];
         return $this->_httpClient->filterHttpResponse(parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects));
     } else {
         return parent::performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
     }
 }
Example #14
0
 /**
  * Deletes this entry to the server using the referenced 
  * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this 
  * entry's link collection.  
  *
  * @return boolean The success of the delete operation
  * @throws Zend_Gdata_App_Exception
  */
 public function delete()
 {
     if ($this->id) {
         // If id is set, look for link rel="edit" in the
         // entry object and DELETE.
         $editLink = $this->getLink('edit');
         $editUri = $editLink->href;
         if (!$editUri) {
             throw new Zend_Gdata_App_Exception('Cannot delete entry; no link rel="edit" is present.');
         }
         $client = $this->getHttpClient();
         if (is_null($client)) {
             $client = Zend_Gdata_App::getStaticHttpClient();
         }
         $client->resetParameters();
         $client->setUri($editUri);
         $client->setHeaders('Content-Type', null);
         $client->setRawData('');
         if (Zend_Gdata_App::getHttpMethodOverride()) {
             $client->setHeaders('X-HTTP-Method-Override', 'DELETE');
             $response = $client->request('DELETE');
         } else {
             $response = $client->request('DELETE');
         }
         if ($response->getStatus() !== 200) {
             require_once 'Zend/Gdata/App/HttpException.php';
             $exception = new Zend_Gdata_App_HttpException('Expected response code 200, got ' . $response->getStatus());
             $exception->setResponse($response);
             throw $exception;
         }
         return true;
     } else {
         throw new Zend_Gdata_App_Exception('Cannot edit entry; no id is present');
     }
 }