Example #1
0
 private function postJSON($url, $headers, $payload)
 {
     $client = new Client();
     $request = $client->createRequest('POST', $url, ["Content-Type" => "application/json;charset=UTF-8", "Accept" => "application/json"] + $headers, $payload);
     $response = $request->send();
     $json = $response->getBody(true);
     return json_decode($json);
 }
 /**
  * {@inheritdoc}
  * Also includes the `api_id`, `user`, and `password` in the request if 
  * `session_id` has not been provided in the request.
  */
 public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
 {
     $request = parent::createRequest($method, $uri, $headers, $body, $options);
     if (!$request->getPostField("session_id")) {
         $config = $this->getConfig();
         $request->addPostFields($config->getAll(array('api_id', 'user', 'password')));
     }
     return $request;
 }
 /**
  * {@inheritDoc}
  */
 public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
 {
     $request = parent::createRequest($method, $uri, $headers, $body, $options);
     $config = $this->getConfig();
     // Add curl authentication to the request when username and password is set.
     if ($config->hasKey('username') && $config->hasKey('password')) {
         $authPlugin = new CurlAuthPlugin($config->get('username'), $config->get('password'));
         $this->addSubscriber($authPlugin);
     } elseif ($config->hasKey('client_id') && $config->hasKey('client_secret')) {
         $request->getQuery()->set('client_id', $config->get('client_id'))->set('client_secret', $config->get('client_secret'));
     }
     return $request;
 }
Example #4
0
 /**
  * Function doing an sql injection on GET with Guzzle
  * @param SqlTarget $target
  */
 public function getGosling(TargetInterface $target)
 {
     //defining $url and $params from $target
     //setting success to false by default
     $url = $target->getUrl();
     $repo = $this->_em->getRepository('AppBundle:SqlError');
     $sql_error = $repo->getSqlError();
     $params = $this->changeParamsToHackParams($target, $sql_error);
     $req = $this->_guzzle->createRequest('GET', $url, $params);
     $result = $this->goslingResponse($req, $url);
     $used_sql_error = $sql_error->getValue();
     $success = $result["Success"];
     $this->report($success, "for url " . $url . "and slq injection : " . $used_sql_error);
 }
 /**
  * Dispatch API request
  *
  * @param string $method    HTTP method
  * @param string $path      Target path relative to base_url option value
  * @param object $paramData Request data
  *
  * @return mixed Response object
  */
 public function request($method, $path, $paramData)
 {
     $req = $this->client->createRequest($method, $path, array());
     $query = $req->getQuery();
     foreach ($paramData->queryParams() as $k => $v) {
         if ($v === null) {
             continue;
         }
         $query->add($k, is_bool($v) ? $v ? 'true' : 'false' : $v);
     }
     if ($method !== 'get' && $method !== 'delete') {
         $body = $paramData->requestBody();
         $json = empty($body) ? '{}' : json_encode($body);
         $req->setBody($json, 'application/json');
     }
     try {
         $res = $req->send();
         return $res->json();
     } catch (\Guzzle\Common\Exception\RuntimeException $e) {
         throw ApiConnectionException::inRequest($e);
     }
 }
Example #6
0
 /**
  * Dispatch API request
  *
  * @param string $operation Target action
  * @param object $paramData Request data
  *
  */
 public function request($method, $path, $paramData)
 {
     if ($method == 'get' && count($paramData) > 0) {
         $path = $path . '?';
         foreach ($paramData as $k => $v) {
             $path .= $k . '=' . $v;
         }
         $paramData = array();
     }
     $this->setSignature($path, $paramData);
     $req = $this->client->createRequest($method, $path, array());
     if ($method == 'post' || $method == 'delete') {
         foreach ($paramData as $k => $v) {
             $req->setPostField($k, $v);
         }
     }
     try {
         $res = $req->send();
         return $res->json();
     } catch (\Guzzle\Common\Exception\RuntimeException $e) {
         echo $e->getResponse()->getBody();
     }
 }
Example #7
0
 /**
  * Ensures that the duplicate query string aggregator is used so that
  * query string values are sent over the wire as foo=bar&foo=baz.
  * {@inheritdoc}
  */
 public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
 {
     $request = parent::createRequest($method, $uri, $headers, $body, $options);
     $request->getQuery()->setAggregator($this->aggregator);
     return $request;
 }
 /**
  * Create and return a new RequestInterface configured for the client.
  *
  * Used internally by the library. Do not use directly.
  *
  * @param string                                    $method  HTTP method. Default to GET.
  * @param string|array                              $uri     Resource URI
  * @param array|Collection                          $headers HTTP headers
  * @param string|resource|array|EntityBodyInterface $body    Entity body of request (POST/PUT) or response (GET)
  * @param array                                     $options Array of options to apply to the request
  *
  * @return RequestInterface
  */
 public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null, array $options = array())
 {
     if (is_array($body)) {
         $body['pio_appkey'] = $this->getConfig()->get("appkey");
     } else {
         $body = array('pio_appkey' => $this->getConfig()->get("appkey"));
     }
     // Remove Guzzle internals to prevent them from going to the API
     unset($body[AbstractCommand::HEADERS_OPTION]);
     unset($body[AbstractCommand::ON_COMPLETE]);
     unset($body[AbstractCommand::DISABLE_VALIDATION]);
     unset($body[AbstractCommand::RESPONSE_PROCESSING]);
     unset($body[AbstractCommand::RESPONSE_BODY]);
     unset($body[AbstractCommand::HIDDEN_PARAMS]);
     if ($method == RequestInterface::GET || $method == RequestInterface::DELETE) {
         $request = parent::createRequest($method, $uri, $headers, null, $options);
         $request->getQuery()->replace($body);
     } else {
         $request = parent::createRequest($method, $uri, $headers, $body, $options);
     }
     $request->setPath($request->getPath() . ".json");
     return $request;
 }
