Skip to content

Commit

Permalink
Merge pull request #187 from line/get_params
Browse files Browse the repository at this point in the history
Fix curl get params handling
  • Loading branch information
Vaduz authored Oct 24, 2018
2 parents c192891 + 6808484 commit f8ab3a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/LINEBot/HTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface HTTPClient
* Sends GET request to LINE Messaging API.
*
* @param string $url Request URL.
* @param array $data Request body.
* @param array $data URL parameters.
* @param array $headers
* @return Response Response of API request.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/LINEBot/HTTPClient/CurlHTTPClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public function __construct($channelToken)
*/
public function get($url, array $data = [], array $headers = [])
{
return $this->sendRequest('GET', $url, $headers, $data);
if ($data) {
$url .= '?' . http_build_query($data);
}
return $this->sendRequest('GET', $url, $headers);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions tests/LINEBot/HTTPClient/CurlHTTPClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,26 @@ protected function setUp()
public function testGet()
{
$curl = new CurlHTTPClient("channel-token");
$res = $curl->get('127.0.0.1:' . CurlHTTPClientTest::$reqMirrorPort . '/foo/bar?buz=qux');
$res = $curl->get('127.0.0.1:' . CurlHTTPClientTest::$reqMirrorPort . '/foo/bar');
$body = $res->getJSONDecodedBody();
$this->assertNotNull($body);
$this->assertEquals('GET', $body['_SERVER']['REQUEST_METHOD']);
$this->assertEquals('/foo/bar', $body['_SERVER']['SCRIPT_NAME']);
$this->assertEquals('', $body['Body']);
$this->assertEquals('buz=qux', $body['_SERVER']['QUERY_STRING']);
$this->assertEquals('Bearer channel-token', $body['_SERVER']['HTTP_AUTHORIZATION']);
$this->assertEquals('LINE-BotSDK-PHP/' . Meta::VERSION, $body['_SERVER']['HTTP_USER_AGENT']);
}

public function testGetWithParams()
{
$curl = new CurlHTTPClient("channel-token");
$res = $curl->get('127.0.0.1:' . CurlHTTPClientTest::$reqMirrorPort . '/foo/bar', ['baz' => 'qwer']);
$body = $res->getJSONDecodedBody();
$this->assertNotNull($body);
$this->assertEquals('GET', $body['_SERVER']['REQUEST_METHOD']);
$this->assertEquals('/foo/bar', $body['_SERVER']['SCRIPT_NAME']);
$this->assertEquals('', $body['Body']);
$this->assertEquals('baz=qwer', $body['_SERVER']['QUERY_STRING']);
$this->assertEquals('Bearer channel-token', $body['_SERVER']['HTTP_AUTHORIZATION']);
$this->assertEquals('LINE-BotSDK-PHP/' . Meta::VERSION, $body['_SERVER']['HTTP_USER_AGENT']);
}
Expand Down

0 comments on commit f8ab3a8

Please sign in to comment.