Completed
Push — 0.1 ( 1296ef...144915 )
by Yuichi
19:51 queued 09:46
created

PreviewApp::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace CybozuHttp\Api\Kintone;
4
5
use CybozuHttp\Client;
6
use CybozuHttp\Api\KintoneApi;
7
use CybozuHttp\Middleware\JsonStream;
8
9
/**
10
 * @author ochi51 <[email protected]>
11
 */
12
class PreviewApp
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18 2
19
    public function __construct(Client $client)
20 2
    {
21 2
        $this->client = $client;
22
    }
23
24
    /**
25
     * Deploy app
26
     * https://cybozudev.zendesk.com/hc/ja/articles/204699420
27
     *
28
     * @param integer $id
29
     * @param integer $guestSpaceId
30
     * @param integer $revision
31
     * @param boolean $revert
32
     * @return array
33 19
     */
34
    public function deploy($id, $guestSpaceId = null, $revision = -1, $revert = false): array
35 19
    {
36 19
        return $this->deployApps([[
37
            'app' => $id,
38 19
            'revision' => $revision
39
        ]], $guestSpaceId, $revert);
40
    }
41
42
    /**
43
     * Deploy apps
44
     * https://cybozudev.zendesk.com/hc/ja/articles/204699420
45
     *
46
     * @param array   $apps
47
     * @param integer $guestSpaceId
48
     * @param boolean $revert
49
     * @return array
50 19
     */
51
    public function deployApps(array $apps, $guestSpaceId = null, $revert = false): array
52
    {
53 19
        $options = ['json' => compact('apps', 'revert')];
54
55 19
        /** @var JsonStream $stream */
56
        $stream = $this->client
57 19
            ->post(KintoneApi::generateUrl('preview/app/deploy.json', $guestSpaceId), $options)
58 19
            ->getBody();
59 19
60
        return $stream->jsonSerialize();
61
    }
62
63
    /**
64
     * get deploy status
65
     * https://cybozudev.zendesk.com/hc/ja/articles/204699420
66
     *
67
     * @param integer $id
68
     * @param integer $guestSpaceId
69
     * @return array
70 19
     */
71
    public function getDeployStatus($id, $guestSpaceId = null): array
72 19
    {
73
        return $this->getDeployStatuses([$id], $guestSpaceId)[0];
74
    }
75
76
    /**
77
     * get deploy statuses
78
     * https://cybozudev.zendesk.com/hc/ja/articles/204699420
79
     *
80
     * @param array $ids
81
     * @param integer $guestSpaceId
82
     * @return array
83 19
     */
84
    public function getDeployStatuses(array $ids, $guestSpaceId = null): array
85 19
    {
86
        $options = ['json' => ['apps' => $ids]];
87 19
88 19
        /** @var JsonStream $stream */
89 19
        $stream = $this->client
90
            ->get(KintoneApi::generateUrl('preview/app/deploy.json', $guestSpaceId), $options)
91
            ->getBody();
92
93
        return $stream->jsonSerialize()['apps'];
94
    }
95
96
    /**
97
     * Post preview app
98
     * https://cybozudev.zendesk.com/hc/ja/articles/202931674#step1
99
     *
100
     * @param string  $name
101
     * @param integer $spaceId
102 28
     * @param integer $threadId
103
     * @param integer $guestSpaceId
104 28
     * @return array
105 28
     */
106 28
    public function post($name, $spaceId = null, $threadId = null, $guestSpaceId = null): array
107 28
    {
108 28
        $options = ['json' => ['name' => $name]];
109
        if ($spaceId !== null) {
110 28
            $options['json']['space'] = $spaceId;
111 28
            $options['json']['thread'] = $threadId;
112 28
        }
113
114
        /** @var JsonStream $stream */
115
        $stream = $this->client
116
            ->post(KintoneApi::generateUrl('preview/app.json', $guestSpaceId), $options)
117
            ->getBody();
118
119
        return $stream->jsonSerialize();
120
    }
