1 | <?php |
||
15 | class Pinners extends Provider |
||
16 | { |
||
17 | use Searchable, Followable, HasFollowers; |
||
18 | |||
19 | protected $loginRequired = [ |
||
20 | 'follow', |
||
21 | 'unFollow', |
||
22 | ]; |
||
23 | |||
24 | /** |
||
25 | * Get user info. |
||
26 | * If username param is not specified, will |
||
27 | * return info for logged user. |
||
28 | * |
||
29 | * @param string $username |
||
30 | * |
||
31 | * @return null|array |
||
32 | */ |
||
33 | public function info($username) |
||
34 | { |
||
35 | return $this->execGetRequest(['username' => $username], UrlHelper::RESOURCE_USER_INFO); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Get pinner followers. |
||
40 | * |
||
41 | * @param string $username |
||
42 | * @param int $batchesLimit |
||
43 | * |
||
44 | * @return Iterator |
||
45 | */ |
||
46 | public function followers($username, $batchesLimit = 0) |
||
47 | { |
||
48 | return $this->paginate( |
||
49 | $username, UrlHelper::RESOURCE_USER_FOLLOWERS, $batchesLimit |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Get pinner following other pinners. |
||
55 | * |
||
56 | * @param string $username |
||
57 | * @param int $batchesLimit |
||
58 | * |
||
59 | * @return Iterator |
||
60 | */ |
||
61 | public function following($username, $batchesLimit = 0) |
||
62 | { |
||
63 | return $this->paginate( |
||
64 | $username, UrlHelper::RESOURCE_USER_FOLLOWING, $batchesLimit |
||
65 | ); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get pinner pins. |
||
70 | * |
||
71 | * @param string $username |
||
72 | * @param int $batchesLimit |
||
73 | * |
||
74 | * @return Iterator |
||
75 | */ |
||
76 | public function pins($username, $batchesLimit = 0) |
||
77 | { |
||
78 | return $this->paginate( |
||
79 | $username, UrlHelper::RESOURCE_USER_PINS, $batchesLimit |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Login as pinner. |
||
85 | * |
||
86 | * @param string $username |
||
87 | * @param string $password |
||
88 | * |
||
89 | * @throws AuthException |
||
90 | * |
||
91 | * @return bool |
||
92 | */ |
||
93 | public function login($username, $password) |
||
94 | { |
||
95 | if ($this->request->isLoggedIn()) { |
||
96 | return true; |
||
97 | } |
||
98 | |||
99 | $this->checkCredentials($username, $password); |
||
100 | |||
101 | $postString = PinnerHelper::createLoginQuery($username, $password); |
||
102 | $this->request->clearToken(); |
||
103 | |||
104 | $response = $this->request->exec(UrlHelper::RESOURCE_LOGIN, $postString); |
||
105 | $result = $this->response->hasErrors($response); |
||
106 | if (!$result) { |
||
107 | throw new AuthException($this->response->getLastError()['message']); |
||
108 | } |
||
109 | $this->request->login(); |
||
110 | |||
111 | return $result; |
||
112 | } |
||
113 | |||
114 | public function logout() |
||
115 | { |
||
116 | $this->request->logout(); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Validates password and login. |
||
121 | * |
||
122 | * @param string $username |
||
123 | * @param string $password |
||
124 | */ |
||
125 | protected function checkCredentials($username, $password) |
||
131 | |||
132 | /** |
||
133 | * Search scope. |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | protected function getScope() |
||
141 | |||
142 | protected function getEntityIdName() |
||
146 | |||
147 | /** |
||
148 | * Follow resource. |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | protected function getFollowUrl() |
||
156 | |||
157 | /** |
||
158 | * UnFollow resource. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | protected function getUnfFollowUrl() |
||
166 | |||
167 | /** |
||
168 | * @param string $username |
||
169 | * @param string $url |
||
170 | * @param int $batchesLimit |
||
171 | * |
||
172 | * @return Iterator |
||
173 | */ |
||
174 | public function paginate($username, $url, $batchesLimit) |
||
183 | } |
||
184 |