diff --git a/src/Client/BitlyClient.php b/src/Client/BitlyClient.php index 7dcef9a..6b53631 100644 --- a/src/Client/BitlyClient.php +++ b/src/Client/BitlyClient.php @@ -49,9 +49,9 @@ public function __construct(ClientInterface $client, $token) * @throws \Shivella\Bitly\Exceptions\AccessDeniedException * @throws \Shivella\Bitly\Exceptions\InvalidResponseException */ - public function getUrl(string $url, ?string $domain = null, ?string $group_guid = null): string + public function getUrl(string $url, ?string $domain = null, ?string $group_guid = null, ?string $title = null, $requestUrl = 'https://api-ssl.bitly.com/v4/shorten'): string { - $requestUrl = 'https://api-ssl.bitly.com/v4/shorten'; + ## $requestUrl = 'https://api-ssl.bitly.com/v4/shorten'; $header = [ 'Authorization' => 'Bearer ' . $this->token, @@ -63,6 +63,7 @@ public function getUrl(string $url, ?string $domain = null, ?string $group_guid 'domain' => $domain, 'group_guid' => $group_guid, ]); + if($title) $data['title'] = $title; try { $request = new Request('POST', $requestUrl, $header, json_encode($data)); @@ -99,4 +100,7 @@ public function getUrl(string $url, ?string $domain = null, ?string $group_guid throw new InvalidResponseException('The response does not contain a shortened link. Response: '.$content); } + public function create(string $url, ?string $title = null, ?string $domain = null, ?string $group_guid = null){ + return $this->getUrl($url, $domain, $group_guid , $title, 'https://api-ssl.bitly.com/v4/bitlinks'); + } } diff --git a/src/Facade/Bitly.php b/src/Facade/Bitly.php index 9512be3..66a6e2b 100644 --- a/src/Facade/Bitly.php +++ b/src/Facade/Bitly.php @@ -17,6 +17,7 @@ * @see \Shivella\Bitly\Client\BitlyClient * * @method string getUrl(string $url) + * @method string create(string $url, string $title) */ class Bitly extends Facade {