exmail/group.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 127 CC 9 SCAR 21.6
CC
9
Cov
0%
create
12.0
update
12.0
delete
12.0
CRAP 8.7
1 package QQ::exmail::group;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::exmail::group
8
9 =head1 DESCRIPTION
10
11 通讯录管理->管理邮件群组
12
13 =cut
14
15 use strict;
16 use base qw(QQ::exmail);
17 use Encode;
18 use LWP::UserAgent;
19 use JSON;
20 use utf8;
21
22 our $VERSION = '1.10';
23 our @EXPORT = qw/ create update delete get /;
24
25 =head1 FUNCTION
26
27 =head2 create(access_token, hash);
28
29 创建邮件群组
30
31 =head2 SYNOPSIS
32
33 L<https://exmail.qq.com/qy_mng_logic/doc#10022>
34
35 =head3 请求说明:
36
37 =head4 请求包结构体为:
38
39 {
40 "groupid": "zhangsangroup@gzdev.com",
41 "groupname": "zhangsangroup ,
42 "userlist": ["zhangsanp@gzdev.com", "lisi@gzdev.com"],
43 "grouplist": ["group@gzdev.com"],
44 "department": [1, 2],
45 "allow_type": 4,
46 "allow_userlist": ["zhangsanp@gzdev.com"]
47 }
48
49 =head4 参数说明:
50
51 参数 必须 说明
52 access_token 是 调用接口凭证
53 groupid 是 邮件群组名称
54 groupname 是 邮件群组名称
55 userlist 否 成员帐号,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
56 grouplist 否 成员邮件群组,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
57 department 否 成员部门,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
58 allow_type 是 群发权限。0: 企业成员, 1任何人, 2:组内成员,3:指定成员
59 allow_userlist 否 群发权限为指定成员时,需要指定成员
60
61 =head3 权限说明
62
63 系统应用须拥有邮件群组的写管理权限。
64
65 =head3 RETURN 返回结果
66
67 {
68 "errcode": 0,
69 "errmsg": "created"
70 }
71
72 =head4 RETURN 参数说明
73
74 参数 说明
75 errcode 返回码
76 errmsg 对返回码的文本描述内容
77
78 =cut
79
80 sub create {
81 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
82 my $access_token = $_[0];
83 my $json = $_[1];
84 my $ua = LWP::UserAgent->new;
85 $ua->timeout(30);
86 $ua->env_proxy;
87
88 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/group/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
89 if ($response->is_success) {
90 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
91 }
92
93 }
94 return 0;
95 }
96
97 =head2 update(access_token, hash);
98
99 更新邮件群组
100
101 =head2 SYNOPSIS
102
103 L<https://exmail.qq.com/qy_mng_logic/doc#10023>
104
105 =head3 请求说明:
106
107 =head4 请求包结构体为:
108
109 {
110 "groupid": "zhangsangroup@gzdev.com",
111 "groupname": "zhangsangroup",
112 "userlist": ["zhangsanp@gzdev.com","lisi@gzdev.com"],
113 "grouplist": ["group@gzdev.com"],
114 "department":[1,2],
115 "allow_type":3,
116 "allow_userlist":["zhangsanp@gzdev.com"]
117 }
118
119 =head4 参数说明:
120
121 参数 必须 说明
122 access_token 是 调用接口凭证
123 groupid 是 邮件群组id,邮件格式
124 groupname 否 邮件群组名称
125 userlist 否 成员帐号,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
126 grouplist 否 成员邮件群组,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
127 department 否 成员部门,userlist,grouplist,department至少一个。成员由userlist,grouplist,department共同组成
128 allow_type 否 群发权限。0: 企业成员,1任何人,2:组内成员,3:指定成员
129 allow_userlist 否 群发权限为指定成员时,需要指定成员
130
131 =head3 权限说明
132
133 系统应用须拥有邮件群组的写管理权限。
134
135 =head3 RETURN 返回结果
136
137 {
138 "errcode": 0,
139 "errmsg": "updated"
140 }
141
142 =head4 RETURN 参数说明
143
144 参数 说明
145 errcode 返回码
146 errmsg 对返回码的文本描述内容
147
148 =cut
149
150 sub update {
151 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
152 my $access_token = $_[0];
153 my $json = $_[1];
154 my $ua = LWP::UserAgent->new;
155 $ua->timeout(30);
156 $ua->env_proxy;
157
158 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/group/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
159 if ($response->is_success) {
160 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
161 }
162
163 }
164 return 0;
165 }
166
167 =head2 delete(access_token, groupid);
168
169 删除邮件群组
170
171 =head2 SYNOPSIS
172
173 L<https://exmail.qq.com/qy_mng_logic/doc#10024>
174
175 =head3 请求说明:
176
177 =head4 参数说明:
178
179 参数 必须 说明
180 access_token 是 调用接口凭证
181 groupid 是 邮件群组id,邮件格式
182 权限说明
183 系统应用须拥有邮件群组的写管理权限
184
185 =head3 RETURN 返回结果
186
187 {
188 "errcode": 0,
189 "errmsg": "deleted"
190 }
191
192 =head4 RETURN 参数说明
193
194 参数 说明
195 errcode 返回码
196 errmsg 对返回码的文本描述内容
197
198 =cut
199
200 sub delete {
201 if ( @_ && $_[0] && $_[1] ) {
202 my $access_token = $_[0];
203 my $groupid = $_[1];
204 my $ua = LWP::UserAgent->new;
205 $ua->timeout(30);
206 $ua->env_proxy;
207
208 my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/group/delete?access_token=$access_token&groupid=$groupid");
209 if ($response->is_success) {
210 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
211 }
212
213 }
214 return 0;
215 }
216
217 =head2 get(access_token, groupid);
218
219 获取邮件群组信息
220
221 =head2 SYNOPSIS
222
223 L<https://exmail.qq.com/qy_mng_logic/doc#10025>
224
225 =head3 请求说明:
226
227 =head4 参数说明:
228
229 参数 必须 说明
230 access_token 是 调用接口凭证
231 groupid 是 邮件群组id,邮件格式
232
233 =head3 权限说明
234
235 系统应用须拥有邮件群组的读权限
236
237 =head3 RETURN 返回结果
238
239 {
240 "errcode": 0,
241 "errmsg": "ok",
242 "groupid": "zhangsangroup@gzdev.com",
243 "groupname": "zhangsangroup",
244 "userlist": ["zhangsanp@gzdev.com", "lisi@gzdev.com"], 
245 "grouplist": [" group@gzdev.com "],
246 "department": [1, 2],
247 "allow_type": 3,
248 "allow_userlist": ["zhangsanp@gzdev.com"]
249 }
250
251 =head4 RETURN 参数说明
252
253 参数 说明
254 errcode 返回码
255 errmsg 对返回码的文本描述内容
256 groupid 邮件群组id,邮件格式
257 groupname 邮件群组名称
258 userlist 成员帐号
259 grouplist 成员邮件群组
260 department 成员部门
261 allow_type 群发权限。0: 企业成员, 1任何人, 2:组内成员,3:指定成员
262 allow_userlist 群发权限为指定成员时,需要指定成员,否则赋值失效
263
264 =cut
265
266 sub get {
267 if ( @_ && $_[0] && $_[1] ) {
268 my $access_token = $_[0];
269 my $groupid = $_[1];
270 my $ua = LWP::UserAgent->new;
271 $ua->timeout(30);
272 $ua->env_proxy;
273
274 my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/group/get?access_token=$access_token&groupid=$groupid");
275 if ($response->is_success) {
276 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
277 }
278
279 }
280 return 0;
281 }
282
283
284 1;
285 __END__