public function testRequest()
 {
     $builder = new RequestBuilder('http://localhost/api/');
     $this->assertStringStartsWith('HitSDK', $builder->getUserAgent());
     $requestOne = $builder->build('DELETE', 'and_point_1');
     $this->assertTrue(is_array($requestOne));
     $this->assertArrayHasKey('http_method', $requestOne);
     $this->assertEquals('DELETE', $requestOne['http_method']);
     $this->assertArrayHasKey('scheme', $requestOne);
     $this->assertEquals('http', $requestOne['scheme']);
     $this->assertArrayHasKey('uri', $requestOne);
     $this->assertEquals('/api/and_point_1', $requestOne['uri']);
     $this->assertArrayHasKey('headers', $requestOne);
     $this->assertTrue(is_array($requestOne['headers']));
     $this->assertArrayHasKey('Host', $requestOne['headers']);
     $this->assertEquals(['localhost'], $requestOne['headers']['Host']);
     $this->assertArrayHasKey('User-Agent', $requestOne['headers']);
     $this->assertTrue(is_array($requestOne['headers']['User-Agent']));
     $this->assertTrue((bool) count($requestOne['headers']['User-Agent']));
     $this->assertStringStartsWith('HitSDK', $requestOne['headers']['User-Agent'][0]);
     $requestTwo = $builder->build('PUT', 'and_point_2', ['a' => 'b']);
     $this->assertTrue(is_array($requestTwo));
     $this->assertArrayHasKey('query_string', $requestTwo);
     $this->assertEquals('a=b', $requestTwo['query_string']);
 }
Exemple #2
0
 /**
  * @param string     $method
  * @param string     $uri
  * @param null|array $params
  * @param mixed      $body
  * @param array      $options
  * @return mixed
  */
 public function performRequest($method, $uri, $params = null, $body = null, array $options = [])
 {
     // Basic request
     $request = $this->requestBuilder->build($method, $uri, $params);
     // Build body
     if (isset($body)) {
         $request['body'] = json_encode($body);
     }
     // To be able to change some options
     $request = array_merge_recursive($request, $options);
     // Run
     $handler = $this->handler;
     $result = $handler($request);
     if ($result instanceof FutureArrayInterface) {
         do {
             $result = $result->wait();
         } while ($result instanceof FutureArrayInterface);
     }
     return $result;
 }