Passed
Push — master ( d0634e...13c37e )
by Yuichi
10:21 queued 22s
created

Comment::post()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 17
ccs 13
cts 13
cp 1
crap 1
rs 9.9332
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 Comment
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
     * Post record comment
26
     * https://cybozudev.zendesk.com/hc/ja/articles/209758903
27
     *
28
     * @param integer $appId
29
     * @param integer $record
30
     * @param string  $comment
31
     * @param array   $mentions
32
     * @param integer $guestSpaceId
33
     * @return array
34
     */
35 2
    public function post($appId, $record, $comment, array $mentions = [], $guestSpaceId = null): array
36
    {
37 2
        $options = ['json' => [
38 2
            'app' => $appId,
39 2
            'record' => $record,
40 2
            'comment' => [
41 2
                'text' => $comment,
42 2
                'mentions' => $mentions
43 2
            ]
44 2
        ]];
45
46
        /** @var JsonStream $stream */
47 2
        $stream = $this->client
48 2
            ->post(KintoneApi::generateUrl('record/comment.json', $guestSpaceId), $options)
49 2
            ->getBody();
50
51 2
        return $stream->jsonSerialize();
52
    }
53
54
    /**
55
     * Delete record comment
56
     * https://cybozudev.zendesk.com/hc/ja/articles/209758703
57
     *
58
     * @param integer $appId
59
     * @param integer $recordId
60
     * @param integer $id
61
     * @param integer $guestSpaceId
62
     * @return array
63
     */
64 2
    public function delete($appId, $recordId, $id, $guestSpaceId = null): array
65
    {
66 2
        $options = ['json' => [
67 2
            'app' => $appId,
68 2
            'record' => $recordId,
69 2
            'comment' => $id
70 2
        ]];
71
72
        /** @var JsonStream $stream */
73 2
        $stream = $this->client
74 2
            ->delete(KintoneApi::generateUrl('record/comment.json', $guestSpaceId), $options)
75 2
            ->getBody();
76
77 2
        return $stream->jsonSerialize();
78
    }
79
}
80