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 Record |
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
|
|
|
* Get record |
26
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/202331474#step1 |
27
|
|
|
* |
28
|
|
|
* @param integer $appId |
29
|
|
|
* @param integer $id |
30
|
|
|
* @param integer $guestSpaceId |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
2 |
|
public function get($appId, $id, $guestSpaceId = null): array |
34
|
|
|
{ |
35
|
2 |
|
$options = ['json' => ['app' => $appId, 'id' => $id]]; |
36
|
|
|
|
37
|
|
|
/** @var JsonStream $stream */ |
38
|
2 |
|
$stream = $this->client |
39
|
2 |
|
->get(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
40
|
2 |
|
->getBody(); |
41
|
|
|
|
42
|
2 |
|
return $stream->jsonSerialize()['record']; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Post record |
47
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/202166160#step1 |
48
|
|
|
* |
49
|
|
|
* @param integer $appId |
50
|
|
|
* @param array $record |
51
|
|
|
* @param integer $guestSpaceId |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
7 |
|
public function post($appId, array $record, $guestSpaceId = null): array |
55
|
|
|
{ |
56
|
7 |
|
$options = ['json' => ['app' => $appId, 'record' => $record]]; |
57
|
|
|
|
58
|
|
|
/** @var JsonStream $stream */ |
59
|
7 |
|
$stream = $this->client |
60
|
7 |
|
->post(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
61
|
7 |
|
->getBody(); |
62
|
|
|
|
63
|
7 |
|
return $stream->jsonSerialize(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Put record |
68
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/201941784#step1 |
69
|
|
|
* |
70
|
|
|
* @param integer $appId |
71
|
|
|
* @param integer $id |
72
|
|
|
* @param array $record |
73
|
|
|
* @param integer $guestSpaceId |
74
|
|
|
* @param integer $revision |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
1 |
|
public function put($appId, $id, array $record, $guestSpaceId = null, $revision = -1): array |
78
|
|
|
{ |
79
|
1 |
|
$options = ['json' => ['app' => $appId, 'id' => $id, 'revision' => $revision, 'record' => $record]]; |
80
|
|
|
|
81
|
|
|
/** @var JsonStream $stream */ |
82
|
1 |
|
$stream = $this->client |
83
|
1 |
|
->put(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
84
|
1 |
|
->getBody(); |
85
|
|
|
|
86
|
1 |
|
return $stream->jsonSerialize(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Delete record |
91
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/201941794 |
92
|
|
|
* |
93
|
|
|
* @param integer $appId |
94
|
|
|
* @param integer $id |
95
|
|
|
* @param integer $guestSpaceId |
96
|
|
|
* @param integer $revision |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
1 |
|
public function delete($appId, $id, $guestSpaceId = null, $revision = -1): array |
100
|
|
|
{ |
101
|
1 |
|
$options = ['json' => [ |
102
|
1 |
|
'app' => $appId, |
103
|
1 |
|
'ids' => [$id], |
104
|
1 |
|
'revisions' => [$revision] |
105
|
1 |
|
]]; |
106
|
|
|
|
107
|
|
|
/** @var JsonStream $stream */ |
108
|
1 |
|
$stream = $this->client |
109
|
1 |
|
->delete(KintoneApi::generateUrl('records.json', $guestSpaceId), $options) |
110
|
1 |
|
->getBody(); |
111
|
|
|
|
112
|
1 |
|
return $stream->jsonSerialize(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Put record status |
117
|
|
|
* https://cybozudev.zendesk.com/hc/ja/articles/204791550#anchor_changeRecordStatus |
118
|
|
|
* |
119
|
|
|
* @param integer $appId |
120
|
|
|
* @param integer $id |
121
|
|
|
* @param string $action |
122
|
|
|
* @param string $assignee |
123
|
|
|
* @param integer $guestSpaceId |
124
|
|
|
* @param integer $revision |
125
|
|
|
* @return array |
126
|
|
|
*/ |
127
|
1 |
|
public function putStatus($appId, $id, $action, $assignee = null, $guestSpaceId = null, $revision = -1): array |
128
|
|
|
{ |
129
|
1 |
|
$options = ['json' => [ |
130
|
1 |
|
'app' => $appId, |
131
|
1 |
|
'id' => $id, |
132
|
1 |
|
'action' => $action, |
133
|
1 |
|
'revision' => $revision |
134
|
1 |
|
]]; |
135
|
1 |
|
if ($assignee !== null) { |
136
|
1 |
|
$options['json']['assignee'] = $assignee; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** @var JsonStream $stream */ |
140
|
1 |
|
$stream = $this->client |
141
|
1 |
|
->put(KintoneApi::generateUrl('record/status.json', $guestSpaceId), $options) |
142
|
1 |
|
->getBody(); |
143
|
|
|
|
144
|
1 |
|
return $stream->jsonSerialize(); |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|