1 | <?php |
||
27 | class GoogleUrl |
||
28 | { |
||
29 | /** |
||
30 | * |
||
31 | */ |
||
32 | const BASE_URL = 'https://www.googleapis.com/urlshortener/v1/url'; |
||
33 | |||
34 | /** |
||
35 | * @var \GuzzleHttp\ClientInterface |
||
36 | */ |
||
37 | private $http; |
||
38 | |||
39 | /** |
||
40 | * @var |
||
41 | */ |
||
42 | private $key; |
||
43 | |||
44 | /** |
||
45 | * GoogleUrl constructor. |
||
46 | * @param $key |
||
47 | * @param \GuzzleHttp\ClientInterface|null $httpClient |
||
48 | */ |
||
49 | 18 | public function __construct($key, ClientInterface $httpClient = null) |
|
58 | |||
59 | /** |
||
60 | * @param $key |
||
61 | */ |
||
62 | 18 | public function setKey($key) |
|
66 | |||
67 | /** |
||
68 | * @param ActionInterface $method |
||
69 | * @return \GuzzleHttp\Message\Request|\GuzzleHttp\Message\RequestInterface |
||
70 | */ |
||
71 | 15 | private function createRequest(ActionInterface $method) |
|
83 | |||
84 | /** |
||
85 | * @param ActionInterface $method |
||
86 | * @return mixed |
||
87 | * @throws \badams\GoogleUrl\Exceptions\InvalidValueException |
||
88 | * @throws \badams\GoogleUrl\Exceptions\GoogleUrlException |
||
89 | * @throws \badams\GoogleUrl\Exceptions\InvalidKeyException |
||
90 | * @throws GoogleUrlException |
||
91 | */ |
||
92 | 15 | private function execute(ActionInterface $method) |
|
107 | |||
108 | /** |
||
109 | * @param $response |
||
110 | * @throws InvalidKeyException |
||
111 | */ |
||
112 | 6 | private function assertInvalidKey($response) |
|
118 | |||
119 | /** |
||
120 | * @param $response |
||
121 | * @throws InvalidValueException |
||
122 | * @throws \badams\GoogleUrl\Exceptions\InvalidValueException |
||
123 | */ |
||
124 | 3 | private function assertInvalidValue($response) |
|
133 | |||
134 | /** |
||
135 | * @param $longUrl |
||
136 | * @return UrlResource |
||
137 | * @throws \badams\GoogleUrl\Exceptions\InvalidValueException |
||
138 | * @throws \badams\GoogleUrl\Exceptions\GoogleUrlException |
||
139 | * @throws \badams\GoogleUrl\Exceptions\InvalidKeyException |
||
140 | */ |
||
141 | 12 | public function shorten($longUrl) |
|
145 | |||
146 | /** |
||
147 | * @param $shortUrl |
||
148 | * @return UrlResource |
||
149 | * @throws \badams\GoogleUrl\Exceptions\InvalidValueException |
||
150 | * @throws \badams\GoogleUrl\Exceptions\GoogleUrlException |
||
151 | * @throws \badams\GoogleUrl\Exceptions\InvalidKeyException |
||
152 | */ |
||
153 | 3 | public function expand($shortUrl) |
|
157 | } |
||
158 |