|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use Iterator; |
|
6
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlBuilder; |
|
7
|
|
|
use seregazhuk\PinterestBot\Api\Traits\Followable; |
|
8
|
|
|
use seregazhuk\PinterestBot\Api\Traits\Searchable; |
|
9
|
|
|
use seregazhuk\PinterestBot\Exceptions\WrongFollowingType; |
|
10
|
|
|
|
|
11
|
|
|
class Pinners extends Provider |
|
12
|
|
|
{ |
|
13
|
|
|
use Searchable, Followable; |
|
14
|
|
|
|
|
15
|
|
|
protected $loginRequiredFor = ['follow', 'unFollow']; |
|
16
|
|
|
|
|
17
|
|
|
protected $searchScope = 'people'; |
|
18
|
|
|
protected $entityIdName = 'user_id'; |
|
19
|
|
|
protected $followersFor = 'username'; |
|
20
|
|
|
|
|
21
|
|
|
protected $followUrl = UrlBuilder::RESOURCE_FOLLOW_USER; |
|
22
|
|
|
protected $unFollowUrl = UrlBuilder::RESOURCE_UNFOLLOW_USER; |
|
23
|
|
|
protected $followersUrl = UrlBuilder::RESOURCE_USER_FOLLOWERS; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get user info. |
|
27
|
|
|
* If username param is not specified, will |
|
28
|
|
|
* return info for logged user. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $username |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function info($username) |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->execGetRequest(['username' => $username], UrlBuilder::RESOURCE_USER_INFO); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Get following info for pinner. |
|
41
|
|
|
* |
|
42
|
|
|
* @param string $username |
|
43
|
|
|
* @param string $type |
|
44
|
|
|
* @param int $limit |
|
45
|
|
|
* @return Iterator |
|
46
|
|
|
* @throws WrongFollowingType |
|
47
|
|
|
*/ |
|
48
|
|
|
public function following($username, $type = UrlBuilder::FOLLOWING_PEOPLE, $limit = 0) |
|
49
|
|
|
{ |
|
50
|
|
|
$followingUrl = UrlBuilder::getFollowingUrlByType($type); |
|
51
|
|
|
|
|
52
|
|
|
if(empty($followingUrl)) { |
|
53
|
|
|
throw new WrongFollowingType("No following results for $type"); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->paginate($username, $followingUrl, $limit); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get following people for pinner. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $username |
|
63
|
|
|
* @param int $limit |
|
64
|
|
|
* @return Iterator |
|
65
|
|
|
*/ |
|
66
|
|
|
public function followingPeople($username, $limit = 0) |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->following($username, UrlBuilder::FOLLOWING_PEOPLE, $limit); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get following boards for pinner. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $username |
|
75
|
|
|
* @param int $limit |
|
76
|
|
|
* @return Iterator |
|
77
|
|
|
*/ |
|
78
|
|
|
public function followingBoards($username, $limit = 0) |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->following($username, UrlBuilder::FOLLOWING_BOARDS, $limit); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get following interests for pinner. |
|
85
|
|
|
* |
|
86
|
|
|
* @param string $username |
|
87
|
|
|
* @param int $limit |
|
88
|
|
|
* @return Iterator |
|
89
|
|
|
* @throws WrongFollowingType |
|
90
|
|
|
*/ |
|
91
|
|
|
public function followingInterests($username, $limit = 0) |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->following($username, UrlBuilder::FOLLOWING_INTERESTS, $limit); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get pinner pins. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $username |
|
100
|
|
|
* @param int $limit |
|
101
|
|
|
* |
|
102
|
|
|
* @return Iterator |
|
103
|
|
|
*/ |
|
104
|
|
|
public function pins($username, $limit = 0) |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->paginate( |
|
107
|
|
|
$username, UrlBuilder::RESOURCE_USER_PINS, $limit |
|
108
|
|
|
); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @param string $username |
|
113
|
|
|
* @param string $url |
|
114
|
|
|
* @param int $limit |
|
115
|
|
|
* |
|
116
|
|
|
* @return Iterator |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function paginate($username, $url, $limit) |
|
119
|
|
|
{ |
|
120
|
|
|
$params = [ |
|
121
|
|
|
'data' => ['username' => $username], |
|
122
|
|
|
'url' => $url, |
|
123
|
|
|
]; |
|
124
|
|
|
|
|
125
|
|
|
return $this->getPaginatedResponse($params, $limit); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|