1 | <?php |
||
5 | class GoogleUrlShortener |
||
6 | { |
||
7 | /** |
||
8 | * Configurations. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $config = []; |
||
13 | |||
14 | /** |
||
15 | * URL Endpoint. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $url = 'https://www.googleapis.com/urlshortener/v1/url?'; |
||
20 | |||
21 | /** |
||
22 | * Extended Response. |
||
23 | * |
||
24 | * @var bool |
||
25 | */ |
||
26 | protected $extended = false; |
||
27 | |||
28 | /** |
||
29 | * Buffer URLs. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected static $buffer = []; |
||
34 | |||
35 | protected $curl; |
||
36 | |||
37 | /** |
||
38 | * GoogleUrlShortener constructor. |
||
39 | * |
||
40 | * @param $app |
||
41 | */ |
||
42 | public function __construct($app) |
||
50 | |||
51 | /** |
||
52 | * Get the API Url. |
||
53 | * |
||
54 | * @return string |
||
55 | */ |
||
56 | protected function url() |
||
62 | |||
63 | /** |
||
64 | * Enable Extended Response. |
||
65 | * |
||
66 | * @return $this |
||
67 | */ |
||
68 | public function extended() |
||
74 | |||
75 | /** |
||
76 | * Shorten URL here. |
||
77 | * |
||
78 | * @param $longUrl |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function shorten($longUrl) |
||
90 | |||
91 | /** |
||
92 | * Expand URL here. |
||
93 | * |
||
94 | * @param $shortUrl |
||
95 | * @return mixed |
||
96 | */ |
||
97 | public function expand($shortUrl) |
||
105 | |||
106 | /** |
||
107 | * Shortener Request. |
||
108 | * |
||
109 | * @param $longUrl |
||
110 | * @return mixed |
||
111 | */ |
||
112 | private function getShorternerResponse($longUrl) |
||
124 | |||
125 | /** |
||
126 | * Destroy Curl. |
||
127 | */ |
||
128 | public function __destruct() |
||
133 | } |
||
134 |