Completed
Push — multiple-files ( 3118de...d64477 )
by Yuichi
04:15
created

Comment   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 14.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 68
ccs 3
cts 21
cp 0.1429
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A post() 0 18 1
A delete() 0 15 1
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 1
    }
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
    public function post($appId, $record, $comment, array $mentions = [], $guestSpaceId = null)
36
    {
37
        $options = ['json' => [
38
            'app' => $appId,
39
            'record' => $record,
40
            'comment' => [
41
                'text' => $comment,
42
                'mentions' => $mentions
43
            ]
44
        ]];
45
46
        /** @var JsonStream $stream */
47
        $stream = $this->client
48
            ->post(KintoneApi::generateUrl('record/comment.json', $guestSpaceId), $options)
49
            ->getBody();
50
51
        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
    public function delete($appId, $recordId, $id, $guestSpaceId = null)
65
    {
66
        $options = ['json' => [
67
            'app' => $appId,
68
            'record' => $recordId,
69
            'comment' => $id
70
        ]];
71
72
        /** @var JsonStream $stream */
73
        $stream = $this->client
74
            ->delete(KintoneApi::generateUrl('record/comment.json', $guestSpaceId), $options)
75
            ->getBody();
76
77
        return $stream->jsonSerialize();
78
    }
79
}