Completed
Pull Request — master (#631)
by
unknown
03:10
created

POI::lists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 1
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
 * POI.php.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @see      https://github.com/overtrue
19
 * @see      http://overtrue.me
20
 */
21
22
namespace EasyWeChat\POI;
23
24
use EasyWeChat\Core\AbstractAPI;
25
26
/**
27
 * Class POI.
28
 */
29
class POI extends AbstractAPI
30
{
31
    const API_CREATE = 'http://api.weixin.qq.com/cgi-bin/poi/addpoi';
32
    const API_GET = 'http://api.weixin.qq.com/cgi-bin/poi/getpoi';
33
    const API_LIST = 'http://api.weixin.qq.com/cgi-bin/poi/getpoilist';
34
    const API_UPDATE = 'http://api.weixin.qq.com/cgi-bin/poi/updatepoi';
35
    const API_DELETE = 'http://api.weixin.qq.com/cgi-bin/poi/delpoi';
36
    const API_GET_CATEGORIES = 'http://api.weixin.qq.com/cgi-bin/poi/getwxcategory';
37
38
39
    /**
40
     * Get POI supported categories.
41
     *
42
     * @return \EasyWeChat\Support\Collection
43
     */
44 1
    public function getCategories()
45
    {
46 1
        return $this->parseJSON('get', [self::API_GET_CATEGORIES]);
47
    }
48
49
    /**
50
     * Get POI by ID.
51
     *
52
     * @param int $poiId
53
     *
54
     * @return \EasyWeChat\Support\Collection
55
     */
56 1
    public function get($poiId)
57
    {
58 1
        return $this->parseJSON('json', [self::API_GET, ['poi_id' => $poiId]]);
59
    }
60
61
    /**
62
     * List POI.
63
     *
64
     * @param int $offset
65
     * @param int $limit
66
     *
67
     * @return \EasyWeChat\Support\Collection
68
     */
69 1
    public function lists($offset = 0, $limit = 10)
70
    {
71
        $params = [
72 1
                   'begin' => $offset,
73 1
                   'limit' => $limit,
74 1
                  ];
75
76 1
        return $this->parseJSON('json', [self::API_LIST, $params]);
77
    }
78
79
    /**
80
     * Create a POI.
81
     *
82
     * @param array $data
83
     *
84
     * @return bool
85
     */
86 1
    public function create(array $data)
87
    {
88
        $params = [
89 1
                   'business' => ['base_info' => $data],
90 1
                  ];
91
92 1
        return $this->parseJSON('json', [self::API_CREATE, $params]);
93
    }
94
95
    /**
96
     * Update a POI.
97
     *
98
     * @param int   $poiId
99
     * @param array $data
100
     *
101
     * @return bool
102
     */
103 1
    public function update($poiId, array $data)
104
    {
105 1
        $data = array_merge($data, ['poi_id' => $poiId]);
106
107
        $params = [
108 1
                   'business' => ['base_info' => $data],
109 1
                  ];
110
111 1
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
112
    }
113
114
    /**
115
     * Delete a POI.
116
     *
117
     * @param int $poiId
118
     *
119
     * @return bool
120
     */
121 1
    public function delete($poiId)
122
    {
123 1
        $params = ['poi_id' => $poiId];
124
125 1
        return $this->parseJSON('json', [self::API_DELETE, $params]);
126
    }
127
}
128