Completed
Push — comment-api ( 9d46a8 )
by Yuichi
09:33
created

KintoneApi::comment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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