wechatpy.enterprise.client.api.agent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 35%

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 74
rs 10
c 0
b 0
f 0
ccs 7
cts 20
cp 0.35
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A WeChatAgent.get() 0 12 1
A WeChatAgent.set() 0 35 3
A WeChatAgent.list() 0 9 1
1
# -*- coding: utf-8 -*-
2 10
from __future__ import absolute_import, unicode_literals
3
4 10
from optionaldict import optionaldict
5
6 10
from wechatpy.client.api.base import BaseWeChatAPI
7
8
9 10
class WeChatAgent(BaseWeChatAPI):
10
    """
11
    https://work.weixin.qq.com/api/doc#90000/90135/90226
12
    """
13
14 10
    def get(self, agent_id):
15
        """
16
        获取指定的应用详情
17
        https://work.weixin.qq.com/api/doc#90000/90135/90227/获取指定的应用详情/
18
19
        :param agent_id: 应用id
20
        :return: 返回的 JSON 数据包
21
        """
22
        return self._get(
23
            'agent/get',
24
            params={
25
                'agentid': agent_id
26
            }
27
        )
28
29 10
    def list(self):
30
        """
31
        获取access_token对应的应用列表
32
        https://work.weixin.qq.com/api/doc#90000/90135/90227/获取access_token对应的应用列表/
33
34
        :return: 应用概况列表
35
        """
36
        res = self._get('agent/list')
37
        return res['agentlist']
38
39 10
    def set(self,
40
            agent_id,
41
            name=None,
42
            description=None,
43
            redirect_domain=None,
44
            logo_media_id=None,
45
            report_location_flag=0,
46
            is_report_user=True,
47
            is_report_enter=True):
48
        """
49
        设置应用
50
        https://work.weixin.qq.com/api/doc#90000/90135/90228
51
52
        :param agent_id: 企业应用的id
53
        :param name: 企业应用名称,长度不超过32个utf8字符
54
        :param description: 企业应用详情,长度为4至120个utf8字符
55
        :param redirect_domain: 企业应用可信域名。注意:域名需通过所有权校验,否则jssdk功能将受限,此时返回错误码85005
56
        :param logo_media_id: 企业应用头像的mediaid,通过素材管理接口上传图片获得mediaid,上传后会自动裁剪成方形和圆形两个头像
57
        :param report_location_flag: 企业应用是否打开地理位置上报 0:不上报;1:进入会话上报;
58
        :param is_report_enter: 是否上报用户进入应用事件。0:不接收;1:接收。
59
        :param is_report_user: 是否接收用户变更通知。0:不接收;1:接收。
60
        :return: 返回的 JSON 数据包
61
        """
62
        agent_data = optionaldict()
63
        agent_data['agentid'] = agent_id
64
        agent_data['name'] = name
65
        agent_data['description'] = description
66
        agent_data['redirect_domain'] = redirect_domain
67
        agent_data['logo_mediaid'] = logo_media_id
68
        agent_data['report_location_flag'] = report_location_flag
69
        agent_data['isreportenter'] = 1 if is_report_enter else 0
70
        agent_data['isreportuser'] = 1 if is_report_user else 0
71
        return self._post(
72
            'agent/set',
73
            data=agent_data
74
        )
75