Skip to content

Commit 3616d61

Browse files
committed
Api: allow call methods with full URL (with hostname)
1 parent 8b9cd23 commit 3616d61

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Github/Api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,10 @@ public function request(Http\Request $request)
216216
*/
217217
public function createRequest($method, $urlPath, array $parameters = [], array $headers = [], $content = NULL)
218218
{
219+
if (stripos($urlPath, $this->url) === 0) {
220+
$urlPath = substr($urlPath, strlen($this->url));
221+
}
222+
219223
$urlPath = $this->expandColonParameters($urlPath, $parameters, $this->defaultParameters);
220224

221225
$url = rtrim($this->url, '/') . '/' . ltrim($urlPath, '/');

tests/Github/Api.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ test(function() {
9090
});
9191

9292

93+
# Api called with full URL
94+
test(function() {
95+
$client = new MockIClient;
96+
$api = new Milo\Github\Api($client);
97+
$api->setUrl('url://test');
98+
99+
$request = $api->createRequest('', 'url://test/path', [], [], NULL);
100+
Assert::same('url://test/path', $request->getUrl());
101+
102+
$request = $api->createRequest('', 'url://tested/path', [], [], NULL);
103+
Assert::same('url://test/ed/path', $request->getUrl());
104+
105+
$request = $api->createRequest('', 'uRl://TeSt/path', [], [], NULL);
106+
Assert::same('url://test/path', $request->getUrl());
107+
});
108+
109+
93110
# Paginator
94111
test(function() {
95112
$client = new MockIClient;

0 commit comments

Comments
 (0)