Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GenericAccessToken #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions config/urlshortener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
'username' => env('URL_SHORTENER_BITLY_USERNAME', ''),
'password' => env('URL_SHORTENER_BITLY_PASSWORD', ''),
],
'bitly-gat' => [
'genericAccessToken' => env('URL_SHORTENER_BITLY_GENERIC_ACCESS_TOKEN', ''),
],
'connect_timeout' => 2,
'timeout' => 2,
];
31 changes: 31 additions & 0 deletions src/Drivers/BitlyGenericAccessToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Waavi\UrlShortener\Drivers;

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

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

/**
* Create a new Bitly URL Shortener instance
*
* @param string $username
* @param string $password
* @param integer $connectTimeout
* @param integer $timeout
* @return void
*/
public function __construct($accessToken, $connectTimeout, $timeout)
{
$this->provider = new BitlyProvider(new GenericAccessTokenAuthenticator($accessToken), ['connect_timeout' => $connectTimeout, 'timeout' => $timeout]);
}
}
11 changes: 11 additions & 0 deletions src/Drivers/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Factory
*/
protected $bitly;

/**
* Bitly Generic Access Token Driver
*
* @var BitlyGenericAccessToken
*/
protected $bitlyGAT;

/**
* Create a new Factory instance
*
Expand All @@ -32,11 +39,13 @@ public function __construct(Config $config)
$googleApiKey = $config->get('urlshortener.google.apikey');
$bitlyUsername = $config->get('urlshortener.bitly.username');
$bitlyPassword = $config->get('urlshortener.bitly.password');
$bitlyGenericAccessToken = $config->get('urlshortener.bitly-gat.genericAccessToken');
$connectTimeout = $config->get('urlshortener.connect_timeout');
$timeout = $config->get('urlshortener.timeout');

$this->google = new Google($googleApiKey, $connectTimeout, $timeout);
$this->bitly = new Bitly($bitlyUsername, $bitlyPassword, $connectTimeout, $timeout);
$this->bitlyGAT = new BitlyGenericAccessToken($bitlyGenericAccessToken, $connectTimeout, $timeout);
}

/**
Expand All @@ -54,6 +63,8 @@ public function make($driverName)
return $this->google;
case 'bitly':
return $this->bitly;
case 'bitly-gat':
return $this->bitlyGAT;
default:
throw new InvalidArgumentException('Invalid URL Shortener driver name');
}
Expand Down