Skip to content

Commit

Permalink
Allow for Bitly generic access tokens to be used.
Browse files Browse the repository at this point in the history
  • Loading branch information
William committed May 6, 2019
1 parent 15301d1 commit 8d9c6bc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions config/urlshortener.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
'apikey' => env('URL_SHORTENER_GOOGLE_API_KEY', ''),
],
'bitly' => [
'username' => env('URL_SHORTENER_BITLY_USERNAME', ''),
'password' => env('URL_SHORTENER_BITLY_PASSWORD', ''),
'username' => env('URL_SHORTENER_BITLY_USERNAME', ''), // Or generic access token
'password' => env('URL_SHORTENER_BITLY_PASSWORD', ''), // Leave blank if generic access token is to be used
],
'connect_timeout' => 2,
'timeout' => 2,
Expand Down
7 changes: 4 additions & 3 deletions src/Drivers/Bitly.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@

use Mremi\UrlShortener\Provider\Bitly\BitlyProvider;
use Mremi\UrlShortener\Provider\Bitly\OAuthClient;
use Mremi\UrlShortener\Provider\Bitly\GenericAccessTokenAuthenticator;

class Bitly extends BaseDriver
{
/**
* Bitly Provider
*
* @var Mremi\UrlShortener\Provider\Bitly\BitlyProvider
*/
protected $provider;

/**
* Create a new Bitly URL Shortener instance
*
* @param string $username
* @param string $username Username or generic access token
* @param string $password
* @param integer $connectTimeout
* @param integer $timeout
* @return void
*/
public function __construct($username, $password, $connectTimeout, $timeout)
{
$this->provider = new BitlyProvider(new OAuthClient($username, $password), ['connect_timeout' => $connectTimeout, 'timeout' => $timeout]);
$authClient = $password ? new OAuthClient($username, $password) : new GenericAccessTokenAuthenticator($username);
$this->provider = new BitlyProvider($authClient, ['connect_timeout' => $connectTimeout, 'timeout' => $timeout]);
}
}

0 comments on commit 8d9c6bc

Please sign in to comment.