Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Tmdb/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setOptions(array $options = [])
/**
* Construct the http client
*
* In case you are implementing your own adapter, the base url will be passed on through the $parameters array
* In case you are implementing your own adapter, the base url will be passed on through the options bag
* at every call in the respective get / post methods etc. of the adapter.
*
* @return void
Expand Down Expand Up @@ -334,7 +334,7 @@ protected function postResolve(array $options = [])

if (!$this->options['adapter']) {
$this->options['adapter'] = new GuzzleAdapter(
new \GuzzleHttp\Client(['base_url' => $this->options['base_url']])
new \GuzzleHttp\Client()
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function getConfiguration(Request $request)
$this->request = $request;

return [
'base_uri' => $request->getOptions()->get('base_url'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess base_uri here is a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually the correct name (I remember re-reading the docs because it looked unusual to me too ;) )

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, just ran into the same confusion ;) Thanks for the follow-up. I'd like to check if this could be covered with test prior merging.

'headers' => $request->getHeaders()->all(),
'query' => $request->getParameters()->all()
];
Expand Down
9 changes: 3 additions & 6 deletions lib/Tmdb/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class HttpClient
* The base url to built requests on top of
*
* @var null
*
* @deprecated since 2.1.10, to be removed in 3.0. Use `base_url` of the request options instead.
*/
protected $base_url = null;

Expand Down Expand Up @@ -97,11 +99,6 @@ public function __construct(
$this->processOptions();
}

private function constructSecureUrl($path)
{
return 'https://' . $this->base_url . $path;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -229,7 +226,7 @@ public function setBaseUrl($url)
private function send($path, $method, array $parameters = [], array $headers = [], $body = null)
{
$request = $this->createRequest(
$this->constructSecureUrl($path),
$path,
$method,
$parameters,
$headers,
Expand Down
23 changes: 23 additions & 0 deletions test/Tmdb/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ public function assertInstances()
);
}

/**
* @test
*/
public function shouldRespectSecureClientOption()
{
$token = new ApiToken(self::API_TOKEN);

$client = new \Tmdb\Client($token);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'https://'));

$client = new \Tmdb\Client($token, ['secure' => true]);
$options = $client->getOptions();
$this->assertTrue(true === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'https://'));

$client = new \Tmdb\Client($token, ['secure' => false]);
$options = $client->getOptions();
$this->assertTrue(false === $options['secure']);
$this->assertTrue(false !== strpos($options['base_url'], 'http://'));
}

public function testShouldSwitchHttpScheme()
{
$token = new ApiToken(self::API_TOKEN);
Expand Down
13 changes: 10 additions & 3 deletions test/Tmdb/Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ protected function getMockedHttpClient(array $methods = [])
/**
* Get the expected request that will deliver a response
*
* @param $path
* @param string $url
* @param array $parameters
* @param string $method
* @param array $headers
* @param null $body
* @return Request
*/
protected function getRequest($path, $parameters = [], $method = 'GET', $headers = [], $body = null)
protected function getRequest($url, $parameters = [], $method = 'GET', $headers = [], $body = null)
{
if (
$method == 'POST' ||
Expand All @@ -161,6 +161,13 @@ protected function getRequest($path, $parameters = [], $method = 'GET', $headers
$headers['Accept'] = 'application/json';
$headers['User-Agent'] = sprintf('wtfzdotnet/php-tmdb-api (v%s)', Client::VERSION);

$baseUrl = 'https://api.themoviedb.org/3/';
if (strpos($url, $baseUrl) === 0) {
$path = substr($url, strlen($baseUrl));
} else {
$path = $url;
}

$request = new Request(
$path,
$method,
Expand All @@ -186,7 +193,7 @@ protected function getRequest($path, $parameters = [], $method = 'GET', $headers
],
'adapter' => $this->createMock('Tmdb\HttpClient\Adapter\AdapterInterface'),
'host' => 'api.themoviedb.org/3/',
'base_url' => 'https://api.themoviedb.org/3/',
'base_url' => $baseUrl,
'session_token' => null,
'event_dispatcher' => $this->eventDispatcher
]));
Expand Down