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