Completed
Pull Request — master (#546)
by
unknown
05:32
created

Stats::pageSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
/**
13
 * Stats.php.
14
 *
15
 * @author    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\ShakeAround;
22
23
use EasyWeChat\Core\AbstractAPI;
24
25
/**
26
 * Class Stats.
27
 */
28
class Stats extends AbstractAPI
29
{
30
    const API_DEVICE = 'https://api.weixin.qq.com/shakearound/statistics/device';
31
    const API_DEVICE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/devicelist';
32
    const API_PAGE = 'https://api.weixin.qq.com/shakearound/statistics/page';
33
    const API_PAGE_LIST = 'https://api.weixin.qq.com/shakearound/statistics/pagelist';
34
35
    /**
36
     * Fetch statistics data by device_id.
37
     *
38
     * @param array $device_identifier
39
     * @param int   $begin_date (Unix timestamp)
40
     * @param int   $end_date (Unix timestamp)
41
     *
42
     * @return \EasyWeChat\Support\Collection
43
     */
44 View Code Duplication
    public function deviceSummary(array $device_identifier, $begin_date, $end_date)
45
    {
46
        $params = [
47
            'device_identifier' => $device_identifier,
48
            'begin_date' => $begin_date,
49
            'end_date' => $end_date,
50
        ];
51
52
        return $this->parseJSON('json', [self::API_DEVICE, $params]);
53
    }
54
55
    /**
56
     * Fetch all devices statistics data by date.
57
     *
58
     * @param int $timestamp
59
     * @param int $page_index
60
     *
61
     * @return \EasyWeChat\Support\Collection
62
     */
63 View Code Duplication
    public function batchDeviceSummary($timestamp, $page_index)
64
    {
65
        $params = [
66
            'date' => $timestamp,
67
            'page_index' => $page_index,
68
        ];
69
70
        return $this->parseJSON('json', [self::API_DEVICE_LIST, $params]);
71
    }
72
73
    /**
74
     * Fetch statistics data by page_id.
75
     *
76
     * @param int $page_id
77
     * @param int $begin_date (Unix timestamp)
78
     * @param int $end_date (Unix timestamp)
79
     *
80
     * @return \EasyWeChat\Support\Collection
81
     */
82 View Code Duplication
    public function pageSummary($page_id, $begin_date, $end_date)
83
    {
84
        $params = [
85
            'page_id' => $page_id,
86
            'begin_date' => $begin_date,
87
            'end_date' => $end_date,
88
        ];
89
        return $this->parseJSON('json', [self::API_PAGE, $params]);
90
    }
91
92
    /**
93
     * Fetch all pages statistics data by date.
94
     *
95
     * @param int $timestamp
96
     * @param int $page_index
97
     *
98
     * @return \EasyWeChat\Support\Collection
99
     */
100 View Code Duplication
    public function batchPageSummary($timestamp, $page_index)
101
    {
102
        $params = [
103
            'date' => $timestamp,
104
            'page_index' => $page_index,
105
        ];
106
107
        return $this->parseJSON('json', [self::API_PAGE_LIST, $params]);
108
    }
109
}
110