121
122
    /**
123
     * Get app settings
124 28
     * https://cybozudev.zendesk.com/hc/ja/articles/204694170
125 28
     *
126 1
     * @param integer $id
127
     * @param integer $guestSpaceId
128 1
     * @param string $lang
129 1
     * @return array
130 1
     */
131
    public function getSettings($id, $guestSpaceId = null, $lang = 'default'): array
132
    {
133
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
134
135
        /** @var JsonStream $stream */
136
        $stream = $this->client
137
            ->get(KintoneApi::generateUrl('preview/app/settings.json', $guestSpaceId), $options)
138
            ->getBody();
139
140
        return $stream->jsonSerialize();
141
    }
142 1
143
    /**
144 1
     * Get app form fields
145
     * https://cybozudev.zendesk.com/hc/ja/articles/204783170#anchor_getform_fields
146 1
     *
147 1
     * @param integer $id
148 1
     * @param integer $guestSpaceId
149
     * @param string $lang
150
     * @return array
151
     */
152
    public function getFields($id, $guestSpaceId = null, $lang = 'default'): array
153
    {
154
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
155
156
        /** @var JsonStream $stream */
157
        $stream = $this->client
158
            ->get(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
159
            ->getBody();
160 1
161
        return $stream->jsonSerialize();
162 1
    }
163
164 1
    /**
165 1
     * Get app form layout
166 1
     * https://cybozudev.zendesk.com/hc/ja/articles/204783170#anchor_getform_layout
167
     *
168
     * @param integer $id
169
     * @param integer $guestSpaceId
170
     * @param string $lang
171
     * @return array
172
     */
173
    public function getLayout($id, $guestSpaceId = null, $lang = 'default'): array
174
    {
175
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
176
177
        /** @var JsonStream $stream */
178 1
        $stream = $this->client
179
            ->get(KintoneApi::generateUrl('preview/app/form/layout.json', $guestSpaceId), $options)
180 1
            ->getBody();
181
182 1
        return $stream->jsonSerialize();
183 1
    }
184 1
185
    /**
186
     * Get app views
187
     * https://cybozudev.zendesk.com/hc/ja/articles/204529784
188
     *
189
     * @param integer $id
190
     * @param integer $guestSpaceId
191
     * @param string $lang
192
     * @return array
193
     */
194
    public function getViews($id, $guestSpaceId = null, $lang = 'default'): array
195
    {
196 1
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
197
198 1
        /** @var JsonStream $stream */
199
        $stream = $this->client
200 1
            ->get(KintoneApi::generateUrl('preview/app/views.json', $guestSpaceId), $options)
201 1
            ->getBody();
202 1
203
        return $stream->jsonSerialize();
204
    }
205
206
    /**
207
     * Get app acl
208
     * https://cybozudev.zendesk.com/hc/ja/articles/204529754
209
     *
210
     * @param integer $id
211
     * @param integer $guestSpaceId
212
     * @param string $lang
213
     * @return array
214 1
     */
215
    public function getAcl($id, $guestSpaceId = null, $lang = 'default'): array
216 1
    {
217
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
218 1
219 1
        /** @var JsonStream $stream */
220 1
        $stream = $this->client
221
            ->get(KintoneApi::generateUrl('preview/app/acl.json', $guestSpaceId), $options)
222
            ->getBody();
223
224
        return $stream->jsonSerialize();
225
    }
226
227
    /**
228
     * Get record acl
229
     * https://cybozudev.zendesk.com/hc/ja/articles/204791510
230
     *
231
     * @param integer $id
232 1
     * @param integer $guestSpaceId
233
     * @param string $lang
234 1
     * @return array
235
     */
236 1
    public function getRecordAcl($id, $guestSpaceId = null, $lang = 'default'): array
237 1
    {
238 1
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
239
240
        /** @var JsonStream $stream */
241
        $stream = $this->client
242
            ->get(KintoneApi::generateUrl('preview/record/acl.json', $guestSpaceId), $options)
243
            ->getBody();
244
245
        return $stream->jsonSerialize();
246
    }
247
248
    /**
249 2
     * Get field acl
250
     * https://cybozudev.zendesk.com/hc/ja/articles/204791520
251 2
     *
252
     * @param integer $id
253 2
     * @param integer $guestSpaceId
254 2
     * @param string $lang
255 2
     * @return array
256
     */
257
    public function getFieldAcl($id, $guestSpaceId = null, $lang = 'default'): array
258
    {
259
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
260
261
        /** @var JsonStream $stream */
262
        $stream = $this->client
263
            ->get(KintoneApi::generateUrl('preview/field/acl.json', $guestSpaceId), $options)
264
            ->getBody();
265
266
        return $stream->jsonSerialize();
267
    }
268
269
    /**
270
     * Get app JavaScript and CSS customize
271 20
     * https://cybozudev.zendesk.com/hc/ja/articles/204529824
272
     *
273
     * @param integer $id
274 20
     * @param integer $guestSpaceId
275 20
     * @return array
276 20
     */
277 20
    public function getCustomize($id, $guestSpaceId = null): array
278 20
    {
279
        $options = ['json' => ['app' => $id]];
280 20
281
        /** @var JsonStream $stream */
282 20
        $stream = $this->client
283 20
            ->get(KintoneApi::generateUrl('preview/app/customize.json', $guestSpaceId), $options)
284 20
            ->getBody();
285
286
        return $stream->jsonSerialize();
287
    }
288
289
    /**
290
     * Get app status list
291
     * https://cybozudev.zendesk.com/hc/ja/articles/216972946
292
     *
293
     * @param integer $id
294
     * @param string  $lang
295
     * @param integer $guestSpaceId
296
     * @return array
297 23
     */
298
    public function getStatus($id, $lang = 'ja', $guestSpaceId = null): array
299
    {
300 23
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
301 23
302
        /** @var JsonStream $stream */
303 23
        $stream = $this->client
304
            ->get(KintoneApi::generateUrl('preview/app/status.json', $guestSpaceId), $options)
305 23
            ->getBody();
306 23
307 23
        return $stream->jsonSerialize();
308
    }
309
310
    /**
311
     * Put preview app settings
312
     * https://cybozudev.zendesk.com/hc/ja/articles/204730520
313
     *
314
     * @param integer $id
315
     * @param string  $name
316
     * @param string  $description
317
     * @param array   $icon
318
     * @param string  $theme
319
     * @param integer $guestSpaceId
320 1
     * @param integer $revision
321
     * @return array
322
     */
323 1
    public function putSettings($id, $name, $description, array $icon, $theme, $guestSpaceId = null, $revision = -1): array
324 1
    {
325
        $options = ['json' => [
326 1
            'app' => $id,
327
            'name' => $name,
328 1
            'description' => $description,
329 1
            'icon' => $icon,
330 1
            'theme' => $theme,
331
            'revision' => $revision
332
        ]];
333
334
        /** @var JsonStream $stream */
335
        $stream = $this->client
336
            ->put(KintoneApi::generateUrl('preview/app/settings.json', $guestSpaceId), $options)
337
            ->getBody();
338
339
        return $stream->jsonSerialize();
340
    }
341
342
    /**
343 1
     * Post form fields to preview app
344
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_addfields
345
     *
346 1
     * @param integer $id
347 1
     * @param array   $fields
348
     * @param integer $guestSpaceId
349 1
     * @param integer $revision
350
     * @return array
351 1
     */
352 1
    public function postFields($id, array $fields, $guestSpaceId = null, $revision = -1): array
353 1
    {
354
        $options = ['json' => [
355
            'app' => $id,
356
            'properties' => $fields,
357
            'revision' => $revision
358
        ]];
359
360
        /** @var JsonStream $stream */
361
        $stream = $this->client
362
            ->post(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
363
            ->getBody();
364
365
        return $stream->jsonSerialize();
366 19
    }
367
368
    /**
369 19
     * Put form fields to preview app
370 19
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_changefields
371
     *
372 19
     * @param integer $id
373
     * @param array   $fields
374 19
     * @param integer $guestSpaceId
375 19
     * @param integer $revision
376 19
     * @return array
377
     */
378
    public function putFields($id, array $fields, $guestSpaceId = null, $revision = -1): array
379
    {
380
        $options = ['json' => [
381
            'app' => $id,
382
            'properties' => $fields,
383
            'revision' => $revision
384
        ]];
385
386
        /** @var JsonStream $stream */
387
        $stream = $this->client
388
            ->put(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
389 20
            ->getBody();
390
391
        return $stream->jsonSerialize();
392 20
    }
393 20
394
    /**
395 20
     * Delete form fields to preview app
396
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_deletefields
397 20
     *
398 20
     * @param integer $id
399 20
     * @param array   $fields
400
     * @param integer $guestSpaceId
401
     * @param integer $revision
402
     * @return array
403
     */
404
    public function deleteFields($id, array $fields, $guestSpaceId = null, $revision = -1): array
405
    {
406
        $options = ['json' => [
407
            'app' => $id,
408
            'fields' => $fields,
409
            'revision' => $revision
410
        ]];
411
412 1
        /** @var JsonStream $stream */
413
        $stream = $this->client
414
            ->delete(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
415 1
            ->getBody();
416 1
417
        return $stream->jsonSerialize();
418 1
    }
419
420 1
    /**
421 1
     * Put form layout to preview app
422 1
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_changelayout
423
     *
424
     * @param integer $id
425
     * @param array   $layout
426
     * @param integer $guestSpaceId
427
     * @param integer $revision
428
     * @return array
429
     */
430
    public function putLayout($id, array $layout, $guestSpaceId = null, $revision = -1): array
431
    {
432
        $options = ['json' => [
433
            'app' => $id,
434
            'layout' => $layout,
435 1
            'revision' => $revision
436
        ]];
437
438 1
        /** @var JsonStream $stream */
439 1
        $stream = $this->client
440
            ->put(KintoneApi::generateUrl('preview/app/form/layout.json', $guestSpaceId), $options)
441 1
            ->getBody();
442
443 1
        return $stream->jsonSerialize();
444 1
    }
445 1
446
    /**
447
     * Put views to preview app
448
     * https://cybozudev.zendesk.com/hc/ja/articles/204529794
449
     *
450
     * @param integer $id
451
     * @param array   $views
452
     * @param integer $guestSpaceId
453
     * @param integer $revision
454
     * @return array
455
     */
456
    public function putViews($id, array $views, $guestSpaceId = null, $revision = -1): array
457
    {
458 1
        $options = ['json' => [
459
            'app' => $id,
460
            'views' => $views,
461 1
            'revision' => $revision
462 1
        ]];
463
464 1
        /** @var JsonStream $stream */
465
        $stream = $this->client
466 1
            ->put(KintoneApi::generateUrl('preview/app/views.json', $guestSpaceId), $options)
467 1
            ->getBody();
468 1
469
        return $stream->jsonSerialize();
470
    }
471
472
    /**
473
     * Put app acl to preview app
474
     * https://cybozudev.zendesk.com/hc/ja/articles/201941844
475
     *
476
     * @param integer $id
477
     * @param array   $rights
478
     * @param integer $guestSpaceId
479
     * @param integer $revision
480
     * @return array
481
     */
482
    public function putAcl($id, array $rights, $guestSpaceId = null, $revision = -1): array
483
    {
484 2
        $options = ['json' => [
485
            'app' => $id,
486
            'rights' => $rights,
487 2
            'revision' => $revision
488
        ]];
489 2
490 2
        /** @var JsonStream $stream */
491 2
        $stream = $this->client
492
            ->put(KintoneApi::generateUrl('preview/app/acl.json', $guestSpaceId), $options)
493
            ->getBody();
494 2
495 2
        return $stream->jsonSerialize();
496
    }
497 2
498
    /**
499 2
     * Put record acl to preview app
500 2
     * https://cybozudev.zendesk.com/hc/ja/articles/201941854
501 2
     *
502
     * @param integer $id
503
     * @param array   $rights
504
     * @param integer $guestSpaceId
505
     * @param integer $revision
506
     * @return array
507
     */
508
    public function putRecordAcl($id, array $rights, $guestSpaceId = null, $revision = -1): array
509
    {
510
        $options = ['json' => compact('id', 'rights', 'revision')];
511
512
        /** @var JsonStream $stream */
513
        $stream = $this->client
514
            ->put(KintoneApi::generateUrl('preview/record/acl.json', $guestSpaceId), $options)
515
            ->getBody();
516
517
        return $stream->jsonSerialize();
518
    }
519
520
    /**
521
     * Put field acl to preview app
522
     * https://cybozudev.zendesk.com/hc/ja/articles/201941854
523
     *
524
     * @param integer $id
525
     * @param array   $rights
526
     * @param integer $guestSpaceId
527
     * @param integer $revision
528
     * @return array
529
     */
530
    public function putFieldAcl($id, array $rights, $guestSpaceId = null, $revision = -1): array
531
    {
532
        $options = ['json' => compact('id', 'rights', 'revision')];
533
534
        /** @var JsonStream $stream */
535
        $stream = $this->client
536
            ->put(KintoneApi::generateUrl('preview/field/acl.json', $guestSpaceId), $options)
537
            ->getBody();
538
539
        return $stream->jsonSerialize();
540
    }
541
542
    /**
543
     * Put app JavaScript & CSS customize to preview app
544
     * https://cybozudev.zendesk.com/hc/ja/articles/204529834
545
     *
546
     * @param integer $id
547
     * @param array   $js
548
     * @param array   $css
549
     * @param array   $mobileJs
550
     * @param integer $guestSpaceId
551
     * @param string  $scope
552
     * @param integer $revision
553
     * @return array
554
     */
555
    public function putCustomize($id, array $js = [], array $css = [], array $mobileJs = [], $guestSpaceId = null, $scope = 'ALL', $revision = -1): array
556
    {
557
        $options = ['json' => [
558
            'app' => $id,
559
            'desktop' => compact('js', 'css'),
560
            'mobile' => [
561
                'js' => $mobileJs
562
            ],
563
            'scope' => $scope,
564
            'revision' => $revision
565
        ]];
566
567
        /** @var JsonStream $stream */
568
        $stream = $this->client
569
            ->put(KintoneApi::generateUrl('preview/app/customize.json', $guestSpaceId), $options)
570
            ->getBody();
571
572
        return $stream->jsonSerialize();
573
    }
574
575
    /**
576
     * Put app status and action
577
     * https://cybozudev.zendesk.com/hc/ja/articles/217905503
578
     *
579
     * @param integer $id
580
     * @param array   $states
581
     * @param array   $actions
582
     * @param boolean $enable
583
     * @param integer $guestSpaceId
584
     * @return array
585
     */
586
    public function putStatus($id, array $states, array $actions, $enable = true, $guestSpaceId = null): array
587
    {
588
        $options = [
589
            'json' => [
590
                'app' => $id,
591
                'enable' => $enable,
592
                'states' => $states,
593
                'actions' => $actions
594
            ]
595
        ];
596
597
        /** @var JsonStream $stream */
598
        $stream = $this->client
599
            ->put(KintoneApi::generateUrl('preview/app/status.json', $guestSpaceId), $options)
600
            ->getBody();
601
602
        return $stream->jsonSerialize();
603
    }
604
}
605