web/enmi/Zend/Gdata/Gbase.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Zend Framework
       
     5  *
       
     6  * LICENSE
       
     7  *
       
     8  * This source file is subject to the new BSD license that is bundled
       
     9  * with this package in the file LICENSE.txt.
       
    10  * It is also available through the world-wide-web at this URL:
       
    11  * http://framework.zend.com/license/new-bsd
       
    12  * If you did not receive a copy of the license and are unable to
       
    13  * obtain it through the world-wide-web, please send an email
       
    14  * to license@zend.com so we can send you a copy immediately.
       
    15  *
       
    16  * @category   Zend
       
    17  * @package    Zend_Gdata
       
    18  * @subpackage Gbase
       
    19  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    20  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    21  * @version    $Id: Gbase.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    22  */
       
    23 
       
    24 /**
       
    25  * @see Zend_Gdata
       
    26  */
       
    27 require_once 'Zend/Gdata.php';
       
    28 
       
    29 /**
       
    30  * @see Zend_Gdata_Gbase_ItemFeed
       
    31  */
       
    32 require_once 'Zend/Gdata/Gbase/ItemFeed.php';
       
    33 
       
    34 /**
       
    35  * @see Zend_Gdata_Gbase_ItemEntry
       
    36  */
       
    37 require_once 'Zend/Gdata/Gbase/ItemEntry.php';
       
    38 
       
    39 /**
       
    40  * @see Zend_Gdata_Gbase_SnippetEntry
       
    41  */
       
    42 require_once 'Zend/Gdata/Gbase/SnippetEntry.php';
       
    43 
       
    44 /**
       
    45  * @see Zend_Gdata_Gbase_SnippetFeed
       
    46  */
       
    47 require_once 'Zend/Gdata/Gbase/SnippetFeed.php';
       
    48 
       
    49 /**
       
    50  * Service class for interacting with the Google Base data API
       
    51  *
       
    52  * @link http://code.google.com/apis/base
       
    53  *
       
    54  * @category   Zend
       
    55  * @package    Zend_Gdata
       
    56  * @subpackage Gbase
       
    57  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    58  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    59  */
       
    60 class Zend_Gdata_Gbase extends Zend_Gdata
       
    61 {
       
    62 
       
    63     /**
       
    64      * Path to the customer items feeds on the Google Base server.
       
    65      */
       
    66     const GBASE_ITEM_FEED_URI = 'http://www.google.com/base/feeds/items';
       
    67 
       
    68     /**
       
    69      * Path to the snippets feeds on the Google Base server.
       
    70      */
       
    71     const GBASE_SNIPPET_FEED_URI = 'http://www.google.com/base/feeds/snippets';
       
    72 
       
    73     /**
       
    74      * Authentication service name for Google Base
       
    75      */
       
    76     const AUTH_SERVICE_NAME = 'gbase';
       
    77 
       
    78     /**
       
    79      * The default URI for POST methods
       
    80      *
       
    81      * @var string
       
    82      */
       
    83     protected $_defaultPostUri = self::GBASE_ITEM_FEED_URI;
       
    84 
       
    85     /**
       
    86      * Namespaces used for Zend_Gdata_Gbase
       
    87      *
       
    88      * @var array
       
    89      */
       
    90     public static $namespaces = array(
       
    91         array('g', 'http://base.google.com/ns/1.0', 1, 0),
       
    92         array('batch', 'http://schemas.google.com/gdata/batch', 1, 0)
       
    93     );
       
    94 
       
    95     /**
       
    96      * Create Zend_Gdata_Gbase object
       
    97      *
       
    98      * @param Zend_Http_Client $client (optional) The HTTP client to use when
       
    99      *          when communicating with the Google Apps servers.
       
   100      * @param string $applicationId The identity of the app in the form of Company-AppName-Version
       
   101      */
       
   102     public function __construct($client = null, $applicationId = 'MyCompany-MyApp-1.0')
       
   103     {
       
   104         $this->registerPackage('Zend_Gdata_Gbase');
       
   105         $this->registerPackage('Zend_Gdata_Gbase_Extension');
       
   106         parent::__construct($client, $applicationId);
       
   107         $this->_httpClient->setParameterPost('service', self::AUTH_SERVICE_NAME);
       
   108     }
       
   109 
       
   110     /**
       
   111      * Retreive feed object
       
   112      *
       
   113      * @param mixed $location The location for the feed, as a URL or Query
       
   114      * @return Zend_Gdata_Gbase_ItemFeed
       
   115      */
       
   116     public function getGbaseItemFeed($location = null)
       
   117     {
       
   118         if ($location === null) {
       
   119             $uri = self::GBASE_ITEM_FEED_URI;
       
   120         } else if ($location instanceof Zend_Gdata_Query) {
       
   121             $uri = $location->getQueryUrl();
       
   122         } else {
       
   123             $uri = $location;
       
   124         }
       
   125         return parent::getFeed($uri, 'Zend_Gdata_Gbase_ItemFeed');
       
   126     }
       
   127 
       
   128     /**
       
   129      * Retreive entry object
       
   130      *
       
   131      * @param mixed $location The location for the feed, as a URL or Query
       
   132      * @return Zend_Gdata_Gbase_ItemEntry
       
   133      */
       
   134     public function getGbaseItemEntry($location = null)
       
   135     {
       
   136         if ($location === null) {
       
   137             require_once 'Zend/Gdata/App/InvalidArgumentException.php';
       
   138             throw new Zend_Gdata_App_InvalidArgumentException(
       
   139                     'Location must not be null');
       
   140         } else if ($location instanceof Zend_Gdata_Query) {
       
   141             $uri = $location->getQueryUrl();
       
   142         } else {
       
   143             $uri = $location;
       
   144         }
       
   145         return parent::getEntry($uri, 'Zend_Gdata_Gbase_ItemEntry');
       
   146     }
       
   147 
       
   148     /**
       
   149      * Insert an entry
       
   150      *
       
   151      * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to upload
       
   152      * @param boolean $dryRun Flag for the 'dry-run' parameter
       
   153      * @return Zend_Gdata_Gbase_ItemFeed
       
   154      */
       
   155     public function insertGbaseItem($entry, $dryRun = false)
       
   156     {
       
   157         if ($dryRun == false) {
       
   158             $uri = $this->_defaultPostUri;
       
   159         } else {
       
   160             $uri = $this->_defaultPostUri . '?dry-run=true';
       
   161         }
       
   162         $newitem = $this->insertEntry($entry, $uri, 'Zend_Gdata_Gbase_ItemEntry');
       
   163         return $newitem;
       
   164     }
       
   165 
       
   166     /**
       
   167      * Update an entry
       
   168      *
       
   169      * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to be updated
       
   170      * @param boolean $dryRun Flag for the 'dry-run' parameter
       
   171      * @return Zend_Gdata_Gbase_ItemEntry
       
   172      */
       
   173     public function updateGbaseItem($entry, $dryRun = false)
       
   174     {
       
   175         $returnedEntry = $entry->save($dryRun);
       
   176         return $returnedEntry;
       
   177     }
       
   178 
       
   179     /**
       
   180      * Delete an entry
       
   181      *
       
   182      * @param Zend_Gdata_Gbase_ItemEntry $entry The Base entry to remove
       
   183      * @param boolean $dryRun Flag for the 'dry-run' parameter
       
   184      * @return Zend_Gdata_Gbase_ItemFeed
       
   185      */
       
   186     public function deleteGbaseItem($entry, $dryRun = false)
       
   187     {
       
   188         $entry->delete($dryRun);
       
   189         return $this;
       
   190     }
       
   191 
       
   192     /**
       
   193      * Retrieve feed object
       
   194      *
       
   195      * @param mixed $location The location for the feed, as a URL or Query
       
   196      * @return Zend_Gdata_Gbase_SnippetFeed
       
   197      */
       
   198     public function getGbaseSnippetFeed($location = null)
       
   199     {
       
   200         if ($location === null) {
       
   201             $uri = self::GBASE_SNIPPET_FEED_URI;
       
   202         } else if ($location instanceof Zend_Gdata_Query) {
       
   203             $uri = $location->getQueryUrl();
       
   204         } else {
       
   205             $uri = $location;
       
   206         }
       
   207         return parent::getFeed($uri, 'Zend_Gdata_Gbase_SnippetFeed');
       
   208     }
       
   209 }