/** * @param $username * @param $password * @return string */ public function getAuthToken($username, $password) { $this->options['getAuthToken'] = ['name' => $username, 'password' => $password]; $this->client->post($this->getServerUrl() . '/_session', 200, $this->getOptions()); $headers = $this->client->getLastHeaders(); $cookie = $headers['Set-Cookie'][0]; list($tokenPart) = explode(';', $cookie); $tokenPart = explode('=', $tokenPart); return $tokenPart[1]; }
/** * Saves or updates the document to the database * @param Document $document */ public function saveDocument(Document $document) { $data = $document->getData(); if (isset($data['_id'])) { $response = $this->client->put($this->getDocumentUrl($data['_id']), 201, $this->server->getOptions(), $document); } else { $response = $this->client->post($this->getDatabaseUrl(), 201, $this->server->getOptions(), $document); $document->setId($response['id']); } $document->setRev($response['rev']); }