Completed
Push — master ( 058da3...8d02ae )
by Carlos
05:22 queued 02:18
created

Page::pagination()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
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
 * Page.php.
14
 *
15
 * @author    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @see       https://github.com/overtrue
19
 * @see       http://overtrue.me
20
 */
21
22
namespace EasyWeChat\ShakeAround;
23
24
use EasyWeChat\Core\AbstractAPI;
25
26
/**
27
 * Class Page.
28
 */
29
class Page extends AbstractAPI
30
{
31
    const API_ADD = 'https://api.weixin.qq.com/shakearound/page/add';
32
    const API_UPDATE = 'https://api.weixin.qq.com/shakearound/page/update';
33
    const API_SEARCH = 'https://api.weixin.qq.com/shakearound/page/search';
34
    const API_DELETE = 'https://api.weixin.qq.com/shakearound/page/delete';
35
    const API_RELATION_SEARCH = 'https://api.weixin.qq.com/shakearound/relation/search';
36
37
    /**
38
     * Add a page.
39
     *
40
     * @param string $title
41
     * @param string $description
42
     * @param string $pageUrl
43
     * @param string $iconUrl
44
     * @param string $comment
45
     *
46
     * @return \EasyWeChat\Support\Collection
47
     */
48 1 View Code Duplication
    public function add($title, $description, $pageUrl, $iconUrl, $comment = '')
49
    {
50
        $params = [
51 1
            'title' => $title,
52 1
            'description' => $description,
53 1
            'page_url' => $pageUrl,
54 1
            'icon_url' => $iconUrl,
55 1
        ];
56 1
        if ($comment !== '') {
57 1
            $params['comment'] = $comment;
58 1
        }
59
60 1
        return $this->parseJSON('json', [self::API_ADD, $params]);
61
    }
62
63
    /**
64
     * update a page info.
65
     *
66
     * @param int    $pageId
67
     * @param string $title
68
     * @param string $description
69
     * @param string $pageUrl
70
     * @param string $iconUrl
71
     * @param string $comment
72
     *
73
     * @return \EasyWeChat\Support\Collection
74
     */
75 1 View Code Duplication
    public function update($pageId, $title, $description, $pageUrl, $iconUrl, $comment = '')
76
    {
77
        $params = [
78 1
            'page_id' => intval($pageId),
79 1
            'title' => $title,
80 1
            'description' => $description,
81 1
            'page_url' => $pageUrl,
82 1
            'icon_url' => $iconUrl,
83 1
        ];
84 1
        if ($comment !== '') {
85 1
            $params['comment'] = $comment;
86 1
        }
87
88 1
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
89
    }
90
91
    /**
92
     * Fetch batch of pages by pageIds.
93
     *
94
     * @param array $pageIds
95
     *
96
     * @return \EasyWeChat\Support\Collection
97
     */
98 1 View Code Duplication
    public function fetchByIds(array $pageIds)
99
    {
100
        $params = [
101 1
            'type' => 1,
102 1
            'page_ids' => $pageIds,
103 1
        ];
104
105 1
        return $this->parseJSON('json', [self::API_SEARCH, $params]);
106
    }
107
108
    /**
109
     * Pagination to fetch batch of pages.
110
     *
111
     * @param int $begin
112
     * @param int $count
113
     *
114
     * @return \EasyWeChat\Support\Collection
115
     */
116 1
    public function pagination($begin, $count)
117
    {
118
        $params = [
119 1
            'type' => 2,
120 1
            'begin' => intval($begin),
121 1
            'count' => intval($count),
122 1
        ];
123
124 1
        return $this->parseJSON('json', [self::API_SEARCH, $params]);
125
    }
126
127
    /**
128
     * delete a page.
129
     *
130
     * @param int $pageId
131
     *
132
     * @return \EasyWeChat\Support\Collection
133
     */
134 1
    public function delete($pageId)
135
    {
136
        $params = [
137 1
            'page_id' => intval($pageId),
138 1
        ];
139
140 1
        return $this->parseJSON('json', [self::API_DELETE, $params]);
141
    }
142
}
143