/** * Execute the queue * * @return mixed */ public function execute() { $response = $this->client->request('POST', "/{$this->database->getName()}/_bulk_docs", ['body' => JSONEncoder::encode($this->data), 'headers' => ['Content-Type' => 'application/json']]); return JSONEncoder::decode((string) $response->getBody()); }
/** * Updates a document * * @param string $id The id from the document * @param array $doc A reference from the document * * @throws Exception */ public function update($id, array &$doc) { $json = JSONEncoder::encode($doc); $response = $this->client->request('PUT', "/{$this->name}/{$id}", ['body' => $json, 'headers' => ['Content-Type' => 'application/json']]); if (201 !== $response->getStatusCode()) { throw new Exception('Unable to save document'); } $value = JSONEncoder::decode((string) $response->getBody()); $doc['_id'] = $value['id']; $doc['_rev'] = $value['rev']; }
public function testEncode() { $this->assertEquals('{"foo":"bar"}', JSONEncoder::encode(['foo' => 'bar'])); }