Completed
Pull Request — master (#1477)
by Carlos
03:05
created

Client::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 4
dl 0
loc 7
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
namespace EasyWeChat\MiniProgram\NearbyPoi;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author joyeekk <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * Add nearby poi.
26
     *
27
     * @param string $name
28
     * @param string $credential
29
     * @param string $address
30
     * @param string $proofMaterial
31
     *
32
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
33
     */
34
    public function add(string $name, string $credential, string $address, string $proofMaterial = null)
35
    {
36
        return $this->httpPostJson('wxa/addnearbypoi', [
37
            'related_name' => $name,
38
            'related_credential' => $credential,
39
            'related_address' => $address,
40
            'related_proof_material' => $proofMaterial,
41
        ]);
42
    }
43
44
    /**
45
     * Delete nearby poi.
46
     *
47
     * @param string $poiId
48
     *
49
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
50
     */
51
    public function delete(string $poiId)
52
    {
53
        return $this->httpPostJson('wxa/delnearbypoi', [
54
            'poi_id' => $poiId,
55
        ]);
56
    }
57
58
    /**
59
     * Get nearby poi list.
60
     *
61
     * @param int $page
62
     * @param int $pageRows
63
     *
64
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
65
     */
66
    public function list(int $page, int $pageRows)
67
    {
68
        return $this->httpGet('wxa/getnearbypoilist', [
69
            'page' => $page,
70
            'page_rows' => $pageRows,
71
        ]);
72
    }
73
74
    /**
75
     * Set nearby poi show status.
76
     *
77
     * @param string $poiId
78
     * @param int    $status
79
     *
80
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
81
     */
82
    public function setVisibility(string $poiId, int $status)
83
    {
84
        if (!in_array($status, [0, 1], true)) {
85
            throw new InvalidArgumentException('status should be 0 or 1.');
86
        }
87
88
        return $this->httpPostJson('wxa/setnearbypoishowstatus', [
89
            'poi_id' => $poiId,
90
            'status' => $status,
91
        ]);
92
    }
93
}
94