Exemplo n.º 1
0
 /**
  * @param int           $facilityId
  * @param int           $doctorId
  * @param DoctorService $doctorService
  *
  * @return DoctorService
  */
 public function patchDoctorService($facilityId, $doctorId, $doctorService)
 {
     $request = $this->client->patch(['facilities/{facilityId}/doctors/{doctorId}/services/{doctorServiceId}', ['facilityId' => $facilityId, 'doctorId' => $doctorId, 'doctorServiceId' => $doctorService->getId()]], [], $this->serializer->serialize($doctorService, 'json', SerializationContext::create()->setGroups(['patch'])));
     /** @var DoctorService $newDoctorService */
     $newDoctorService = $this->authorizedRequest($request, DoctorService::class, DeserializationContext::create()->setGroups(['get']));
     return $newDoctorService;
 }
 /**
  * Edit an user fields.
  *
  * @param int $id
  * @param array $fields
  *
  * @return mixed
  */
 public function patchUser($id, array $fields)
 {
     $request = $this->client->patch($this->customer['url'] . '/api/users/' . $id);
     $request->setAuth($this->customer['username'], $this->customer['password']);
     $request->setBody(json_encode($fields));
     $response = $request->send();
     return json_decode($response->getBody(true));
 }
Exemplo n.º 3
0
 function patch($endpoint, $data = array())
 {
     try {
         $client = new Client();
         $bearerAuth = new BearerAuth($this->token);
         $client->addSubscriber($bearerAuth);
         $request = $client->patch($this->base_url . $endpoint, array(), json_encode($data, JSON_FORCE_OBJECT));
         $request->addHeader('Content-Type', 'application/json');
         $response = $request->send();
         return $response->json();
     } catch (BearerErrorResponseException $e) {
         return $e->getMessage();
     } catch (BadResponseException $e) {
         return $e->getMessage();
     }
 }
Exemplo n.º 4
0
 /**
  * Patch (partial update) an object at a set location ($path)
  * @param string $path the path to post this object to.
  * @param object $object the object to be posted to given path
  * @param array $headers an array of headers to send with the request
  * @return \DrestClient\Response $response Response object with a populated representation instance
  * @throws ErrorException upon the return of any error document from the server
  */
 public function patch($path, &$object, array $headers = array())
 {
     $representation = $this->getRepresentationInstance();
     $representation->update($object);
     $request = $this->transport->patch($path, $headers, $representation->__toString());
     foreach ($this->getVarsFromPath($path) as $key => $value) {
         $request->setPostField($key, $value);
     }
     $request->setHeader('Content-Type', $representation->getContentType());
     try {
         $response = $this->transport->send($request);
     } catch (BadResponseException $exception) {
         throw $this->handleErrorResponse($exception);
     }
     return new Response($representation, $response);
 }
