Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Client/BitlyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, but why is the requestUrl now a function param?

Copy link
Author

@phpawcom phpawcom Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To use it in the new method create():

 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');
    }


$header = [
'Authorization' => 'Bearer ' . $this->token,
Expand All @@ -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));
Expand Down Expand Up @@ -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');
}
}
1 change: 1 addition & 0 deletions src/Facade/Bitly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down