/**
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function getContacts()
 {
     $params = $this->request->urlParams;
     $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
     $lastModified = $addressBook->lastModified();
     $etag = null;
     $response = new JSONResponse();
     if (!is_null($lastModified)) {
         //$response->addHeader('Cache-Control', 'private, must-revalidate');
         $response->setLastModified(\DateTime::createFromFormat('U', $lastModified) ?: null);
         $etag = md5($lastModified);
         $response->setETag($etag);
     }
     if (!is_null($etag) && $this->request->getHeader('If-None-Match') === '"' . $etag . '"') {
         return $response->setStatus(Http::STATUS_NOT_MODIFIED);
     } else {
         switch ($this->request->method) {
             case 'OPTIONS':
                 $options = array('GET', 'HEAD', 'OPTIONS');
                 if ($addressBook->hasPermission(\OCP\PERMISSION_DELETE) && $addressBook->getBackend()->hasAddressBookMethodFor(\OCP\PERMISSION_DELETE)) {
                     $options[] = 'DELETE';
                 }
                 if ($addressBook->hasPermission(\OCP\PERMISSION_UPDATE) && $addressBook->getBackend()->hasAddressBookMethodFor(\OCP\PERMISSION_UPDATE)) {
                     $options[] = 'POST';
                 }
                 $response->addHeader('Allow', implode(',', $options));
                 return $response;
             case 'HEAD':
                 return $response;
             case 'GET':
                 $contacts = array();
                 foreach ($addressBook->getChildren() as $i => $contact) {
                     $result = JSONSerializer::serializeContact($contact);
                     if ($result !== null) {
                         $contacts[] = $result;
                     }
                 }
                 return $response->setData(array('contacts' => $contacts));
         }
     }
 }
 /**
  * @NoAdminRequired
  */
 public function addChild()
 {
     $params = $this->request->urlParams;
     $response = new JSONResponse();
     $addressBook = $this->app->getAddressBook($params['backend'], $params['addressBookId']);
     try {
         $id = $addressBook->addChild();
     } catch (Exception $e) {
         return $response->bailOut($e->getMessage());
     }
     if ($id === false) {
         return $response->bailOut(App::$l10n->t('Error creating contact.'));
     }
     $contact = $addressBook->getChild($id);
     $response->setStatus('201');
     $response->setETag($contact->getETag());
     $response->addHeader('Location', \OCP\Util::linkToRoute('contacts_contact_get', array('backend' => $params['backend'], 'addressBookId' => $params['addressBookId'], 'contactId' => $id)));
     return $response->setParams(JSONSerializer::serializeContact($contact));
 }