Exemplo n.º 5
0
             $app['session']->set('error', $e->getResponse()->getStatusCode() . ": " . $e->getResponse()->getReasonPhrase());
             return $app->redirect('../../ui/error');
         }
     }
     // return the response (the json or php file)
     return $response;
 } elseif ($app['session']->get('method') == 'get') {
     $title = $title . "for getting";
     $app['session']->set('userget', $formdata['Username']);
     $app['session']->set('pswdget', $formdata['Password']);
 } elseif ($app['session']->get('method') == 'patch') {
     $title = $title . "for editing";
     $app['session']->set('userpatch', $formdata['Username']);
     $app['session']->set('pswdpatch', $formdata['Password']);
     try {
         $request = $client->patch($app['session']->get('path'), null, $app['session']->get('body'))->setAuth($formdata['Username'], $formdata['Password']);
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         if ($e->getResponse()->getStatusCode() == 401) {
             return $app->redirect($hostname . 'ui/authentication');
         } else {
             $app['session']->set('error', $e->getResponse()->getStatusCode() . ": " . $e->getResponse()->getReasonPhrase());
             return $app->redirect('../../ui/error');
         }
     }
 } elseif ($app['session']->get('method') == 'put') {
     $title = $title . "for putting";
     $app['session']->set('userput', $formdata['Username']);
     $app['session']->set('pswdput', $formdata['Password']);
     try {
         $request = $client->put($app['session']->get('path'), null, $app['session']->get('body'))->setAuth($formdata['Username'], $formdata['Password']);
Exemplo n.º 6
0
 public function testClientHasHelperMethodsForCreatingRequests()
 {
     $url = $this->getServer()->getUrl();
     $client = new Client($url . 'base');
     $this->assertEquals('GET', $client->get()->getMethod());
     $this->assertEquals('PUT', $client->put()->getMethod());
     $this->assertEquals('POST', $client->post()->getMethod());
     $this->assertEquals('HEAD', $client->head()->getMethod());
     $this->assertEquals('DELETE', $client->delete()->getMethod());
     $this->assertEquals('OPTIONS', $client->options()->getMethod());
     $this->assertEquals('PATCH', $client->patch()->getMethod());
     $this->assertEquals($url . 'base/abc', $client->get('abc')->getUrl());
     $this->assertEquals($url . 'zxy', $client->put('/zxy')->getUrl());
     $this->assertEquals($url . 'zxy?a=b', $client->post('/zxy?a=b')->getUrl());
     $this->assertEquals($url . 'base?a=b', $client->head('?a=b')->getUrl());
     $this->assertEquals($url . 'base?a=b', $client->delete('/base?a=b')->getUrl());
 }
Exemplo n.º 7
0
 // getting the data from the form
 $formdata = $form->getData();
 // making array for the body of the put request
 $body = array();
 foreach ($parameterstobechanged as $key => $value) {
     $body[$key] = $formdata[$key];
 }
 // initializing a new client
 $client2 = new Client();
 try {
     $path = $hostname . "tdtadmin/resources/" . $app['session']->get('pathtoresource');
     // the put request
     // checking if once in a session time a username and password is given to authorise for patching
     // if not, try without authentication
     if ($app['session']->get('userpatch') == null || $app['session']->get('pswdpatch') == null) {
         $request = $client2->patch($path, null, $body);
     } else {
         $request = $client2->patch($path, null, $body)->setAuth($app['session']->get('userpatch'), $app['session']->get('pswdpatch'));
     }
     $response = $request->send();
 } catch (ClientErrorResponseException $e) {
     // if tried with authentication and it failed
     // or when tried without authentication and authentication is needed
     if ($e->getResponse()->getStatusCode() == 401) {
         // necessary information is stored in the session object, needed to redo the request after authentication
         $app['session']->set('method', 'patch');
         $app['session']->set('path', $path);
         $app['session']->set('body', $body);
         $app['session']->set('redirect', $hostname . 'ui/package');
         $app['session']->set('referer', $hostname . 'ui/resource/edit');
         return $app->redirect('../../ui/authentication');
Exemplo n.º 8
0
 /**
  * @param Client $client
  * @param string $method
  * @param string $url
  * @param array $parameters
  * @param array $options
  * @param string|null $payload
  * @return \Guzzle\Http\Message\Response
  * @throws \Exception
  */
 protected function executeRequest(Client $client, $method, $url, array $parameters, array $options, $payload = null)
 {
     switch ($method) {
         case 'get':
             $request = $client->get($url, $parameters, $options);
             break;
         case 'post':
         case 'upload':
             $request = $client->post($url, $parameters, $payload, $options);
             break;
         case 'put':
             $request = $client->put($url, $parameters, $payload, $options);
             break;
         case 'patch':
             $request = $client->patch($url, $parameters, $payload, $options);
             break;
         case 'delete':
             $request = $client->delete($url, $parameters, $payload, $options);
             break;
         default:
             throw new \Exception('Invalid method');
             break;
     }
     return $request->send();
 }