GetFriendsOnlineStatusRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parseResponse() 0 17 4
1
<?php
2
/*
3
 * This file is part of the slince/smartqq package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\SmartQQ\Request;
12
13
use Slince\SmartQQ\Credential;
14
use Slince\SmartQQ\Entity\OnlineStatus;
15
use Slince\SmartQQ\EntityCollection;
16
use Slince\SmartQQ\EntityFactory;
17
use GuzzleHttp\Psr7\Response;
18
use Slince\SmartQQ\Exception\ResponseException;
19
20
class GetFriendsOnlineStatusRequest extends Request
21
{
22
    protected $uri = 'http://d1.web2.qq.com/channel/get_online_buddies2?vfwebqq={vfwebqq}&clientid=53999199&psessionid={psessionid}&t=0.1';
23
24
    protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2';
25
26
    public function __construct(Credential $credential)
27
    {
28
        $this->setTokens([
29
            'vfwebqq' => $credential->getVfWebQQ(),
30
            'psessionid' => $credential->getPSessionId(),
31
        ]);
32
    }
33
34
    /**
35
     * 解析响应数据.
36
     *
37
     * @param Response $response
38
     *
39
     * @return EntityCollection
40
     */
41
    public static function parseResponse(Response $response)
42
    {
43
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
44
        if ($jsonData && 0 == $jsonData['retcode']) {
45
            $onlineStatuses = [];
46
            foreach ($jsonData['result'] as $status) {
47
                $onlineStatuses[] = EntityFactory::createEntity(OnlineStatus::class, [
48
                    'clientType' => $status['client_type'],
49
                    'uin' => $status['uin'],
50
                    'status' => $status['status'],
51
                ]);
52
            }
53
54
            return new EntityCollection($onlineStatuses);
55
        }
56
        throw new ResponseException($jsonData['retcode'], $response);
57
    }
58
}
59