From 5064813fec15a92c96a68a6c960bf148b67d226f Mon Sep 17 00:00:00 2001 From: Abdulaziz Al Rashdi Date: Mon, 9 Sep 2024 23:13:18 +0400 Subject: [PATCH 1/3] create link method Add "Create Link" to be able to add a title --- src/Client/BitlyClient.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client/BitlyClient.php b/src/Client/BitlyClient.php index 7dcef9a..5eba0be 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, @@ -99,4 +99,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'); + } } From 871585fc18057ebbb05d3a74e230afd9d53b3858 Mon Sep 17 00:00:00 2001 From: Abdulaziz Al Rashdi Date: Mon, 9 Sep 2024 23:15:57 +0400 Subject: [PATCH 2/3] Update Bitly.php --- src/Facade/Bitly.php | 1 + 1 file changed, 1 insertion(+) 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 { From fc858155ba17092c25d8baa911b66cd6e67f867e Mon Sep 17 00:00:00 2001 From: Abdulaziz Al Rashdi Date: Mon, 9 Sep 2024 23:39:41 +0400 Subject: [PATCH 3/3] Update BitlyClient.php --- src/Client/BitlyClient.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Client/BitlyClient.php b/src/Client/BitlyClient.php index 5eba0be..6b53631 100644 --- a/src/Client/BitlyClient.php +++ b/src/Client/BitlyClient.php @@ -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));