Example #9
0
 /**
  * Creates mpi request as innovate api need it.
  *
  * @param string $method
  * @param string $uri
  * @param array $headers
  * @param string|resource|array|EntityBodyInterface $body
  * @return \Guzzle\Http\Message\RequestInterface
  */
 public function createMpiRequest($method = 'GET', $uri = null, $headers = null, $body = null)
 {
     $request = parent::createRequest($method, $uri, $headers, $body);
     if (!$body) {
         $request->createMpiBody($this->getStoreId(), $this->getKey(), $this->getTransaction(), $this->getCard(), $this->getBillingInformation(), $this->getBrowser());
     }
     return $request;
 }
 /**
  * @param string $bodyString
  * @see https://developers.google.com/safe-browsing/developers_guide_v2#HTTPRequestForData
  * @return array
  */
 public function getChunks($bodyString = '')
 {
     $resource = 'downloads';
     $client = new Client($this->getServiceUrl($resource));
     $request = $client->createRequest('POST', null, null, $bodyString);
     $response = $this->sendRequest($request);
     return array('code' => $response->getStatusCode(), 'data' => $response->getBody(true));
 }
 /**
  * @param string $path
  * @return string|bool
  */
 public function checkPublishing($path = '')
 {
     $client = new Client($this->getServiceUrl());
     $body = '<propfind xmlns="DAV:"><prop><public_url xmlns="urn:yandex:disk:meta"/></prop></propfind>';
     $request = $client->createRequest('PROPFIND', $path, array('Content-Length' => strlen($body), 'Depth' => '0'), $body);
     $result = $this->sendRequest($request)->xml()->children('DAV:');
     $propArray = (array) $result->response->propstat->prop->children();
     return empty($propArray['public_url']) ? (bool) false : (string) $propArray['public_url'];
 }
 /**
  *
  * @see \Guzzle\Http\Client::createRequest()
  */
 public function createRequest($method = RequestInterface::POST, $uri = null, $headers = null, $body = null, array $options = array())
 {
     $request = parent::createRequest($method, $uri, $headers, $body, $options);
     return $request;
 }
 /**
  * Update changed delivery parameters
  *
  * @param int $orderId
  * @param Models\Delivery $delivery
  * @return Models\Order
  *
  * Example:
  * PUT /v2/campaigns/10003/order/12345/delivery.json HTTP/1.1
  *
  * @link http://api.yandex.ru/market/partner/doc/dg/reference/put-campaigns-id-orders-id-delivery.xml
  */
 public function updateDelivery($orderId, Models\Delivery $delivery)
 {
     $resource = 'campaigns/' . $this->campaignId . '/orders/' . $orderId . '/delivery.json';
     $data = json_encode($delivery->toArray());
     $client = new Client($this->getServiceUrl($resource));
     $request = $client->createRequest('PUT', null, null, $data);
     $request->setHeader('Content-type', 'application/json');
     $response = $this->sendRequest($request)->json();
     $updateOrderDeliveryResponse = new Models\UpdateOrderDeliveryResponse($response);
     return $updateOrderDeliveryResponse->getOrder();
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function createRequest($method = RequestInterface::GET, $uri = null, $headers = null, $body = null)
 {
     $request = parent::createRequest($method, $uri, $headers, $body);
     $request->setHeader('Content-Type', 'text/xml');
     return $request;
 }
 /**
  * {@inheritdoc}
  *
  * Prepends the {+base_path} expressions to the URI
  */
 public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
 {
     $uri = '{+base_path}/' . ltrim($uri, '/');
     return parent::createRequest($method, $uri, $headers, $body, $options);
 }
Example #16
0
 /**
  * {@inheritdoc}
  *
  * Prepends the {+base_path} expressions to the URI, converts the GET to a
  * POST if the query string is too long.
  */
 public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
 {
     $uri = '{+base_path}/' . ltrim($uri, '/');
     if ('GET' == $method && $this->usePostMethod($uri, $options)) {
         $method = 'POST';
         $body = $options['query'];
         unset($options['query']);
     }
     return parent::createRequest($method, $uri, $headers, $body, $options);
 }
 /**
  * @param  string                                       $method
  * @param  \Kbrw\RiakBundle\Model\KV\Datas              $datas
  * @param  \Guzzle\Http\Curl\CurlMultiInterface         $curlMulti
  * @param  \Guzzle\Service\Client                       $client
  * @return array<\Guzzle\Http\Message\RequestInterface>
  */
 public function prepareRequests($method, $datas, &$curlMulti, $client)
 {
     $requests = array();
     foreach ($datas->getDatas() as $data) {
         $request = $client->createRequest($method, urlencode($data->getKey()), $data->getHeaderBag()->all(), $data->getContent(true));
         $curlMulti->add($request);
         $requests[$data->getKey()] = $request;
     }
     return $requests;
 }
Example #18
0
 /**
  * @param string $endpoint
  * @param string $content
  * @param array $headers
  * @return Response
  */
 public function send($endpoint, $content, array $headers = array())
 {
     $request = $this->client->createRequest(RequestInterface::POST, $endpoint, $headers, $content);
     $response = $request->send();
     return new Response($response->getStatusCode(), $response->getBody(true));
 }