|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CybozuHttp\Api; |
|
4
|
|
|
|
|
5
|
|
|
use CybozuHttp\Api\Kintone\Apis; |
|
6
|
|
|
use CybozuHttp\Client; |
|
7
|
|
|
use CybozuHttp\Api\Kintone\App; |
|
8
|
|
|
use CybozuHttp\Api\Kintone\Apps; |
|
9
|
|
|
use CybozuHttp\Api\Kintone\PreviewApp; |
|
10
|
|
|
use CybozuHttp\Api\Kintone\Record; |
|
11
|
|
|
use CybozuHttp\Api\Kintone\Records; |
|
12
|
|
|
use CybozuHttp\Api\Kintone\Cursor; |
|
13
|
|
|
use CybozuHttp\Api\Kintone\File; |
|
14
|
|
|
use CybozuHttp\Api\Kintone\Comment; |
|
15
|
|
|
use CybozuHttp\Api\Kintone\Comments; |
|
16
|
|
|
use CybozuHttp\Api\Kintone\Graph; |
|
17
|
|
|
use CybozuHttp\Api\Kintone\Space; |
|
18
|
|
|
use CybozuHttp\Api\Kintone\Thread; |
|
19
|
|
|
use CybozuHttp\Api\Kintone\Guests; |
|
20
|
|
|
use CybozuHttp\Middleware\JsonStream; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author ochi51 <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class KintoneApi |
|
26
|
|
|
{ |
|
27
|
|
|
public const API_PREFIX = '/k/v1/'; |
|
28
|
|
|
public const GUEST_SPACE_PREFIX = '/k/guest/'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Client |
|
32
|
|
|
*/ |
|
33
|
|
|
private $client; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var Apis |
|
37
|
|
|
*/ |
|
38
|
|
|
private $apis; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var App |
|
42
|
|
|
*/ |
|
43
|
|
|
private $app; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var Apps |
|
47
|
|
|
*/ |
|
48
|
|
|
private $apps; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var PreviewApp |
|
52
|
|
|
*/ |
|
53
|
|
|
private $preview; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var Record |
|
57
|
|
|
*/ |
|
58
|
|
|
private $record; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @var Records |
|
62
|
|
|
*/ |
|
63
|
|
|
private $records; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var Cursor |
|
67
|
|
|
*/ |
|
68
|
|
|
private $cursor; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var File |
|
72
|
|
|
*/ |
|
73
|
|
|
private $file; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var Comment |
|
77
|
|
|
*/ |
|
78
|
|
|
private $comment; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var Comments |
|
82
|
|
|
*/ |
|
83
|
|
|
private $comments; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @var Graph |
|
87
|
|
|
*/ |
|
88
|
|
|
private $graph; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @var Space |
|
92
|
|
|
*/ |
|
93
|
|
|
private $space; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @var Thread |
|
97
|
|
|
*/ |
|
98
|
|
|
private $thread; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @var Guests |
|
102
|
|
|
*/ |
|
103
|
|
|
private $guests; |
|
104
|
|
|
|
|
105
|
1 |
|
public function __construct(Client $client) |
|
106
|
|
|
{ |
|
107
|
1 |
|
$this->client = $client; |
|
108
|
1 |
|
$this->apis = new Apis($client); |
|
109
|
1 |
|
$this->app = new App($client); |
|
110
|
1 |
|
$this->apps = new Apps($client); |
|
111
|
1 |
|
$this->preview = new PreviewApp($client); |
|
112
|
1 |
|
$this->record = new Record($client); |
|
113
|
1 |
|
$this->records = new Records($client); |
|
114
|
1 |
|
$this->cursor = new Cursor($client); |
|
115
|
1 |
|
$this->file = new File($client); |
|
116
|
1 |
|
$this->comment = new Comment($client); |
|
117
|
1 |
|
$this->comments = new Comments($client); |
|
118
|
1 |
|
$this->graph = new Graph($client); |
|
119
|
1 |
|
$this->space = new Space($client); |
|
120
|
1 |
|
$this->thread = new Thread($client); |
|
121
|
1 |
|
$this->guests = new Guests($client); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @param string $api |
|
126
|
|
|
* @param integer|null $guestSpaceId |
|
127
|
|
|
* @return string |
|
128
|
|
|
*/ |
|
129
|
1 |
|
public static function generateUrl($api, $guestSpaceId = null): string |
|
130
|
|
|
{ |
|
131
|
1 |
|
if ($guestSpaceId && is_numeric($guestSpaceId)) { |
|
|
|
|
|
|
132
|
|
|
return self::GUEST_SPACE_PREFIX . $guestSpaceId . '/v1/' . $api; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
1 |
|
return self::API_PREFIX . $api; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @return Client |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getClient(): Client |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->client; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return Apis |
|
148
|
|
|
*/ |
|
149
|
1 |
|
public function apis(): Apis |
|
150
|
|
|
{ |
|
151
|
1 |
|
return $this->apis; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* @return App |
|
156
|
|
|
*/ |
|
157
|
|
|
public function app(): App |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->app; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* @return Apps |
|
164
|
|
|
*/ |
|
165
|
|
|
public function apps(): Apps |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->apps; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* @return PreviewApp |
|
172
|
|
|
*/ |
|
173
|
|
|
public function preview(): PreviewApp |
|
174
|
|
|
{ |
|
175
|
|
|
return $this->preview; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* @return Record |
|
180
|
|
|
*/ |
|
181
|
|
|
public function record(): Record |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->record; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* @return Records |
|
188
|
|
|
*/ |
|
189
|
|
|
public function records(): Records |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->records; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @return Cursor |
|
196
|
|
|
*/ |
|
197
|
|
|
public function cursor(): Cursor |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->cursor; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* @return File |
|
204
|
|
|
*/ |
|
205
|
|
|
public function file(): File |
|
206
|
|
|
{ |
|
207
|
|
|
return $this->file; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @return Comment |
|
212
|
|
|
*/ |
|
213
|
|
|
public function comment(): Comment |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->comment; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return Comments |
|
220
|
|
|
*/ |
|
221
|
|
|
public function comments(): Comments |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->comments; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @return Graph |
|
228
|
|
|
*/ |
|
229
|
|
|
public function graph(): Graph |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->graph; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* @return Space |
|
236
|
|
|
*/ |
|
237
|
|
|
public function space(): Space |
|
238
|
|
|
{ |
|
239
|
|
|
return $this->space; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* @return Thread |
|
244
|
|
|
*/ |
|
245
|
|
|
public function thread(): Thread |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->thread; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return Guests |
|
252
|
|
|
*/ |
|
253
|
|
|
public function guests(): Guests |
|
254
|
|
|
{ |
|
255
|
|
|
return $this->guests; |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
/** |
|
259
|
|
|
* Post bulkRequest |
|
260
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/201941814 |
|
261
|
|
|
* |
|
262
|
|
|
* @param array $requests |
|
263
|
|
|
* @param integer $guestSpaceId |
|
264
|
|
|
* @return array |
|
265
|
|
|
*/ |
|
266
|
|
|
public function postBulkRequest(array $requests, $guestSpaceId = null): array |
|
267
|
|
|
{ |
|
268
|
|
|
$options = ['json' => ['requests' => $requests]]; |
|
269
|
|
|
|
|
270
|
|
|
/** @var JsonStream $stream */ |
|
271
|
|
|
$stream = $this->client |
|
272
|
|
|
->post(self::generateUrl('bulkRequest.json', $guestSpaceId), $options) |
|
273
|
|
|
->getBody(); |
|
274
|
|
|
|
|
275
|
|
|
return $stream->jsonSerialize()['results']; |
|
276
|
|
|
} |
|
277
|
|
|
} |
|
278
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: