Esempio n. 1
0
 /**
  * @param string $path
  * @param array  $data
  * @param string $method
  *
  * @return Response
  *
  * @throws InvalidArgumentException
  */
 protected function request($path, array $data, $method = 'get')
 {
     $url = $this->buildRequestUrl($path);
     $headers = $this->getHeaders();
     $response = null;
     switch ($method) {
         case 'get':
             $response = $this->httpDriver->get($url, $headers, array('query' => $data));
             break;
         case 'post':
             $body = json_encode($data);
             $response = $this->httpDriver->post($url, $headers, $body);
             break;
         case 'patch':
             $body = json_encode($data);
             $response = $this->httpDriver->patch($url, $headers, $body);
             break;
         default:
             throw new InvalidArgumentException(sprintf('Invalid method: %s', $method));
     }
     return $response;
 }
Esempio n. 2
0
 public function testItShouldGetWordCount()
 {
     $text = 'beep beep, I am a robot.';
     $this->httpDriver->expects($this->once())->method('post')->with($this->unbabel->buildRequestUrl('/wordcount/'), $this->unbabel->getHeaders(), json_encode(array('text' => $text)));
     $this->unbabel->getWordCount($text);
 }