Completed
Pull Request — master (#168)
by Sergey
03:10
created

Pinners::followingBoards()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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
     * Get pins that user likes.
113
     *
114
     * @param string $username
115
     * @param int $limit
116
     * @return Iterator
117
     */
118
    public function likes($username, $limit = 0)
119
    {
120
        return $this->paginate(
121
            $username, UrlBuilder::RESOURCE_USER_LIKES, $limit
122
        );
123
    }
124
125
    /**
126
     * @param string $username
127
     * @param string $url
128
     * @param int $limit
129
     *
130
     * @return Iterator
131
     */
132
    protected function paginate($username, $url, $limit)
133
    {
134
        $params = [
135
            'data' => ['username' => $username],
136
            'url'  => $url,
137
        ];
138
139
        return $this->getPaginatedResponse($params, $limit);
140
    }
141
}
142