Exemple #1
0
 /**
  * Tests Sopha_Http_Request::post()
  */
 public function testPost()
 {
     // TODO Auto-generated Sopha_Http_RequestTest::testPost()
     $this->markTestIncomplete("post test not implemented");
     Sopha_Http_Request::post();
 }
Exemple #2
0
 /**
  * Create a new document and save it in DB. Will return the new Document object
  *
  * @param  mixed  $data
  * @param  string $doc
  * @return Sopha_Document
  */
 public function create($data, $doc = null)
 {
     require_once 'Sopha/Json.php';
     $url = $this->_db_uri;
     if ($doc) {
         $doc = self::encodeDocPath($doc);
         $response = Sopha_Http_Request::put($url . urlencode($doc), Sopha_Json::encode($data));
     } else {
         $response = Sopha_Http_Request::post($url, Sopha_Json::encode($data));
     }
     switch ($response->getStatus()) {
         case 201:
             $responseData = $response->getDocument();
             $url .= urlencode($responseData['id']);
             $data['_id'] = $responseData['id'];
             $data['_rev'] = $responseData['rev'];
             require_once 'Sopha/Document.php';
             return new Sopha_Document($data, $url, $this);
             break;
         default:
             require_once 'Sopha/Db/Exception.php';
             throw new Sopha_Db_Exception("Unexpected response from server: " . "{$response->getStatus()} {$response->getMessage()}", $response->getStatus());
             break;
     }
 }
Exemple #3
0
 /**
  * Bulk-update a set of documents
  * 
  * If documents contain the _id and _rev parameters, they will be updated. 
  * If these parameters are ommitted, new documents will be created. 
  * An array of document IDs and revision numbers will be returned. 
  * 
  * @param  array $docs an array of documents to update / insert
  * @return array
  */
 public function bulkUpdate(array $docs)
 {
     $url = $this->_db_uri . '/_bulk_docs';
     $response = Sopha_Http_Request::post($url, Sopha_Json::encode(array('docs' => $docs)));
     switch ($response->getStatus()) {
         case 200:
         case 201:
             return $response->getDocument();
             break;
         default:
             require_once 'Sopha/Db/Exception.php';
             throw new Sopha_Db_Exception("Unexpected response from server: " . "{$response->getStatus()} {$response->getMessage()}", $response->getStatus());
             break;
     }
 }