Completed
Pull Request — master (#194)
by r
05:53
created

LogManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
namespace Qiniu\Cdn;
3
4
use Qiniu\Auth;
5
use Qiniu\Config;
6
use Qiniu\Http\Client;
7
use Qiniu\Http\Error;
8
9
/**
10
 * 主要涉及了CDN 日志的列取
11
 *
12
 * @link http://developer.qiniu.com/article/fusion/api/log.html 
13
 */
14
final class LogManager
15
{
16
    private $auth;
17
18
    public function __construct(Auth $auth)
19
    {
20
        $this->auth = $auth;
21
    }
22
23
    function list_logs($domains, $day)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
    {
25
26
    	if (empty($day) || empty($domains)) {
27
            return;
28
    	}
29
30
        $domains = join(';', $domains);
31
        $body = array('day' => $day, 'domains' => $domains);
32
        $body = json_encode($body);
33
34
    	return $this->post(Config::FUSION_HOST . '/v2/tune/log/list', $body);
35
    }
36
37
    private function post($url, $body)
38
    {
39
        $headers = $this->auth->authorization($url, $body, 'application/json');
40
        $headers['Content-Type'] = 'application/json';
41
        $ret = Client::post($url, $body, $headers);
42
        if (!$ret->ok()) {
43
            return array(null, new Error($url, $ret));
44
        }
45
        $r = ($ret->body === null) ? array() : $ret->json();
46
        return array($r, null);
47
    }
48
}
49