Passed
Pull Request — master (#77)
by Yuichi
04:41 queued 02:24
created

PreviewApp::getAcl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 10
ccs 0
cts 6
cp 0
crap 2
rs 10
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
19 1
    public function __construct(Client $client)
20
    {
21 1
        $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
     */
34
    public function deploy($id, $guestSpaceId = null, $revision = -1, $revert = false): array
35
    {
36
        return $this->deployApps([[
37
            'app' => $id,
38
            '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
     */
51
    public function deployApps(array $apps, $guestSpaceId = null, $revert = false): array
52
    {
53
        $options = ['json' => compact('apps', 'revert')];
54
55
        /** @var JsonStream $stream */
56
        $stream = $this->client
57
            ->post(KintoneApi::generateUrl('preview/app/deploy.json', $guestSpaceId), $options)
58
            ->getBody();
59
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
     */
71
    public function getDeployStatus($id, $guestSpaceId = null): array
72
    {
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
     */
84
    public function getDeployStatuses(array $ids, $guestSpaceId = null): array
85
    {
86
        $options = ['json' => ['apps' => $ids]];
87
88
        /** @var JsonStream $stream */
89
        $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
     * @param integer $threadId
103
     * @param integer $guestSpaceId
104
     * @return array
105
     */
106
    public function post($name, $spaceId = null, $threadId = null, $guestSpaceId = null): array
107
    {
108
        $options = ['json' => ['name' => $name]];
109
        if ($spaceId !== null) {
110
            $options['json']['space'] = $spaceId;
111
            $options['json']['thread'] = $threadId;
112
        }
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
     * https://cybozudev.zendesk.com/hc/ja/articles/204694170
125
     *
126
     * @param integer $id
127
     * @param integer $guestSpaceId
128
     * @param string $lang
129
     * @return array
130
     */
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
143
    /**
144
     * Get app form fields
145
     * https://cybozudev.zendesk.com/hc/ja/articles/204783170#anchor_getform_fields
146
     *
147
     * @param integer $id
148
     * @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
161
        return $stream->jsonSerialize();
162
    }
163
164
    /**
165
     * Get app form layout
166
     * 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
        $stream = $this->client
179
            ->get(KintoneApi::generateUrl('preview/app/form/layout.json', $guestSpaceId), $options)
180
            ->getBody();
181
182
        return $stream->jsonSerialize();
183
    }
184
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
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
197
198
        /** @var JsonStream $stream */
199
        $stream = $this->client
200
            ->get(KintoneApi::generateUrl('preview/app/views.json', $guestSpaceId), $options)
201
            ->getBody();
202
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
     */
215
    public function getAcl($id, $guestSpaceId = null, $lang = 'default'): array
216
    {
217
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
218
219
        /** @var JsonStream $stream */
220
        $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
     * @param integer $guestSpaceId
233
     * @param string $lang
234
     * @return array
235
     */
236
    public function getRecordAcl($id, $guestSpaceId = null, $lang = 'default'): array
237
    {
238
        $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
     * Get field acl
250
     * https://cybozudev.zendesk.com/hc/ja/articles/204791520
251
     *
252
     * @param integer $id
253
     * @param integer $guestSpaceId
254
     * @param string $lang
255
     * @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
     * https://cybozudev.zendesk.com/hc/ja/articles/204529824
272
     *
273
     * @param integer $id
274
     * @param integer $guestSpaceId
275
     * @return array
276
     */
277
    public function getCustomize($id, $guestSpaceId = null): array
278
    {
279
        $options = ['json' => ['app' => $id]];
280
281
        /** @var JsonStream $stream */
282
        $stream = $this->client
283
            ->get(KintoneApi::generateUrl('preview/app/customize.json', $guestSpaceId), $options)
284
            ->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
     */
298
    public function getStatus($id, $lang = 'ja', $guestSpaceId = null): array
299
    {
300
        $options = ['json' => ['app' => $id, 'lang' => $lang]];
301
302
        /** @var JsonStream $stream */
303
        $stream = $this->client
304
            ->get(KintoneApi::generateUrl('preview/app/status.json', $guestSpaceId), $options)
305
            ->getBody();
306
307
        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
     * @param integer $revision
321
     * @return array
322
     */
323
    public function putSettings($id, $name, $description, array $icon, $theme, $guestSpaceId = null, $revision = -1): array
324
    {
325
        $options = ['json' => [
326
            'app' => $id,
327
            'name' => $name,
328
            'description' => $description,
329
            'icon' => $icon,
330
            '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
     * Post form fields to preview app
344
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_addfields
345
     *
346
     * @param integer $id
347
     * @param array   $fields
348
     * @param integer $guestSpaceId
349
     * @param integer $revision
350
     * @return array
351
     */
352
    public function postFields($id, array $fields, $guestSpaceId = null, $revision = -1): array
353
    {
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
    }
367
368
    /**
369
     * Put form fields to preview app
370
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_changefields
371
     *
372
     * @param integer $id
373
     * @param array   $fields
374
     * @param integer $guestSpaceId
375
     * @param integer $revision
376
     * @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
            ->getBody();
390
391
        return $stream->jsonSerialize();
392
    }
393
394
    /**
395
     * Delete form fields to preview app
396
     * https://cybozudev.zendesk.com/hc/ja/articles/204529724#anchor_changeform_deletefields
397
     *
398
     * @param integer $id
399
     * @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
        /** @var JsonStream $stream */
413
        $stream = $this->client
414
            ->delete(KintoneApi::generateUrl('preview/app/form/fields.json', $guestSpaceId), $options)
415
            ->getBody();
416
417
        return $stream->jsonSerialize();
418
    }
419
420
    /**
421
     * Put form layout to preview app
422
     * 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
            'revision' => $revision
436
        ]];
437
438
        /** @var JsonStream $stream */
439
        $stream = $this->client
440
            ->put(KintoneApi::generateUrl('preview/app/form/layout.json', $guestSpaceId), $options)
441
            ->getBody();
442
443
        return $stream->jsonSerialize();
444
    }
445
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
        $options = ['json' => [
459
            'app' => $id,
460
            'views' => $views,
461
            'revision' => $revision
462
        ]];
463
464
        /** @var JsonStream $stream */
465
        $stream = $this->client
466
            ->put(KintoneApi::generateUrl('preview/app/views.json', $guestSpaceId), $options)
467
            ->getBody();
468
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
        $options = ['json' => [
485
            'app' => $id,
486
            'rights' => $rights,
487
            'revision' => $revision
488
        ]];
489
490
        /** @var JsonStream $stream */
491
        $stream = $this->client
492
            ->put(KintoneApi::generateUrl('preview/app/acl.json', $guestSpaceId), $options)
493
            ->getBody();
494
495
        return $stream->jsonSerialize();
496
    }
497
498
    /**
499
     * Put record acl to preview app
500
     * https://cybozudev.zendesk.com/hc/ja/articles/201941854
501
     *
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