コード例 #1
0
 /**
  * @param Client $http
  * @param string $endPoint
  * @param array  $query
  * @return array
  */
 private function __requestApi(Client $http, $endPoint, $query = [])
 {
     $url = self::BASE_URL . $endPoint;
     $accessToken = $this->Session->read('Config.access_token');
     $this->header['headers']['Authorization'] = $this->header['headers']['Authorization'] . $accessToken;
     $response = $http->put($url, $query, $this->header);
     return $response->json;
 }
コード例 #2
0
ファイル: ClientTest.php プロジェクト: rashmi/newrepo
 /**
  * Test that string payloads with no content type have a default content-type set.
  *
  * @return void
  */
 public function testPostWithStringDataDefaultsToFormEncoding()
 {
     $response = new Response();
     $data = 'some=value&more=data';
     $headers = ['Connection' => 'close', 'User-Agent' => 'CakePHP', 'Content-Type' => 'application/x-www-form-urlencoded'];
     $mock = $this->getMockBuilder('Cake\\Network\\Http\\Adapter\\Stream')->setMethods(['send'])->getMock();
     $mock->expects($this->any())->method('send')->with($this->logicalAnd($this->attributeEqualTo('_body', $data), $this->attributeEqualTo('_headers', $headers)))->will($this->returnValue([$response]));
     $http = new Client(['host' => 'cakephp.org', 'adapter' => $mock]);
     $http->post('/projects/add', $data);
     $http->put('/projects/add', $data);
     $http->delete('/projects/add', $data);
 }
コード例 #3
0
 /**
  *  Put Request
  *
  *  Execute put request
  *
  * @param string  $url - url of the to send the request.
  * @param Array  $data - Array to data to send if not null.
  * @param string  $type - Type of data specified in request.
  * @param Array  $option -  Array of options to add into request as get variables.
  * @param Array  $header -  Array of header to add into request as http headers.
  * @param boolean  $entityAdmin -  flag to use either _api or _admin in request.
  *
  *
  * @return array $response - The response array.
  */
 public function put($url, $data = NULL, $type = NULL, $option = NULL, $headers = NULL, $entityAdmin = false)
 {
     $entity = self::ENTRY_API;
     if ($entityAdmin) {
         $entity = self::ENTRY_ADMIN;
     }
     $uri = $this->protocol . '://' . $this->user . ':' . $this->pass . '@' . $this->host . ':' . $this->port . '/' . self::ENTRY_DB . '/' . $this->db . '/' . $entity . '/' . $url;
     if ($option != NULL) {
         $uri .= '?';
         foreach ($option as $key => $value) {
             # code...
             $uri .= $key . '=' . $value . '&';
         }
     }
     $http = new Client();
     $response = $http->put($uri, json_encode($data), ['type' => 'json'], ['headers' => $headers]);
     return $response;
 }