Client::updateFriend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
3
namespace EasyIM\TencentIM\Sns;
4
5
use EasyIM\Kernel\BaseClient;
6
use EasyIM\Kernel\Support\Arr;
7
use EasyIM\TencentIM\Kernel\Constant\SnsConstant;
8
use EasyIM\TencentIM\Sns\Parameter\AddFriendParameter;
9
use EasyIM\TencentIM\Sns\Parameter\ImportFriendParameter;
10
use EasyIM\TencentIM\Sns\Parameter\UpdateFriendParameter;
11
12
/**
13
 * Class Client
14
 *
15
 * @package EasyIM\TencentIM\Sns
16
 * @author  longing <[email protected]>
17
 */
18
class Client extends BaseClient
19
{
20
    /**
21
     * get Friends.
22
     *
23
     * @param string $fromAccount
24
     * @param array  $toAccount
25
     * @param array  $tagList
26
     *
27
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
28
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
29
     * @throws \GuzzleHttp\Exception\GuzzleException
30
     */
31
    public function getFriends(string $fromAccount, array $toAccount, array $tagList)
32
    {
33
        $params = [
34
            'From_Account' => $fromAccount,
35
            'To_Account' => $toAccount,
36
            'TagList' => $tagList,
37
        ];
38
39
        return $this->httpPostJson('sns/friend_get_list', $params);
40
    }
41
42
43
    /**
44
     * get Friend List.
45
     *
46
     * @param string   $fromAccount
47
     * @param int      $startIndex
48
     * @param int|null $standardSequence
49
     * @param int|null $customSequence
50
     *
51
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
52
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
53
     * @throws \GuzzleHttp\Exception\GuzzleException
54
     */
55
    public function getFriendList(string $fromAccount, int $startIndex = 0, int $standardSequence = null, int $customSequence = null)
56
    {
57
        $params = [
58
            'From_Account' => $fromAccount,
59
            'StartIndex' => $startIndex,
60
        ];
61
62
        Arr::setNotNullValue($params, 'StandardSequence', $standardSequence);
63
        Arr::setNotNullValue($params, 'CustomSequence', $customSequence);
64
65
        return $this->httpPostJson('sns/friend_get', $params);
66
    }
67
68
    /**
69
     * check Friend.
70
     *
71
     * @param string $fromAccount
72
     * @param array  $toAccount
73
     * @param string $checkType
74
     *
75
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
76
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
77
     * @throws \GuzzleHttp\Exception\GuzzleException
78
     */
79
    public function checkFriend(string $fromAccount, array $toAccount, string $checkType = SnsConstant::CHECK_RESULT_TYPE_BOTH)
80
    {
81
        $params = [
82
            'From_Account' => $fromAccount,
83
            'To_Account' => $toAccount,
84
            'CheckType' => $checkType
85
        ];
86
87
        return $this->httpPostJson('sns/friend_check', $params);
88
    }
89
90
    /**
91
     * delete All Friend.
92
     *
93
     * @param string      $fromAccount
94
     * @param string $deleteType
95
     *
96
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
97
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
98
     * @throws \GuzzleHttp\Exception\GuzzleException
99
     */
100
    public function deleteAllFriend(string $fromAccount, string $deleteType = SnsConstant::DELETE_TYPE_BOTH)
101
    {
102
        $params = [
103
            'From_Account' => $fromAccount,
104
            'DeleteType' => $deleteType
105
        ];
106
107
        return $this->httpPostJson('sns/friend_delete_all', $params);
108
    }
109
110
111
    /**
112
     * delete Friend.
113
     *
114
     * @param string      $fromAccount
115
     * @param array       $toAccount
116
     * @param string      $deleteType
117
     *
118
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
119
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
120
     * @throws \GuzzleHttp\Exception\GuzzleException
121
     */
122
    public function deleteFriend(string $fromAccount, array $toAccount, string $deleteType = SnsConstant::DELETE_TYPE_BOTH)
123
    {
124
        $params = [
125
            'From_Account' => $fromAccount,
126
            'To_Account' => $toAccount,
127
            'DeleteType' => $deleteType
128
        ];
129
130
        return $this->httpPostJson('sns/friend_delete', $params);
131
    }
132
133
134
    /**
135
     * update Friend.
136
     *
137
     * @param string                $fromAccount
138
     * @param UpdateFriendParameter ...$updateFriendParameters
139
     *
140
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
141
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
142
     * @throws \GuzzleHttp\Exception\GuzzleException
143
     */
144
    public function updateFriend(string $fromAccount, UpdateFriendParameter ...$updateFriendParameters)
145
    {
146
        $params = [
147
            'From_Account' => $fromAccount,
148
            'UpdateItem' => \parameterList(...$updateFriendParameters)()
149
        ];
150
151
        return $this->httpPostJson('sns/friend_update', $params);
152
    }
153
154
155
    /**
156
     * import Friend.
157
     *
158
     * @param string                $fromAccount
159
     * @param ImportFriendParameter ...$importFriendParameters
160
     *
161
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
162
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
163
     * @throws \GuzzleHttp\Exception\GuzzleException
164
     */
165
    public function importFriend(string $fromAccount, ImportFriendParameter ...$importFriendParameters)
166
    {
167
        $params = [
168
            'From_Account' => $fromAccount,
169
            'AddFriendItem' => \parameterList(...$importFriendParameters)()
170
        ];
171
172
        return $this->httpPostJson('sns/friend_import', $params);
173
    }
174
175
176
    /**
177
     * add Friend.
178
     *
179
     * @param string               $fromAccount
180
     * @param string               $addType
181
     * @param int                  $forceAddFlags
182
     * @param AddFriendParameter   $addFriendParameters
183
     *
184
     * @return array|\EasyIM\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
185
     * @throws \EasyIM\Kernel\Exceptions\InvalidConfigException
186
     * @throws \GuzzleHttp\Exception\GuzzleException
187
     */
188
    public function addFriend(
189
        string $fromAccount,
190
        string $addType = SnsConstant::ADD_TYPE_BOTH,
191
        int $forceAddFlags = SnsConstant::NORMAL_ADD_FRIEND,
192
        AddFriendParameter ...$addFriendParameters
193
    ) {
194
        $params = [
195
            'From_Account' => $fromAccount,
196
            'AddType' => $addType,
197
            'ForceAddFlags' => $forceAddFlags,
198
            'AddFriendItem' => \parameterList(...$addFriendParameters)()
199
        ];
200
201
        return $this->httpPostJson('sns/friend_add', $params);
202
    }
203
}
204