Passed
Push — master ( aec68f...df9c3d )
by Carlos
02:44
created

POI::createAndGetId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
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
     * Get POI supported categories.
40
     *
41
     * @return \EasyWeChat\Support\Collection
42
     */
43 1
    public function getCategories()
44
    {
45 1
        return $this->parseJSON('get', [self::API_GET_CATEGORIES]);
46
    }
47
48
    /**
49
     * Get POI by ID.
50
     *
51
     * @param int $poiId
52
     *
53
     * @return \EasyWeChat\Support\Collection
54
     */
55 1
    public function get($poiId)
56
    {
57 1
        return $this->parseJSON('json', [self::API_GET, ['poi_id' => $poiId]]);
58
    }
59
60
    /**
61
     * List POI.
62
     *
63
     * @param int $offset
64
     * @param int $limit
65
     *
66
     * @return \EasyWeChat\Support\Collection
67
     */
68 1
    public function lists($offset = 0, $limit = 10)
69
    {
70
        $params = [
71 1
                   'begin' => $offset,
72 1
                   'limit' => $limit,
73 1
                  ];
74
75 1
        return $this->parseJSON('json', [self::API_LIST, $params]);
76
    }
77
78
    /**
79
     * Create a POI.
80
     *
81
     * @param array $data
82
     *
83
     * @return bool
84
     */
85 1
    public function create(array $data)
86
    {
87
        $params = [
88 1
                   'business' => ['base_info' => $data],
89 1
                  ];
90
91 1
        return $this->parseJSON('json', [self::API_CREATE, $params]);
92
    }
93
94
    /**
95
     * @param array $data
96
     *
97
     * @return int
98
     */
99
    public function createAndGetId(array $data)
100
    {
101
        return $this->create($data)['poi_id'];
102
    }
103
104
    /**
105
     * Update a POI.
106
     *
107
     * @param int   $poiId
108
     * @param array $data
109
     *
110
     * @return bool
111
     */
112 1
    public function update($poiId, array $data)
113
    {
114 1
        $data = array_merge($data, ['poi_id' => $poiId]);
115
116
        $params = [
117 1
                   'business' => ['base_info' => $data],
118 1
                  ];
119
120 1
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
121
    }
122
123
    /**
124
     * Delete a POI.
125
     *
126
     * @param int $poiId
127
     *
128
     * @return bool
129
     */
130 1
    public function delete($poiId)
131
    {
132 1
        $params = ['poi_id' => $poiId];
133
134 1
        return $this->parseJSON('json', [self::API_DELETE, $params]);
135
    }
136
}
137