Skip to content

Commit

Permalink
Add optional domain and group_guid params (#43)
Browse files Browse the repository at this point in the history
thanks to @bomshteyn
  • Loading branch information
bomshteyn authored Aug 25, 2021
1 parent 943cdae commit e57d08c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions src/Client/BitlyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ public function __construct(ClientInterface $client, $token)

/**
* @param string $url raw URL.
* @param string|null $domain
* @param string|null $group_guid
*
* @return string shorten URL.
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \Shivella\Bitly\Exceptions\AccessDeniedException
* @throws \Shivella\Bitly\Exceptions\InvalidResponseException
*
* @return string shorten URL.
*/
public function getUrl(string $url): string
public function getUrl(string $url, ?string $domain = null, ?string $group_guid = null): string
{
$requestUrl = 'https://api-ssl.bitly.com/v4/shorten';

Expand All @@ -56,8 +58,14 @@ public function getUrl(string $url): string
'Content-Type' => 'application/json',
];

$data = array_filter([
'long_url' => $url,
'domain' => $domain,
'group_guid' => $group_guid,
]);

try {
$request = new Request('POST', $requestUrl, $header, json_encode(['long_url' => $url]));
$request = new Request('POST', $requestUrl, $header, json_encode($data));

$response = $this->client->send($request);
} catch (RequestException $e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Testing/BitlyClientFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
* @param string $url raw URL.
* @return string shorten URL.
*/
public function getUrl(string $url): string
public function getUrl(string $url, ?string $domain = NULL, ?string $group_guid = NULL): string
{
return 'http://bit.ly/'.substr(sha1($url), 0, 6);
}
Expand Down

0 comments on commit e57d08c

Please sign in to comment.