Completed
Push — 0.1 ( 039bdb )
by Yuichi
24s queued 22s
created

Thread   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 66
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A put() 0 14 3
A comment() 0 16 1
1
<?php
2
3
namespace CybozuHttp\Api\Kintone;
4
5
use CybozuHttp\Client;
6
use CybozuHttp\Api\KintoneApi;
7
8
/**
9
 * @author ochi51 <[email protected]>
10
 */
11
class Thread
12
{
13
    /**
14
     * @var Client
15
     */
16
    private $client;
17
18 2
    public function __construct(Client $client)
19
    {
20 2
        $this->client = $client;
21 2
    }
22
23
    /**
24
     * Put thread
25
     * https://cybozudev.zendesk.com/hc/ja/articles/201941894
26
     *
27
     * @param integer $id
28
     * @param string  $name
29
     * @param string  $body
30
     * @param integer $guestSpaceId
31
     * @return array
32
     */
33 1
    public function put($id, $name = null, $body = null, $guestSpaceId = null)
34
    {
35 1
        $options = ['json' => ['id' => $id]];
36 1
        if ($name !== null) {
37 1
            $options['json']['name'] = $name;
38 1
        }
39 1
        if ($body !== null) {
40 1
            $options['json']['body'] = $body;
41 1
        }
42
43 1
        return $this->client
44 1
            ->put(KintoneApi::generateUrl('space/thread.json', $guestSpaceId), $options)
45 1
            ->json();
46
    }
47
48
    /**
49
     * Post thread comment
50
     * https://cybozudev.zendesk.com/hc/ja/articles/209732306
51
     *
52
     * @param int $spaceId
53
     * @param int $threadId
54
     * @param string $comment
55
     * @param array $mentions
56
     * @param array $files
57
     * @param int $guestSpaceId
58
     * @return array
59
     */
60 1
    public function comment($spaceId, $threadId, $comment, $mentions = [], $files = [], $guestSpaceId = null)
61
    {
62
        $options = ['json' => [
63 1
            'space'  => $spaceId,
64 1
            'thread' => $threadId,
65
            'comment'  => [
66 1
                'text' => $comment,
67 1
                'mentions' => $mentions,
68
                'files' => $files
69 1
            ],
70 1
        ]];
71
72 1
        return $this->client
73 1
            ->post(KintoneApi::generateUrl('space/thread/comment.json', $guestSpaceId), $options)
74 1
            ->json();
75
    }
76
}