exmail/department.pm untested

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 152 CC 11 SCAR 22.1
CC
11
Cov
0%
create
12.0
update
12.0
delete
12.0
CRAP 9.1
1 package QQ::exmail::department;
2
3 =pod
4
5 =encoding utf8
6
7 =head1 Name
8
9 QQ::exmail::department
10
11 =head1 DESCRIPTION
12
13 通讯录管理->管理部门
14
15 =cut
16
17 use strict;
18 use base qw(QQ::exmail);
19 use Encode;
20 use LWP::UserAgent;
21 use JSON;
22 use utf8;
23
24 our $VERSION = '1.10';
25 our @EXPORT = qw/ create update delete list search /;
26
27 =head1 FUNCTION
28
29 =head2 create(access_token, hash);
30
31 创建部门
32
33 =head2 SYNOPSIS
34
35 L<https://exmail.qq.com/qy_mng_logic/doc#10008>
36
37 =head3 请求说明
38
39 =head4 请求包结构体为:
40
41 {
42 "name": "广州研发中心",
43 "parentid": 1,
44 "order": 0
45 }
46
47 =head4 参数说明
48
49 参数 必须 说明
50 access_token 是 调用接口凭证
51 name 是 部门名称。长度限制为1~64个字节,字符不能包括\:*?"<>|
52 parentid 是 父部门id。id为1可表示根部门
53 order 否 在父部门中的次序值。order值小的排序靠前,1-10000为保留值,若使用保留值,将被强制重置为0。
54
55 =head3 权限说明
56
57 系统应用须拥有父部门的管理权限。
58
59 =head3 RETURN 返回结果
60
61 {
62 "errcode": 0,
63 "errmsg": "created",
64 "id": 2
65 }
66
67 =head4 RETURN 参数说明
68
69 参数 说明
70 errcode 返回码
71 errmsg 对返回码的文本描述内容
72 id 创建的部门id。id为64位整型数
73
74 =cut
75
76 sub create {
77 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
78 my $access_token = $_[0];
79 my $json = $_[1];
80 my $ua = LWP::UserAgent->new;
81 $ua->timeout(30);
82 $ua->env_proxy;
83
84 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/department/create?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
85 if ($response->is_success) {
86 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
87 }
88
89 }
90 return 0;
91 }
92
93 =head2 update(access_token, hash);
94
95 更新部门
96
97 =head2 SYNOPSIS
98
99 L<https://exmail.qq.com/qy_mng_logic/doc#10009>
100
101 =head3 请求说明:
102
103 =head4 请求包结构体为(如果非必须的字段未指定,则不更新该字段之前的设置值):
104
105 {
106 "id": 2,
107 "name": "广州研发中心",
108 "parentid": 1,
109 "order": 0
110 }
111
112 =head4 参数说明:
113
114 参数 必须 说明
115 access_token 是 调用接口凭证
116 id 是 部门id
117 name 否 更新的部门名称。长度限制为1~64个字节,字符不能包括\:*?"<>|。修改部门名称时指定该参数
118 parentid 否 父部门id。id为1可表示根部门
119 order 否 在父部门中的次序值。order值小的排序靠前,1-10000为保留值,若使用保留值,将被强制重置为0。
120
121 =head3 权限说明
122
123 系统应用须拥有指定部门的管理权限。
124
125 =head3 RETURN 返回结果
126
127 {
128 "errcode": 0,
129 "errmsg": "updated"
130 }
131
132 =head4 RETURN 参数说明
133
134 参数 说明
135 errcode 返回码
136 errmsg 对返回码的文本描述内容
137
138 =cut
139
140 sub update {
141 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
142 my $access_token = $_[0];
143 my $json = $_[1];
144 my $ua = LWP::UserAgent->new;
145 $ua->timeout(30);
146 $ua->env_proxy;
147
148 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/department/update?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
149 if ($response->is_success) {
150 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
151 }
152
153 }
154 return 0;
155 }
156
157 =head2 delete(access_token, id);
158
159 删除部门
160
161 =head2 SYNOPSIS
162
163 L<https://exmail.qq.com/qy_mng_logic/doc#10010>
164
165 =head3 请求说明:
166
167 =head4 参数说明:
168
169 参数 必须 说明
170 access_token 是 调用接口凭证
171 id 是 部门id。(注:不能删除根部门;不能删除含有子部门、成员的部门)
172
173 =head4 权限说明
174
175 系统应用须拥有指定部门的管理权限。
176
177 =head3 RETURN 返回结果
178
179 {
180 "errcode": 0,
181 "errmsg": "deleted"
182 }
183
184 =head4 RETURN 参数说明
185
186 参数 说明
187 errcode 返回码
188 errmsg 对返回码的文本描述内容
189
190 =cut
191
192 sub delete {
193 if ( @_ && $_[0] && $_[1] ) {
194 my $access_token = $_[0];
195 my $id = $_[1];
196 my $ua = LWP::UserAgent->new;
197 $ua->timeout(30);
198 $ua->env_proxy;
199
200 my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/department/delete?access_token=$access_token&id=$id");
201 if ($response->is_success) {
202 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
203 }
204
205 }
206 return 0;
207 }
208
209 =head2 list(access_token, id);
210
211 获取部门列表
212
213 =head2 SYNOPSIS
214
215 L<https://exmail.qq.com/qy_mng_logic/doc#10011>
216
217 =head3 参数说明:
218
219 参数 必须 说明
220 access_token 是 调用接口凭证
221 id 否 部门id。获取指定部门及其下的子部门。id为1时可获取根部门下的子部门。
222
223 =head3 权限说明
224
225 系统应用须拥有指定部门的查看权限。
226
227 =head3 RETURN 返回结果
228
229 {
230 "errcode": 0,
231 "errmsg": "ok",
232 "department": [{
233 "id": 2,
234 "name": "广州研发中心",
235 "parentid": 1,
236 "order": 10
237 },
238 {
239 "id": 3
240 "name": "邮箱产品部",
241 "parentid": 2,
242 "order": 40
243 }
244 ]
245 }
246
247 =head4 RETURN 参数说明
248
249 参数 说明
250 errcode 返回码
251 errmsg 对返回码的文本描述内容
252 department 部门列表数据。以部门的order字段从小到大排列
253 id 部门id
254 name 部门名称
255 parentid 父部门id。
256 order 在父部门中的次序值。order值小的排序靠前
257
258 =cut
259
260 sub list {
261 if ( @_ && $_[0] && $_[1] ) {
262 my $access_token = $_[0];
263 my $id = $_[1];
264 my $ua = LWP::UserAgent->new;
265 $ua->timeout(30);
266 $ua->env_proxy;
267
268 my $response = $ua->get("https://api.exmail.qq.com/cgi-bin/department/list?access_token=$access_token&id=$id");
269 if ($response->is_success) {
270 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
271 }
272
273 }
274 return 0;
275 }
276
277 =head2 search(access_token, hash);
278
279 查找部门
280
281 =head2 SYNOPSIS
282
283 L<https://exmail.qq.com/qy_mng_logic/doc#10012>
284
285 =head3 请求说明:
286
287 =head4 请求包结构体为:
288
289 {
290 "name": "邮箱产品部",
291 "fuzzy": 0,
292 }
293
294 =head4 参数说明:
295
296 参数 必须 说明
297 access_token 是 调用接口凭证
298 name 否 查找的部门名字,必须合法
299 fuzzy 否 1/0:是否模糊匹配
300
301 =head3 权限说明
302
303 系统应用须拥有指定部门的查看权限。
304
305 =head3 RETURN 返回结果
306
307 {
308 "errcode": 0,
309 "errmsg": "ok",
310 "department": [
311 {
312 "id": 3
313 "name": "邮箱产品部",
314 "parentid": 2,
315 "order": 40,
316 "path":"广州研发中心/邮箱产品部"
317 },
318 {
319 "id": 10
320 "name": "邮箱产品部",
321 "parentid": 6,
322 "order": 40,
323 "path":"深圳研发中心/邮箱产品部"
324 }
325 ]
326 }
327
328 =head4 RETURN 参数说明
329
330 参数 说明
331 errcode 返回码
332 errmsg 对返回码的文本描述内容
333 department 部门列表数据。以部门的order字段从小到大排列
334 id 部门id
335 name 部门名称
336 parentid 父部门id。根部门为0
337 order 在父部门中的次序值。order值小的排序靠前。
338 path 部门路径,部门用’/ ’作分割符
339
340 =cut
341
342 sub search {
343 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
344 my $access_token = $_[0];
345 my $json = $_[1];
346 my $ua = LWP::UserAgent->new;
347 $ua->timeout(30);
348 $ua->env_proxy;
349
350 my $response = $ua->post("https://api.exmail.qq.com/cgi-bin/department/search?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
351 if ($response->is_success) {
352 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
353 }
354
355 }
356 return 0;
357 }
358
359
360 1;
361 __END__