Completed
Push — master ( 2144bf...4c4f9b )
by
unknown
21:02 queued 36s
created

ArgusManager::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
namespace Qiniu\Storage;
3
4
use Qiniu\Auth;
5
use Qiniu\Config;
6
use Qiniu\Zone;
7
use Qiniu\Http\Client;
8
use Qiniu\Http\Error;
9
10
/**
11
 * 主要涉及了鉴黄接口的实现,具体的接口规格可以参考
12
 *
13
 * @link https://developer.qiniu.com/dora/manual/3674/kodo-product-introduction
14
 */
15
final class ArgusManager
16
{
17
    private $auth;
18
    private $config;
19
20
    public function __construct(Auth $auth, Config $config = null)
21
    {
22
        $this->auth = $auth;
23
        if ($config == null) {
24
            $this->config = new Config();
25
        } else {
26
            $this->config = $config;
27
        }
28
    }
29
30
    /**
31
     * 视频鉴黄
32
     *
33
     * @param $body     body信息
34
     * @param $vid      videoID
35
     *
36
     * @return mixed      成功返回NULL,失败返回对象Qiniu\Http\Error
37
     * @link  https://developer.qiniu.com/dora/manual/4258/video-pulp
38
     */
39
    public function pulpVideo($body, $vid)
40
    {
41
        $path = '/v1/video/' . $vid;
42
        
43
        return $this->arPost($path, $body);
44
    }
45
46
    private function getArHost()
47
    {
48
        $scheme = "http://";
49
        if ($this->config->useHTTPS == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
50
            $scheme = "https://";
51
        }
52
        return $scheme . Config::ARGUS_HOST;
53
    }
54
55
    private function arPost($path, $body = null)
56
    {
57
        $url = $this->getArHost() . $path;
58
        return $this->post($url, $body);
59
    }
60
61
    private function post($url, $body)
62
    {
63
        $headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
64
        $headers['Content-Type']='application/json';
65
        $ret = Client::post($url, $body, $headers);
66
        if (!$ret->ok()) {
67
            print($ret->statusCode);
68
            return array(null, new Error($url, $ret));
69
        }
70
        $r = ($ret->body === null) ? array() : $ret->json();
71
        return array($r, null);
72
    }
73
}
74