Example #1
2
 private function getResponse($stack, $base_uri, $uri, $data, $httpMethod)
 {
     $middleware = new Oauth1(['consumer_key' => self::CONSUMER_KEY, 'consumer_secret' => self::CONSUMER_SECRET, 'token_secret' => self::TOKEN_SECRET]);
     //'auth' => ['user_name', 'pass_name'], // when using username & password
     $options = ['auth' => 'oauth', 'debug' => false, 'headers' => ['Accept' => 'application/hal+json', 'Content-Type' => 'application/hal+json'], 'body' => json_encode($data)];
     $stack->push($middleware);
     $client = new Client(['base_uri' => $base_uri, 'handler' => $stack]);
     $response = false;
     switch ($httpMethod) {
         case self::HTTP_GET:
             $response = $client->get($uri, $options);
             break;
         case self::HTTP_POST:
             $response = $client->post($uri, $options);
             break;
         case self::HTTP_PUT:
             $response = $client->put($uri, $options);
             break;
         case self::HTTP_PATCH:
             $response = $client->patch($uri, $options);
             break;
         case self::HTTP_DELETE:
             $response = $client->delete($uri, $options);
             break;
     }
     return $response;
 }
 public function removeObject($object)
 {
     $identifier = $this->getObjectIdentifier($object);
     $class = $this->objectManager->getClassMetadata(get_class($object));
     $url = sprintf('%s/%s', $this->url, $identifier[$class->identifier[0]]);
     $this->client->delete($url);
 }
Example #3
0
 function makeHttpRequest($method, $url, $apiRequest = null, $queryString = null)
 {
     $urlEndPoint = $this->apiConfiguration->getDefaultEndPoint() . '/' . $url;
     $data = ['headers' => ['Authorization' => 'Bearer ' . $this->apiConfiguration->getAccessToken()], 'json' => $apiRequest, 'query' => $queryString];
     try {
         switch ($method) {
             case 'post':
                 $response = $this->guzzle->post($urlEndPoint, $data);
                 break;
             case 'put':
                 $response = $this->guzzle->put($urlEndPoint, $data);
                 break;
             case 'delete':
                 $response = $this->guzzle->delete($urlEndPoint, $data);
                 break;
             case 'get':
                 $response = $this->guzzle->get($urlEndPoint, $data);
                 break;
             default:
                 throw new \Exception('Missing request method!');
         }
         if (in_array(current($response->getHeader('Content-Type')), ['image/png', 'image/jpg'])) {
             $result = $response->getBody()->getContents();
         } else {
             $result = json_decode($response->getBody(), true);
         }
         return $result;
     } catch (ConnectException $c) {
         throw $c;
     } catch (RequestException $e) {
         throw $e;
     }
 }
 /**
  * Retrieve a user by the given credentials.
  *
  * @param array $credentials
  *
  * @return \Magister\Services\Database\Elegant\Model|null
  */
 public function retrieveByCredentials(array $credentials)
 {
     $body = ['body' => $credentials];
     $this->client->delete('sessies/huidige');
     $this->client->post('sessies', $body);
     return $this->retrieveByToken();
 }
