@@ 9-34 (lines=26) @@ | ||
6 | use LeadThread\Shortener\Interfaces\UrlShortener; |
|
7 | use LeadThread\Shortener\Rotators\Account\Bitly as BitlyRotator; |
|
8 | ||
9 | class Bitly implements UrlShortener |
|
10 | { |
|
11 | protected $config; |
|
12 | protected $rotator; |
|
13 | ||
14 | public function __construct(BitlyRotator $rotator = null) |
|
15 | { |
|
16 | $this->config = config('shortener.accounts.bitly'); |
|
17 | ||
18 | if(!$rotator instanceof BitlyRotator){ |
|
19 | $drivers = []; |
|
20 | ||
21 | foreach ($this->config as $c) { |
|
22 | $drivers[] = new BitlyDriver($c['token']); |
|
23 | } |
|
24 | ||
25 | $rotator = new BitlyRotator($drivers); |
|
26 | } |
|
27 | ||
28 | $this->rotator = $rotator; |
|
29 | } |
|
30 | ||
31 | public function shorten($url, $encode = true){ |
|
32 | return $this->rotator->shorten($url, $encode); |
|
33 | } |
|
34 | } |
@@ 9-34 (lines=26) @@ | ||
6 | use LeadThread\Shortener\Interfaces\UrlShortener; |
|
7 | use LeadThread\Shortener\Rotators\Account\Google as GoogleRotator; |
|
8 | ||
9 | class Google implements UrlShortener |
|
10 | { |
|
11 | protected $config; |
|
12 | protected $rotator; |
|
13 | ||
14 | public function __construct(GoogleRotator $rotator = null) |
|
15 | { |
|
16 | $this->config = config('shortener.accounts.google'); |
|
17 | ||
18 | if(!$rotator instanceof GoogleRotator){ |
|
19 | $drivers = []; |
|
20 | ||
21 | foreach ($this->config as $c) { |
|
22 | $drivers[] = new GoogleDriver($c['token']); |
|
23 | } |
|
24 | ||
25 | $rotator = new GoogleRotator($drivers); |
|
26 | } |
|
27 | ||
28 | $this->rotator = $rotator; |
|
29 | } |
|
30 | ||
31 | public function shorten($url, $encode = true){ |
|
32 | return $this->rotator->shorten($url, $encode); |
|
33 | } |
|
34 | } |