execute() публичный Метод

public execute ( $url, $method = 'GET', $parameters = [], $headers = [] )
Пример #1
0
 public function test_json_patch()
 {
     global $TEST_SERVER_URL;
     $api = new RestClient();
     $result = $api->execute($TEST_SERVER_URL, 'PATCH', "{\"foo\":\"bar\"}", array('X-HTTP-Method-Override' => 'PATCH', 'Content-Type' => 'application/json-patch+json'));
     $response_json = $result->decode_response();
     $this->assertEquals('application/json-patch+json', $response_json->headers->{"Content-Type"});
     $this->assertEquals('PATCH', $response_json->headers->{"X-HTTP-Method-Override"});
     $this->assertEquals('PATCH', $response_json->SERVER->REQUEST_METHOD);
     $this->assertEquals("{\"foo\":\"bar\"}", $response_json->body);
 }
Пример #2
0
 /**
  * Executes the request to the API
  */
 public function execute()
 {
     $this->restClient->setUri($this->vistaMethod);
     $this->restClient->setMethod($this->requestMethod);
     !$this->requestMethod == 'get' || $this->restClient->addParam('showtotal', 1);
     $requestParam = $this->requestMethod == 'get' ? 'pesquisa' : 'cadastro';
     if (!$this->emptyBody) {
         $this->restClient->addParam($requestParam, json_encode($this->params));
     }
     $this->restClient->execute();
     $this->result = $this->restClient->getResponse();
     foreach (array_keys($this->pagination) as $pagParam) {
         if (isset($this->result[$pagParam])) {
             $this->pagination[$pagParam] = intval($this->result[$pagParam]);
             unset($this->result[$pagParam]);
         }
     }
 }
 public function withParameters()
 {
     $fixture = new RestClient();
     $fixture->setConnection(self::$conn->newInstance());
     $this->assertEquals("POST / HTTP/1.1\r\n" . "Connection: close\r\n" . "Host: test\r\n" . "Content-Length: 9\r\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "\r\n" . "key=value", $fixture->execute(create(new RestRequest('/', HttpConstants::POST))->withParameter('key', 'value'))->content());
 }