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