1 | <?php |
||
31 | class CodebirdTwitterApiGateway implements TwitterApiGateway, LoggerAwareInterface |
||
32 | { |
||
33 | use LoggerAwareTrait; |
||
34 | |||
35 | /** @var Codebird */ |
||
36 | private $codebird; |
||
37 | |||
38 | /** |
||
39 | * Constructor |
||
40 | * |
||
41 | * @param CodebirdFactory $factory |
||
42 | * @param string $consumerKey |
||
43 | * @param string $consumerSecret |
||
44 | */ |
||
45 | 39 | public function __construct( |
|
53 | |||
54 | /** |
||
55 | * Authenticate a user |
||
56 | * |
||
57 | * @param AuthenticationToken $token |
||
58 | */ |
||
59 | 6 | public function authenticate(AuthenticationToken $token) |
|
63 | |||
64 | /** |
||
65 | * Get Oauth authentication URL |
||
66 | * |
||
67 | * @return string |
||
68 | * |
||
69 | * @throws TwitterException |
||
70 | */ |
||
71 | 3 | public function getAuthenticationUrl() |
|
79 | |||
80 | /** |
||
81 | * Get the authentication token by providing the verifier. |
||
82 | * |
||
83 | * @param string $verificationToken |
||
84 | * |
||
85 | * @return AuthenticationToken |
||
86 | * |
||
87 | * @throws TwitterException |
||
88 | */ |
||
89 | 3 | public function getAuthenticationToken($verificationToken) |
|
97 | |||
98 | /** |
||
99 | * Sets streaming callback |
||
100 | * |
||
101 | * @param UserStreamQuery $request |
||
102 | * @param callable $callback |
||
103 | * |
||
104 | * @throws \Exception |
||
105 | */ |
||
106 | 3 | public function consumeUserStream( |
|
113 | |||
114 | /** |
||
115 | * @param UserInformationQuery $request |
||
116 | * |
||
117 | * @return ApiResponse |
||
118 | * |
||
119 | * @throws TwitterException |
||
120 | */ |
||
121 | 3 | public function getUserInformation(UserInformationQuery $request) |
|
125 | |||
126 | /** |
||
127 | * Get the tweets mentioning the user |
||
128 | * |
||
129 | * @param MentionsTimelineQuery $query |
||
130 | * |
||
131 | * @return ApiResponse |
||
132 | * |
||
133 | * @throws TwitterException |
||
134 | */ |
||
135 | 3 | public function statusesMentionsTimeLine(MentionsTimelineQuery $query) |
|
142 | |||
143 | /** |
||
144 | * Get the tweets of the user |
||
145 | * |
||
146 | * @param UserTimelineQuery $query |
||
147 | * |
||
148 | * @return ApiResponse |
||
149 | * |
||
150 | * @throws TwitterException |
||
151 | */ |
||
152 | public function statusesUserTimeLine(UserTimelineQuery $query) |
||
159 | |||
160 | /** |
||
161 | * Get the direct messages to teh user |
||
162 | * |
||
163 | * @param DirectMessageQuery $query |
||
164 | * |
||
165 | * @return ApiResponse |
||
166 | * |
||
167 | * @throws TwitterException |
||
168 | */ |
||
169 | 3 | public function directMessages(DirectMessageQuery $query) |
|
176 | |||
177 | /** |
||
178 | * Get the direct messages sent by the user |
||
179 | * |
||
180 | * @param SentDirectMessageQuery $query |
||
181 | * |
||
182 | * @return ApiResponse |
||
183 | * |
||
184 | * @throws TwitterException |
||
185 | */ |
||
186 | public function sentDirectMessages(SentDirectMessageQuery $query) |
||
193 | |||
194 | /** |
||
195 | * @param FriendsListQuery $query |
||
196 | * |
||
197 | * @return ApiResponse |
||
198 | * |
||
199 | * @throws TwitterException |
||
200 | */ |
||
201 | public function friends(FriendsListQuery $query) |
||
205 | |||
206 | /** |
||
207 | * Sends a tweet |
||
208 | * |
||
209 | * @param TweetParameters $parameters |
||
210 | * |
||
211 | * @return ApiResponse |
||
212 | * |
||
213 | * @throws TwitterException |
||
214 | */ |
||
215 | 9 | public function updateStatus(TweetParameters $parameters) |
|
219 | |||
220 | /** |
||
221 | * Sends a direct message to $user |
||
222 | * |
||
223 | * @param DirectMessageParameters $parameters |
||
224 | * |
||
225 | * @return ApiResponse |
||
226 | * |
||
227 | * @throws TwitterException |
||
228 | */ |
||
229 | 3 | public function newDirectMessage(DirectMessageParameters $parameters) |
|
233 | |||
234 | /** |
||
235 | * Delete a tweet |
||
236 | * |
||
237 | * @param DeleteTweetParameters $parameters |
||
238 | * |
||
239 | * @return ApiResponse |
||
240 | * |
||
241 | * @throws TwitterException |
||
242 | */ |
||
243 | public function deleteStatus(DeleteTweetParameters $parameters) |
||
247 | |||
248 | /** |
||
249 | * Delete a direct message |
||
250 | * |
||
251 | * @param DeleteDirectMessageParameters $parameters |
||
252 | * |
||
253 | * @return ApiResponse |
||
254 | * |
||
255 | * @throws TwitterException |
||
256 | */ |
||
257 | public function deleteDirectMessage(DeleteDirectMessageParameters $parameters) |
||
261 | |||
262 | /** |
||
263 | * Follow a $user |
||
264 | * |
||
265 | * @param FollowParameters $parameters |
||
266 | * |
||
267 | * @return ApiResponse |
||
268 | * |
||
269 | * @throws TwitterException |
||
270 | */ |
||
271 | 3 | public function createFriendship(FollowParameters $parameters) |
|
275 | |||
276 | /** |
||
277 | * Unfollow a $user |
||
278 | * |
||
279 | * @param UserIdentifier $parameters |
||
280 | * |
||
281 | * @return ApiResponse |
||
282 | * |
||
283 | * @throws TwitterException |
||
284 | */ |
||
285 | 3 | public function destroyFriendship(UserIdentifier $parameters) |
|
289 | |||
290 | /** |
||
291 | * Handles a twitter API response object |
||
292 | * |
||
293 | * @param object $result |
||
294 | * @param bool $isList |
||
295 | * |
||
296 | * @return ApiResponse |
||
297 | * |
||
298 | * @throws TwitterException |
||
299 | */ |
||
300 | 33 | private function handleResult($result, $isList = false) |
|
310 | |||
311 | /** |
||
312 | * @param object $result |
||
313 | * |
||
314 | * @throws TwitterException |
||
315 | */ |
||
316 | 33 | private function handleErrors($result) |
|
323 | |||
324 | /** |
||
325 | * @param object $result |
||
326 | * |
||
327 | * @return HttpStatus |
||
328 | * |
||
329 | * @throws TwitterException |
||
330 | */ |
||
331 | 30 | private function getHttpStatus($result) |
|
340 | |||
341 | /** |
||
342 | * @param object $result |
||
343 | * |
||
344 | * @return ApiRate |
||
345 | */ |
||
346 | 27 | private function getRate($result) |
|
354 | |||
355 | /** |
||
356 | * @param object $result |
||
357 | * @param bool $isList |
||
358 | * |
||
359 | * @return object|array|null |
||
360 | */ |
||
361 | 27 | private function getContent($result, $isList) |
|
380 | } |
||
381 |