Completed
Push — master ( 54c965...f73d6c )
by Sergey
05:24 queued 02:35
created

Bot::wait()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace seregazhuk\PinterestBot;
4
5
use seregazhuk\PinterestBot\Api\Providers\Auth;
6
use seregazhuk\PinterestBot\Api\Providers\Inbox;
7
use seregazhuk\PinterestBot\Api\Providers\Pins;
8
use seregazhuk\PinterestBot\Api\Providers\User;
9
use seregazhuk\PinterestBot\Api\Providers\Topics;
10
use seregazhuk\PinterestBot\Api\Providers\Boards;
11
use seregazhuk\PinterestBot\Api\Providers\Pinners;
12
use seregazhuk\PinterestBot\Api\Providers\Comments;
13
use seregazhuk\PinterestBot\Api\Providers\Keywords;
14
use seregazhuk\PinterestBot\Api\ProvidersContainer;
15
use seregazhuk\PinterestBot\Api\Providers\Interests;
16
use seregazhuk\PinterestBot\Api\Contracts\HttpClient;
17
use seregazhuk\PinterestBot\Api\Providers\Core\Provider;
18
19
/**
20
 * Class Bot.
21
 *
22
 * @property Pins $pins 
23
 * @property Inbox $inbox
24
 * @property User $user
25
 * @property Boards $boards
26
 * @property Pinners $pinners
27
 * @property Keywords $keywords
28
 * @property Interests $interests
29
 * @property Topics $topics
30
 * @property Auth $auth
31
 * @property Comments $comments
32
 *
33
 * @method HttpClient getHttpClient
34
 * @method string|null getLastError
35
 */
36
class Bot
37
{
38
    /**
39
     * @var ProvidersContainer
40
     */
41
    protected $providersContainer;
42
43
    /**
44
     * @param ProvidersContainer $providersContainer
45
     */
46
    public function __construct(ProvidersContainer $providersContainer)
47
    {
48
        $this->providersContainer = $providersContainer;
49
    }
50
51
    /**
52
     * Magic method to access different providers from the providers container.
53
     *
54
     * @param string $provider
55
     * @return Provider
56
     */
57
    public function __get($provider)
58
    {
59
        return $this->providersContainer->getProvider($provider);
60
    }
61
62
    /**
63
     *  All method calls are proxied to the providers container.
64
     *
65
     * @param string $method
66
     * @param array $parameters
67
     * @return mixed
68
     */
69
    public function __call($method, $parameters)
70
    {
71
        return call_user_func([$this->providersContainer, $method], $parameters);
72
    }
73
74
    /**
75
     * Returns client context from Pinterest response. By default info returns from the last
76
     * Pinterest response. If there was no response before or the argument $reload is
77
     * true, we make a dummy request to the main page to update client context.
78
     *
79
     * @param bool $reload
80
     * @return array|null
81
     */
82
    public function getClientInfo($reload = false)
83
    {
84
        $clientInfo = $this->providersContainer->getClientInfo();
85
86
        if(is_null($clientInfo) || $reload) {
87
            $this->user->visitPage();
88
        }
89
90
        return $this->providersContainer->getClientInfo();
91
    }
92
93
    /**
94
     * Creates a timeout
95
     * @param int $seconds
96
     * @return $this
97
     */
98
    public function wait($seconds = 1)
99
    {
100
        sleep($seconds);
101
        
102
        return $this;
103
    }
104
}
105