Menu::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace EntWeChat\Menu;
4
5
use EntWeChat\Core\AbstractAPI;
6
7
/**
8
 * Class Menu.
9
 */
10
class Menu extends AbstractAPI
11
{
12
    const API_CREATE = 'https://qyapi.weixin.qq.com/cgi-bin/menu/create';
13
    const API_GET = 'https://qyapi.weixin.qq.com/cgi-bin/menu/get';
14
    const API_DELETE = 'https://qyapi.weixin.qq.com/cgi-bin/menu/delete';
15
16
    /**
17
     * Get all menus.
18
     *
19
     * @return \EntWeChat\Support\Collection
20
     */
21
    public function all($agentId)
22
    {
23
        return $this->parseJSON('get', [self::API_GET, ['agentid' => $agentId]]);
24
    }
25
26
    /**
27
     * Add menu.
28
     *
29
     * @param int   $agentId
30
     * @param array $buttons
31
     *
32
     * @return bool
33
     */
34
    public function add($agentId, array $buttons)
35
    {
36
        return $this->parseJSON('json', [self::API_CREATE, ['button' => $buttons], JSON_UNESCAPED_UNICODE, ['agentid' => $agentId]]);
37
    }
38
39
    /**
40
     * Destroy menu.
41
     *
42
     * @param int $agentId
43
     *
44
     * @return bool
45
     */
46
    public function destroy($agentId)
47
    {
48
        return $this->parseJSON('get', [self::API_DELETE, ['agentid' => $agentId]]);
49
    }
50
}
51