Passed
Pull Request — master (#77)
by Yuichi
04:41 queued 02:24
created

UserOrganizations::postByCsv()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace CybozuHttp\Api\User;
4
5
use CybozuHttp\Client;
6
use CybozuHttp\Api\UserApi;
7
use CybozuHttp\Middleware\JsonStream;
8
9
/**
10
 * @author ochi51 <[email protected]>
11
 */
12
class UserOrganizations
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18
19
    /**
20
     * @var Csv
21
     */
22
    private $csv;
23
24
    public function __construct(Client $client, Csv $csv)
25
    {
26
        $this->client = $client;
27
        $this->csv = $csv;
28
    }
29
30
    /**
31
     * Get organizations and titles of user
32
     * https://cybozudev.zendesk.com/hc/ja/articles/202124774#step2
33
     *
34
     * @param string $code
35
     * @return array
36
     */
37
    public function get($code): array
38
    {
39
        $options = ['json' => ['code' => $code]];
40
41
        /** @var JsonStream $stream */
42
        $stream = $this->client
43
            ->get(UserApi::generateUrl('user/organizations.json'), $options)
44
            ->getBody();
45
46
        return $stream->jsonSerialize()['organizationTitles'];
47
    }
48
49
    /**
50
     * Get userOrganizations by csv
51
     * https://cybozudev.zendesk.com/hc/ja/articles/202124774#step1
52
     *
53
     * @return string
54
     * @throws \InvalidArgumentException
55
     */
56
    public function getByCsv(): string
57
    {
58
        return $this->csv->get('userOrganizations');
59
    }
60
61
    /**
62
     * Post userOrganizations by csv
63
     * https://cybozudev.zendesk.com/hc/ja/articles/202362860
64
     *
65
     * @param $filename
66
     * @return int
67
     * @throws \InvalidArgumentException
68
     */
69
    public function postByCsv($filename): int
70
    {
71
        return $this->csv->post('userOrganizations', $filename);
72
    }
73
}
74