Completed
Push — master ( e6b198...e30f90 )
by Messense
11:09 queued 10:06
created

WeChatMenu.update()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.2963
Metric Value
cc 1
dl 0
loc 3
ccs 1
cts 3
cp 0.3333
crap 1.2963
rs 10
1
# -*- coding: utf-8 -*-
2 10
from __future__ import absolute_import, unicode_literals
3 10
from wechatpy.client.api.base import BaseWeChatAPI
4 10
from wechatpy.exceptions import WeChatClientException
5
6
7 10
class WeChatMenu(BaseWeChatAPI):
8
9 10
    def create(self, agent_id, menu_data):
10
        return self._post(
11
            'menu/create',
12
            params={
13
                'agentid': agent_id
14
            },
15
            data=menu_data
16
        )
17
18 10
    def get(self, agent_id):
19
        try:
20
            return self._get(
21
                'menu/get',
22
                params={
23
                    'agentid': agent_id
24
                }
25
            )
26
        except WeChatClientException as e:
27
            if e.errcode == 46003:
28
                # menu not exist
29
                return None
30
            else:
31
                raise e
32
33 10
    def delete(self, agent_id):
34
        return self._get(
35
            'menu/delete',
36
            params={
37
                'agentid': agent_id
38
            }
39
        )
40
41 10
    def update(self, agent_id, menu_data):
42
        self.delete(agent_id)
43
        return self.create(agent_id, menu_data)
44