1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiClients\Client\Twitter; |
4
|
|
|
|
5
|
|
|
use ApiClients\Client\Twitter\Resource\ProfileInterface; |
6
|
|
|
use ApiClients\Client\Twitter\Resource\TweetInterface; |
7
|
|
|
use ApiClients\Client\Twitter\Resource\UserInterface; |
8
|
|
|
use React\EventLoop\Factory as LoopFactory; |
9
|
|
|
use React\EventLoop\LoopInterface; |
10
|
|
|
use function Clue\React\Block\await; |
11
|
|
|
|
12
|
|
|
final class Client implements ClientInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var LoopInterface |
16
|
|
|
*/ |
17
|
|
|
protected $loop; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var AsyncClient |
21
|
|
|
*/ |
22
|
|
|
protected $client; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var StreamingClient |
26
|
|
|
*/ |
27
|
|
|
protected $streamingClient; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
string $consumerKey, |
31
|
|
|
string $consumerSecret |
32
|
|
|
) { |
33
|
|
|
$this->loop = LoopFactory::create(); |
34
|
|
|
$this->client = new AsyncClient($consumerKey, $consumerSecret, $this->loop); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function withAccessToken(string $accessToken, string $accessTokenSecret): Client |
38
|
|
|
{ |
39
|
|
|
$clone = clone $this; |
40
|
|
|
$clone->client = $this->client->withAccessToken($accessToken, $accessTokenSecret); |
41
|
|
|
return $clone; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function withOutAccessToken(): Client |
45
|
|
|
{ |
46
|
|
|
$clone = clone $this; |
47
|
|
|
$clone->client = $this->client->withOutAccessToken(); |
48
|
|
|
return $clone; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function stream(): StreamingClient |
52
|
|
|
{ |
53
|
|
|
if (!($this->streamingClient instanceof StreamingClient)) { |
54
|
|
|
$this->streamingClient = new StreamingClient( |
55
|
|
|
$this->loop, |
56
|
|
|
$this->client->getCommandBus(), |
57
|
|
|
$this->client->stream() |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->streamingClient; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function tweet(string $tweet): TweetInterface |
65
|
|
|
{ |
66
|
|
|
return await( |
67
|
|
|
$this->client->tweet($tweet), |
|
|
|
|
68
|
|
|
$this->loop |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function profile(): ProfileInterface |
73
|
|
|
{ |
74
|
|
|
return await( |
75
|
|
|
$this->client->profile(), |
76
|
|
|
$this->loop |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function user(string $tweet): UserInterface |
81
|
|
|
{ |
82
|
|
|
return await( |
83
|
|
|
$this->client->user($tweet), |
84
|
|
|
$this->loop |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.