-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.php
More file actions
197 lines (177 loc) · 6.04 KB
/
Copy pathClient.php
File metadata and controls
197 lines (177 loc) · 6.04 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
declare(strict_types=1);
namespace BeeperDesktop;
use BeeperDesktop\BeeperDesktopClientService\BeeperDesktopClientServiceFocusResponse;
use BeeperDesktop\BeeperDesktopClientService\BeeperDesktopClientServiceSearchResponse;
use BeeperDesktop\Core\BaseClient;
use BeeperDesktop\Core\Exceptions\APIException;
use BeeperDesktop\Core\Util;
use BeeperDesktop\Services\AccountsService;
use BeeperDesktop\Services\AssetsService;
use BeeperDesktop\Services\BeeperDesktopClientRawService;
use BeeperDesktop\Services\BeeperDesktopClientService;
use BeeperDesktop\Services\ChatsService;
use BeeperDesktop\Services\InfoService;
use BeeperDesktop\Services\MessagesService;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
/**
* @phpstan-import-type NormalizedRequest from \BeeperDesktop\Core\BaseClient
* @phpstan-import-type RequestOpts from \BeeperDesktop\RequestOptions
*/
class Client extends BaseClient
{
public string $accessToken;
/**
* @api
*/
public AccountsService $accounts;
/**
* @api
*/
public ChatsService $chats;
/**
* @api
*/
public MessagesService $messages;
/**
* @api
*/
public AssetsService $assets;
/**
* @api
*/
public InfoService $info;
/**
* @api
*/
public BeeperDesktopClientRawService $raw;
/**
* @api
*/
private BeeperDesktopClientService $beeperDesktopClientService;
/**
* @param RequestOpts|null $requestOptions
*/
public function __construct(
?string $accessToken = null,
?string $baseUrl = null,
RequestOptions|array|null $requestOptions = null,
) {
$this->accessToken = (string) ($accessToken ?? Util::getenv(
'BEEPER_ACCESS_TOKEN'
));
$baseUrl ??= Util::getenv(
'BEEPER_DESKTOP_BASE_URL'
) ?: 'http://localhost:23373';
$options = RequestOptions::parse(
RequestOptions::with(
uriFactory: Psr17FactoryDiscovery::findUriFactory(),
streamFactory: Psr17FactoryDiscovery::findStreamFactory(),
requestFactory: Psr17FactoryDiscovery::findRequestFactory(),
transporter: Psr18ClientDiscovery::find(),
),
$requestOptions,
);
parent::__construct(
headers: [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'User-Agent' => sprintf('beeperdesktop/PHP %s', VERSION),
'X-Stainless-Lang' => 'php',
'X-Stainless-Package-Version' => '0.0.1',
'X-Stainless-Arch' => Util::machtype(),
'X-Stainless-OS' => Util::ostype(),
'X-Stainless-Runtime' => php_sapi_name(),
'X-Stainless-Runtime-Version' => phpversion(),
],
baseUrl: $baseUrl,
options: $options
);
$this->accounts = new AccountsService($this);
$this->chats = new ChatsService($this);
$this->messages = new MessagesService($this);
$this->assets = new AssetsService($this);
$this->info = new InfoService($this);
$this->raw = new BeeperDesktopClientRawService($this);
$this->beeperDesktopClientService = new BeeperDesktopClientService($this);
}
/**
* @api
*
* Focus Beeper Desktop and optionally navigate to a specific chat, message, or pre-fill draft text and attachment.
*
* @param string $chatID Optional Beeper chat ID (or local chat ID) to focus after opening the app. If omitted, only opens/focuses the app.
* @param string $draftAttachmentPath optional draft attachment path to populate in the message input field
* @param string $draftText optional draft text to populate in the message input field
* @param string $messageID Optional message ID. Jumps to that message in the chat when opening.
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function focus(
?string $chatID = null,
?string $draftAttachmentPath = null,
?string $draftText = null,
?string $messageID = null,
RequestOptions|array|null $requestOptions = null,
): BeeperDesktopClientServiceFocusResponse {
return $this->beeperDesktopClientService->focus(
$chatID,
$draftAttachmentPath,
$draftText,
$messageID,
$requestOptions
);
}
/**
* @api
*
* Returns matching chats, participant name matches in groups, and the first page of messages in one call. Paginate messages via search-messages. Paginate chats via search-chats.
*
* @param string $query User-typed search text. Literal word matching (non-semantic).
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function search(
string $query,
RequestOptions|array|null $requestOptions = null
): BeeperDesktopClientServiceSearchResponse {
return $this->beeperDesktopClientService->search($query, $requestOptions);
}
/** @return array<string,string> */
protected function authHeaders(): array
{
return $this->accessToken ? [
'Authorization' => "Bearer {$this->accessToken}",
] : [];
}
/**
* @internal
*
* @param string|list<string> $path
* @param array<string,mixed> $query
* @param array<string,string|int|list<string|int>|null> $headers
* @param RequestOpts|null $opts
*
* @return array{NormalizedRequest, RequestOptions}
*/
protected function buildRequest(
string $method,
string|array $path,
array $query,
array $headers,
mixed $body,
RequestOptions|array|null $opts,
): array {
return parent::buildRequest(
method: $method,
path: $path,
query: $query,
headers: [...$this->authHeaders(), ...$headers],
body: $body,
opts: $opts,
);
}
}