Client.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Lackoxygen\TiktokOpen\Base\Client;
use Lackoxygen\TiktokOpen\Application;
use Lackoxygen\TiktokOpen\Base\Event\Fail;
use Lackoxygen\TiktokOpen\Base\Event\Request;
use Lackoxygen\TiktokOpen\Base\Event\Response;
use Lackoxygen\TiktokOpen\Base\ServiceManager;
use Lackoxygen\TiktokOpen\Base\Signer\NoneSigner;
use Lackoxygen\TiktokOpen\Base\Signer\SignerInterface;
use Lackoxygen\TiktokOpen\Base\Traits\BaseClient;
use Lackoxygen\TiktokOpen\Wap\Listener;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Facades\Event;
class Client extends ServiceManager
{
use BaseClient;
private string $requestOption = '';
private bool $withSession;
private SignerInterface $signer;
public function __construct(
Application $app, $requestOption = '', $withSession = false
)
{
parent::__construct($app);
$this->requestOption = $requestOption;
$this->withSession = $withSession;
$this->signer = new NoneSigner();
$this->listen();
}
protected function listen()
{
Event::listen(Request::class, [Listener::class, 'request']);
Event::listen(Response::class, [Listener::class, 'response']);
Event::listen(Fail::class, [Listener::class, 'fail']);
}
public function asForm(): Client
{
return new Client(
$this->app,
RequestOptions::FORM_PARAMS,
$this->withSession
);
}
public function asJson(): Client
{
return new Client(
$this->app,
RequestOptions::JSON,
$this->withSession
);
}
public function asMultipart(): Client
{
return new Client(
$this->app,
RequestOptions::MULTIPART,
$this->withSession
);
}
public function asQuery(): Client
{
return new Client(
$this->app,
RequestOptions::QUERY,
$this->withSession
);
}
public function withSession(): Client
{
return new Client(
$this->app,
$this->requestOption,
true
);
}
public function signVia(SignerInterface $signer): Client
{
$this->signer = $signer;
return $this;
}
public function refresh()
{
$this->requestOption = '';
$this->withSession = false;
}
}