Completed
Push — master ( 368732...0870ad )
by Sergey
09:08 queued 05:12
created

Pinners::checkCredentials()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 3
eloc 3
nc 2
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use Iterator;
6
use LogicException;
7
use seregazhuk\PinterestBot\Helpers\UrlHelper;
8
use seregazhuk\PinterestBot\Helpers\Pagination;
9
use seregazhuk\PinterestBot\Exceptions\AuthException;
10
use seregazhuk\PinterestBot\Helpers\Requests\PinnerHelper;
11
use seregazhuk\PinterestBot\Api\Traits\Followable;
12
use seregazhuk\PinterestBot\Api\Traits\Searchable;
13
use seregazhuk\PinterestBot\Api\Traits\HasFollowers;
14
15
class Pinners extends Provider
16
{
17
    use Searchable, Followable, HasFollowers;
18
19
    protected $loginRequiredFor = ['follow', 'unFollow'];
20
21
    protected $searchScope  = 'people';
22
    protected $entityIdName = 'user_id';
23
    protected $followersFor = 'username';
24
25
    protected $followUrl    = UrlHelper::RESOURCE_FOLLOW_USER;
26
    protected $unFollowUrl  = UrlHelper::RESOURCE_UNFOLLOW_USER;
27
    protected $followersUrl = UrlHelper::RESOURCE_USER_FOLLOWERS;
28
    
29
    /**
30
     * Get user info.
31
     * If username param is not specified, will
32
     * return info for logged user.
33
     *
34
     * @param string $username
35
     *
36
     * @return null|array
37
     */
38
    public function info($username)
39
    {
40
        return $this->execGetRequest(['username' => $username], UrlHelper::RESOURCE_USER_INFO);
41
    }
42
43
    /**
44
     * Get pinner following other pinners.
45
     *
46
     * @param string $username
47
     * @param int $limit
48
     *
49
     * @return Iterator
50
     */
51
    public function following($username, $limit = 0)
52
    {
53
        return $this->paginate(
54
            $username, UrlHelper::RESOURCE_USER_FOLLOWING, $limit
55
        );
56
    }
57
58
    /**
59
     * Get pinner pins.
60
     *
61
     * @param string $username
62
     * @param int $limit
63
     *
64
     * @return Iterator
65
     */
66
    public function pins($username, $limit = 0)
67
    {
68
        return $this->paginate(
69
            $username, UrlHelper::RESOURCE_USER_PINS, $limit
70
        );
71
    }
72
73
    /**
74
     * @param string $username
75
     * @param string $url
76
     * @param int $limit
77
     *
78
     * @return Iterator
79
     */
80
    protected function paginate($username, $url, $limit)
81
    {
82
        $params = [
83
            'data' => ['username' => $username],
84
            'url'  => $url,
85
        ];
86
87
        return (new Pagination($this))->paginateOver('getPaginatedData', $params, $limit);
88
    }
89
}
90