Completed
Push — master ( 5ddcc0...9e0ead )
by Carlos
42s
created

POI   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 87
ccs 19
cts 19
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A lists() 0 9 1
A create() 0 8 1
A update() 0 10 1
A delete() 0 6 1
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
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\POI;
22
23
use EasyWeChat\Core\AbstractAPI;
24
25
/**
26
 * Class POI.
27
 */
28
class POI extends AbstractAPI
29
{
30
    const API_CREATE = 'http://api.weixin.qq.com/cgi-bin/poi/addpoi';
31
    const API_GET = 'http://api.weixin.qq.com/cgi-bin/poi/getpoi';
32
    const API_LIST = 'http://api.weixin.qq.com/cgi-bin/poi/getpoilist';
33
    const API_UPDATE = 'http://api.weixin.qq.com/cgi-bin/poi/updatepoi';
34
    const API_DELETE = 'http://api.weixin.qq.com/cgi-bin/poi/delpoi';
35
36
    /**
37
     * Get POI by ID.
38
     *
39
     * @param int $poiId
40
     *
41
     * @return \EasyWeChat\Support\Collection
42
     */
43 1
    public function get($poiId)
44
    {
45 1
        return $this->parseJSON('json', [self::API_GET, ['poi_id' => $poiId]]);
46
    }
47
48
    /**
49
     * List POI.
50
     *
51
     * @param int $offset
52
     * @param int $limit
53
     *
54
     * @return \EasyWeChat\Support\Collection
55
     */
56 1
    public function lists($offset = 0, $limit = 10)
57
    {
58
        $params = [
59 1
                   'begin' => $offset,
60 1
                   'limit' => $limit,
61 1
                  ];
62
63 1
        return $this->parseJSON('json', [self::API_LIST, $params]);
64
    }
65
66
    /**
67
     * Create a POI.
68
     *
69
     * @param array $data
70
     *
71
     * @return bool
72
     */
73 1
    public function create(array $data)
74
    {
75
        $params = [
76 1
                   'business' => ['base_info' => $data],
77 1
                  ];
78
79 1
        return $this->parseJSON('json', [self::API_CREATE, $params]);
80
    }
81
82
    /**
83
     * Update a POI.
84
     *
85
     * @param int   $poiId
86
     * @param array $data
87
     *
88
     * @return bool
89
     */
90 1
    public function update($poiId, array $data)
91
    {
92 1
        $data = array_merge($data, ['poi_id' => $poiId]);
93
94
        $params = [
95 1
                   'business' => ['base_info' => $data],
96 1
                  ];
97
98 1
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
99
    }
100
101
    /**
102
     * Delete a POI.
103
     *
104
     * @param int $poiId
105
     *
106
     * @return bool
107
     */
108 1
    public function delete($poiId)
109
    {
110 1
        $params = ['poi_id' => $poiId];
111
112 1
        return $this->parseJSON('json', [self::API_DELETE, $params]);
113
    }
114
}
115