Example #5
0
 /** @AfterScenario */
 public function afterScenario()
 {
     $davUrl = $this->baseUrl . '/remote.php/dav/addressbooks/users/admin/MyAddressbook';
     try {
         $this->client->delete($davUrl, ['auth' => ['admin', 'admin']]);
     } catch (\GuzzleHttp\Exception\ClientException $e) {
     }
 }
 public function testDeleteScheduleFailed()
 {
     try {
         self::$client->delete('/');
         $this->fail("Call did not fail");
     } catch (ClientException $e) {
         $this->assertEquals(400, $e->getCode());
     }
 }
 public function testNoCacheOtherMethod()
 {
     $this->client->post('anything');
     $response = $this->client->post('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->put('anything');
     $response = $this->client->put('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->delete('anything');
     $response = $this->client->delete('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->patch('anything');
     $response = $this->client->patch('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
 }
 public function testNoCacheOtherMethod()
 {
     $this->client->post("anything");
     $response = $this->client->post("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->put("anything");
     $response = $this->client->put("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->delete("anything");
     $response = $this->client->delete("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->patch("anything");
     $response = $this->client->patch("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
 }
Example #9
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Retorna status da deleção  200=OK
  */
 public function delete($id)
 {
     $client = new GuzzleHttp\Client();
     $request = $client->delete($this->_apiBase . $this->_className . '/' . $id . '?access_token=' . $this->_apiKey);
     $response = $request->getBody();
     return $response;
 }
Example #10
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     DB::connection()->reconnect();
     $pin = Pin::findOrFail($this->pinId);
     $client = new Client(['base_uri' => 'https://timeline-api.getpebble.com/v1/user/pins/']);
     try {
         $response = $client->delete($pin->pin_id, ['headers' => ['Content-Type' => 'application/json', 'X-User-Token' => $this->timelineToken]]);
         if ($response->getStatusCode() === 200) {
             $pin->status = 'deleted';
             $pin->status_code = $response->getStatusCode();
             $pin->response = $response->getBody();
             $pin->update();
         } else {
             Log::error('Pin Delete Failure - ' . $pin->id . ' due to ' . $response->getStatusCode() . ' - ' . $response->getBody());
         }
     } catch (RequestException $e) {
         $responseCode = $e->getResponse()->getStatusCode();
         $responseBody = $e->getResponse()->getBody();
         Log::error('Pin Delete Failure - API - ' . $pin->id . ' due to ' . $responseCode . ' - ' . $responseBody);
     } catch (TransferException $e) {
         $responseCode = $e->getResponse()->getStatusCode();
         $responseBody = $e->getResponse()->getBody();
         Log::error('Pin Delete Failure - Network - ' . $pin->id . ' due to ' . $responseCode . ' - ' . $responseBody);
     }
 }
 public function delete($resource, $type, $options = [])
 {
     $options['future'] = true;
     return $this->client->delete($resource, $options)->then(function (Response $reponse) {
         return $reponse->json();
     });
 }
Example #12
0
 public function delete($url = null, array $options = [])
 {
     $options = $this->setVerify($options);
     $options['query'] = $this->ApiParams;
     $this->resetParams();
     return parent::delete($url, $options);
 }
Example #13
0
 private function request($method, $path, $params = array())
 {
     $url = $this->api . rtrim($path, '/') . '/';
     $client = new Client(['base_uri' => $url, 'auth' => [$this->auth_id, $this->auth_token], 'http_errors' => false]);
     if (!strcmp($method, "POST")) {
         $body = json_encode($params, JSON_FORCE_OBJECT);
         try {
             $response = $client->post('', array('headers' => ['Content-type' => 'application/json'], 'body' => $body));
         } catch (ClientException $e) {
             echo $e->getRequest();
             echo $e->getResponse();
         }
     } else {
         if (!strcmp($method, "GET")) {
             try {
                 $response = $client->get('', array('query' => $params));
             } catch (ClientException $e) {
                 echo $e->getRequest();
                 echo $e->getResponse();
             }
         } else {
             if (!strcmp($method, "DELETE")) {
                 try {
                     $response = $client->delete('', array('query' => $params));
                 } catch (ClientException $e) {
                     echo $e->getRequest();
                     echo $e->getResponse();
                 }
             }
         }
     }
     $responseData = json_decode($response->getBody(), true);
     $status = $response->getStatusCode();
     return array("status" => $status, "response" => $responseData);
 }
 public static function makeRequest($request, $url, $getRawResponse = false)
 {
     $client = new Client();
     switch ($request->getActionType()) {
         case ActionType::GET:
             if ($getRawResponse) {
                 return $client->get($url);
             } else {
                 $response = GuzzleHelper::getAsset($url);
                 //$client->get($url);
             }
             break;
         case ActionType::DELETE:
             $response = $client->delete($url);
             break;
         case ActionType::PUT:
             $response = $client->put($url);
             break;
         case ActionType::POST:
             $response = $client->post($url);
             break;
         default:
             $response = GuzzleHelper::getAsset($url);
             //$client->get($url);
     }
     return $response;
 }
Example #15
0
 /**
  * Remove an image from docker daemon
  *
  * @param Image   $image   Image to remove
  * @param boolean $force   Force removal of image (default false)
  * @param boolean $noprune Do not remove parent images (default false)
  *
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  *
  * @return ImageManager
  */
 public function remove(Image $image, $force = false, $noprune = false)
 {
     $response = $this->client->delete(['/images/{image}?force={force}&noprune={noprune}', ['image' => $image->__toString(), 'force' => $force, 'noprune' => $noprune, 'wait' => true]]);
     if ($response->getStatusCode() !== "200") {
         throw UnexpectedStatusCodeException::fromResponse($response);
     }
     return $this;
 }
Example #16
0
 /**
  * @param string $uri
  * @param array $data
  * @param array $options
  * @param bool $api
  * @return $this;
  */
 public function delete($uri, array $data = [], array $options = [], $api = true)
 {
     $options = $this->configureOptions($options);
     $uri = $api ? $this->getServiceConfig('api_url') . $uri : $uri;
     $response = $this->client->delete($uri, array_merge($options, ['form_params' => $data]));
     $this->setGuzzleResponse($response);
     return $this;
 }
Example #17
0
 /**
  * Send Delete request to slave
  *
  */
 public function handle()
 {
     $client = new Client();
     try {
         $response = $client->delete($this->slave . ApiUrl::$delete . '/' . $this->filename . '?token=' . getMasterPassword());
     } catch (\Exception $e) {
     }
 }
 /**
  * Remove a container from docker server
  *
  * @param \Docker\Container $container
  * @param boolean           $volumes
  *
  * @throws \Docker\Exception\UnexpectedStatusCodeException
  *
  * @return \Docker\Manager\ContainerManager
  */
 public function remove(Container $container, $volumes = false)
 {
     $response = $this->client->delete(['/containers/{id}?v={volumes}', ['id' => $container->getId(), 'volumes' => (int) $volumes]], ['wait' => true]);
     if ($response->getStatusCode() !== "204") {
         throw UnexpectedStatusCodeException::fromResponse($response);
     }
     return $this;
 }
Example #19
0
 public function delete($url, $data = [])
 {
     $client = new Client(['base_uri' => $this->basic_url, 'timeout' => $this->timeout]);
     $response = $client->delete($this->basic_url . $url, ['timeout' => $this->timeout]);
     $response->addHeader('Content-Type', 'application/json');
     $body = $response->getBody();
     return (string) $body;
 }
Example #20
0
 /**
  * @param array $rules
  *
  * @return RuleList
  * @throws InvalidRuleFormatException
  */
 public function delete(array $rules)
 {
     if (!RuleList::validateRawRuleFormat($rules, false)) {
         throw new InvalidRuleFormatException();
     }
     $client = new Client();
     $client->delete($this->api_url, ['auth' => $this->auth, 'decode_content' => 'gzip', 'Content-Type' => 'application/json', 'body' => json_encode(['rules' => $rules])]);
     return $this->read();
 }
Example #21
0
 /**
  * @param $url
  * @param $version
  * @param array  $data
  * @param string $bodyEncoding
  *
  * @return \GuzzleHttp\Message\FutureResponse|\GuzzleHttp\Message\ResponseInterface|\GuzzleHttp\Ring\Future\FutureInterface|null
  */
 private function delete($url, $version, array $data = [], $bodyEncoding = 'json')
 {
     $requestOptions = $this->getPostRequestOptions($version, $data, $bodyEncoding);
     $response = $this->client->delete($url, $requestOptions);
     if (204 !== $response->getStatusCode()) {
         throw new \LogicException('An error occurred when trying to POST data to MR API');
     }
     return $response;
 }
Example #22
0
 /**
  * @param string $path
  *
  * @return array
  *
  * @throws ImaggaException
  */
 private function _delete($path)
 {
     try {
         $res = $this->_client->delete(self::API . $path, ['auth' => [$this->_apiKey, $this->_apiSecret]]);
     } catch (ClientException $e) {
         throw new ImaggaException($e->getResponse()->json()['message']);
     }
     return $res->json();
 }
Example #23
0
 /**
  * https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record
  * @param  string $dnsCfId
  * @return JSONObject
  */
 private function deleteDnsRecord($dnsCfId)
 {
     try {
         $response = $this->client->delete('zones/' . $this->zoneId . '/dns_records/' . $dnsCfId);
         return $response->json(['object' => true])->result;
     } catch (Exception $e) {
         throw $this->createCloudflareException($e);
     }
 }
 /**
  * @param $ip
  *
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function deleteDroplet($ip)
 {
     $http = new Client();
     try {
         return $http->delete("https://api.digitalocean.com/v2/droplets/{$ip}", ['headers' => ['Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . Config::get('api_token')]]);
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         return;
     }
 }
Example #25
0
 /**
  * @When :user removes the tag :tagName from :fileName shared by :shareUser
  * @param string $user
  * @param string $tagName
  * @param string $fileName
  * @param string $shareUser
  */
 public function removesTheTagFromSharedBy($user, $tagName, $fileName, $shareUser)
 {
     $tagId = $this->findTagIdByName($tagName);
     $fileId = $this->getFileIdForPath($fileName, $shareUser);
     try {
         $this->response = $this->client->delete($this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $fileId . '/' . $tagId, ['auth' => [$user, $this->getPasswordForUser($user)]]);
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         $this->response = $e->getResponse();
     }
 }
Example #26
0
 /**
  * @param $uri
  * @return bool
  */
 private function delete($uri)
 {
     try {
         $this->httpClient->delete($uri);
     } catch (\Exception $e) {
         echo $e->getMessage();
         return false;
     }
     return true;
 }
Example #27
0
 /**
  * @param int $groupId
  * @param int $userId
  */
 public function removeGroupUser($groupId, $userId)
 {
     try {
         $this->guzzle->delete('groups/' . $groupId . '/users/' . $userId);
     } catch (ClientException $e) {
         if ($e->getResponse()->getStatusCode() !== 404) {
             throw $e;
         }
         // Ignore not found when trying to delete the exact resource
     }
 }
Example #28
0
 /**
  * {@inheritdoc}
  */
 public function request($uri, array $parameters = array(), $method = Client::GET, array $headers = array(), array $options = array())
 {
     switch ($method) {
         case Client::GET:
             $response = $this->client->get($uri, ['query' => $parameters, 'headers' => $headers]);
             break;
         case Client::POST:
             $response = $this->client->post($uri, ['form_params' => $parameters, 'headers' => $headers]);
             break;
         case Client::PUT:
             $response = $this->client->put($uri, ['form_params' => $parameters, 'headers' => $headers]);
             break;
         case Client::DELETE:
             $response = $this->client->delete($uri, ['query' => $parameters, 'headers' => $headers]);
             break;
         default:
             throw new InvalidArgumentException("Method {$method} is not supported");
     }
     return new Response($response->getStatusCode(), (string) $response->getBody(), $response->getHeaders());
 }
Example #29
0
 /**
  * @param $endPoint
  * @param array $params
  * @param array $options
  * @return string
  * @throws \Exception
  */
 public function delete($endPoint, array $params = [], array $options = [])
 {
     $response = $this->client->delete($endPoint, $this->prepareData($params, $options));
     switch ($response->getHeader('content-type')) {
         case "application/json":
             return $response->json();
             break;
         default:
             return $response->getBody()->getContents();
     }
 }
 /**
  * @param string $uri
  */
 public function delete($uri)
 {
     $this->lastRequestBody = null;
     try {
         $this->lastResponse = $this->client->delete($uri, ['headers' => $this->headers]);
     } catch (RequestException $e) {
         $this->lastResponse = $e->getResponse();
     } finally {
         $this->lastResponseBody = $this->lastResponse->getBody()->getContents();
     }
 }