|
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
|
|
|
public function get($appId, $id, $guestSpaceId = null): array |
|
34
|
|
|
{ |
|
35
|
|
|
$options = ['json' => ['app' => $appId, 'id' => $id]]; |
|
36
|
|
|
|
|
37
|
|
|
/** @var JsonStream $stream */ |
|
38
|
|
|
$stream = $this->client |
|
39
|
|
|
->get(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
|
40
|
|
|
->getBody(); |
|
41
|
|
|
|
|
42
|
|
|
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
|
|
|
public function post($appId, array $record, $guestSpaceId = null): array |
|
55
|
|
|
{ |
|
56
|
|
|
$options = ['json' => ['app' => $appId, 'record' => $record]]; |
|
57
|
|
|
|
|
58
|
|
|
/** @var JsonStream $stream */ |
|
59
|
|
|
$stream = $this->client |
|
60
|
|
|
->post(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
|
61
|
|
|
->getBody(); |
|
62
|
|
|
|
|
63
|
|
|
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
|
|
|
public function put($appId, $id, array $record, $guestSpaceId = null, $revision = -1): array |
|
78
|
|
|
{ |
|
79
|
|
|
$options = ['json' => ['app' => $appId, 'id' => $id, 'revision' => $revision, 'record' => $record]]; |
|
80
|
|
|
|
|
81
|
|
|
/** @var JsonStream $stream */ |
|
82
|
|
|
$stream = $this->client |
|
83
|
|
|
->put(KintoneApi::generateUrl('record.json', $guestSpaceId), $options) |
|
84
|
|
|
->getBody(); |
|
85
|
|
|
|
|
86
|
|
|
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
|
|
|
public function delete($appId, $id, $guestSpaceId = null, $revision = -1): array |
|
100
|
|
|
{ |
|
101
|
|
|
$options = ['json' => [ |
|
102
|
|
|
'app' => $appId, |
|
103
|
|
|
'ids' => [$id], |
|
104
|
|
|
'revisions' => [$revision] |
|
105
|
|
|
]]; |
|
106
|
|
|
|
|
107
|
|
|
/** @var JsonStream $stream */ |
|
108
|
|
|
$stream = $this->client |
|
109
|
|
|
->delete(KintoneApi::generateUrl('records.json', $guestSpaceId), $options) |
|
110
|
|
|
->getBody(); |
|
111
|
|
|
|
|
112
|
|
|
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
|
|
|
public function putStatus($appId, $id, $action, $assignee = null, $guestSpaceId = null, $revision = -1): array |
|
128
|
|
|
{ |
|
129
|
|
|
$options = ['json' => [ |
|
130
|
|
|
'app' => $appId, |
|
131
|
|
|
'id' => $id, |
|
132
|
|
|
'action' => $action, |
|
133
|
|
|
'revision' => $revision |
|
134
|
|
|
]]; |
|
135
|
|
|
if ($assignee !== null) { |
|
136
|
|
|
$options['json']['assignee'] = $assignee; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** @var JsonStream $stream */ |
|
140
|
|
|
$stream = $this->client |
|
141
|
|
|
->put(KintoneApi::generateUrl('record/status.json', $guestSpaceId), $options) |
|
142
|
|
|
->getBody(); |
|
143
|
|
|
|
|
144
|
|
|
return $stream->jsonSerialize(); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|