Skip to content

Commit

Permalink
fix request headers close #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Erico Pedroso committed Jan 19, 2016
1 parent e54f5da commit f199419
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
34 changes: 9 additions & 25 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,32 @@
use GuzzleHttp\Client as Guzzle;
use Vindi\Vindi;

class Client
class Client extends Guzzle
{
/**
* @var \GuzzleHttp\Client
*/
private $client;

/**
* Client constructor.
*/
public function __construct()
public function __construct(array $config = [])
{
$vindi = new Vindi;

$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '';

$this->client = new Guzzle([
$config = array_merge([
'base_uri' => Vindi::$apiBase,
'auth' => [$vindi->getApiKey(), '', 'BASIC'],
'request.options' => [
'headers' => [
'Content-Type' => 'application/json',
'User-Agent' => trim('Vindi-PhpSdk/' . Vindi::$sdkVersion . "; {$host}"),
],
'headers' => [
'Content-Type' => 'application/json',
'User-Agent' => trim('Vindi-PHP/' . Vindi::$sdkVersion . "; {$host}"),
],
'verify' => $vindi->getCertPath(),
'timeout' => 60,
'curl.options' => [
'CURLOPT_SSLVERSION' => 'CURL_SSLVERSION_TLSv1_2',
]
]);
}
], $config);

/**
* @param string $method The HTTP method being used
* @param string $uri The URI being requested, including domain and protocol
* @param array $options
*
* @return \GuzzleHttp\Promise\PromiseInterface
*/
public function request($method, $uri = null, array $options = [])
{
return $this->client->request($method, $uri, $options);

parent::__construct($config);
}
}
12 changes: 11 additions & 1 deletion tests/Http/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ public function it_should_call_request()

$this->assertNotNull($response);
}
}

/** @test */
public function it_should_have_correct_headers()
{
$version = \Vindi\Vindi::$sdkVersion;
$headers = $this->client->getConfig()['headers'];

$this->assertEquals($headers['Content-Type'], 'application/json');
$this->assertEquals(preg_split('/\;/', $headers['User-Agent'])[0], "Vindi-PHP/{$version}");
}
}

0 comments on commit f199419

Please sign in to comment.