WeChatAgent.set()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 9.762

Importance

Changes 0
Metric Value
cc 3
eloc 21
nop 9
dl 0
loc 35
rs 9.376
c 0
b 0
f 0
ccs 1
cts 11
cp 0.0909
crap 9.762

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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