-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathClient.java
More file actions
697 lines (619 loc) · 20.3 KB
/
Client.java
File metadata and controls
697 lines (619 loc) · 20.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
// code generated by oapi sdk gen
/*
* MIT License
*
* Copyright (c) 2022 Lark Technologies Pte. Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.lark.oapi;
import com.lark.oapi.core.Config;
import com.lark.oapi.core.Transport;
import com.lark.oapi.core.cache.ICache;
import com.lark.oapi.core.cache.LocalCache;
import com.lark.oapi.core.enums.AppType;
import com.lark.oapi.core.enums.BaseUrlEnum;
import com.lark.oapi.core.httpclient.IHttpTransport;
import com.lark.oapi.core.httpclient.OkHttpTransport;
import com.lark.oapi.core.request.RequestOptions;
import com.lark.oapi.core.response.RawResponse;
import com.lark.oapi.core.token.*;
import com.lark.oapi.core.utils.OKHttps;
import com.lark.oapi.core.utils.Sets;
import com.lark.oapi.core.utils.Strings;
import com.lark.oapi.service.acs.v1.AcsService;
import com.lark.oapi.service.admin.v1.AdminService;
import com.lark.oapi.service.application.v6.ApplicationService;
import com.lark.oapi.service.approval.v4.ApprovalService;
import com.lark.oapi.service.attendance.v1.AttendanceService;
import com.lark.oapi.service.auth.v3.AuthService;
import com.lark.oapi.service.authen.v1.AuthenService;
import com.lark.oapi.service.baike.v1.BaikeService;
import com.lark.oapi.service.bitable.v1.BitableService;
import com.lark.oapi.service.block.v2.BlockService;
import com.lark.oapi.service.calendar.v4.CalendarService;
import com.lark.oapi.service.contact.v3.ContactService;
import com.lark.oapi.service.corehr.v1.CorehrService;
import com.lark.oapi.service.docx.v1.DocxService;
import com.lark.oapi.service.drive.v1.DriveService;
import com.lark.oapi.service.ehr.v1.EhrService;
import com.lark.oapi.service.event.v1.EventService;
import com.lark.oapi.service.ext.ExtService;
import com.lark.oapi.service.gray_test_open_sg.v1.GrayTestOpenSgService;
import com.lark.oapi.service.helpdesk.v1.HelpdeskService;
import com.lark.oapi.service.hire.v1.HireService;
import com.lark.oapi.service.human_authentication.v1.HumanAuthenticationService;
import com.lark.oapi.service.im.v1.ImService;
import com.lark.oapi.service.lingo.v1.LingoService;
import com.lark.oapi.service.mail.v1.MailService;
import com.lark.oapi.service.mdm.v1.MdmService;
import com.lark.oapi.service.meeting_room.v1.MeetingRoomService;
import com.lark.oapi.service.okr.v1.OkrService;
import com.lark.oapi.service.optical_char_recognition.v1.OpticalCharRecognitionService;
import com.lark.oapi.service.passport.v1.PassportService;
import com.lark.oapi.service.personal_settings.v1.PersonalSettingsService;
import com.lark.oapi.service.search.v2.SearchService;
import com.lark.oapi.service.security_and_compliance.v1.SecurityAndComplianceService;
import com.lark.oapi.service.sheets.v3.SheetsService;
import com.lark.oapi.service.speech_to_text.v1.SpeechToTextService;
import com.lark.oapi.service.task.v1.TaskService;
import com.lark.oapi.service.tenant.v2.TenantService;
import com.lark.oapi.service.translation.v1.TranslationService;
import com.lark.oapi.service.vc.v1.VcService;
import com.lark.oapi.service.wiki.v2.WikiService;
import com.lark.oapi.service.workplace.v1.WorkplaceService;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
public class Client {
private Config config;
private AcsService acs; // 智能门禁
private AdminService admin; // 管理后台-数据报表
private ApplicationService application; // 应用信息
private ApprovalService approval; // 审批
private AttendanceService attendance; // 打卡
private AuthService auth; //
private AuthenService authen; //
private BaikeService baike; // 企业百科
private BitableService bitable; // 云文档-多维表格
private BlockService block; // 小组件
private CalendarService calendar; // 日历
private ContactService contact; // 通讯录
private CorehrService corehr; // CoreHR
private DocxService docx; // 云文档-文档
private DriveService drive; // 云文档-文件管理
private EhrService ehr; // 智能人事
private EventService event; // 事件订阅
private GrayTestOpenSgService grayTestOpenSg; //
private HelpdeskService helpdesk; // 服务台
private HireService hire; // 招聘
private HumanAuthenticationService humanAuthentication; // 实名认证
private ImService im; // 消息与群组
private LingoService lingo; //
private MailService mail; // 邮箱
private MdmService mdm; // 主数据
private MeetingRoomService meetingRoom; //
private OkrService okr; // OKR
private OpticalCharRecognitionService opticalCharRecognition; // AI能力
private PassportService passport; // 帐号
private PersonalSettingsService personalSettings; // 个人设置
private SearchService search; // 搜索
private SecurityAndComplianceService securityAndCompliance; //
private SheetsService sheets; // 云文档-电子表格
private SpeechToTextService speechToText; // AI能力
private TaskService task; // 任务
private TenantService tenant; // 企业信息
private TranslationService translation; // AI能力
private VcService vc; // 视频会议
private WikiService wiki; // 云文档-知识库
private WorkplaceService workplace; //
private ExtService extService;
public static Builder newBuilder(String appId, String appSecret) {
return new Builder(appId, appSecret);
}
public ExtService ext() {
return extService;
}
public void setConfig(Config config) {
this.config = config;
}
/**
* 智能门禁
*
* @return
*/
public AcsService acs() {
return acs;
}
/**
* 管理后台-数据报表
*
* @return
*/
public AdminService admin() {
return admin;
}
/**
* 应用信息
*
* @return
*/
public ApplicationService application() {
return application;
}
/**
* 审批
*
* @return
*/
public ApprovalService approval() {
return approval;
}
/**
* 打卡
*
* @return
*/
public AttendanceService attendance() {
return attendance;
}
/**
* @return
*/
public AuthService auth() {
return auth;
}
/**
* @return
*/
public AuthenService authen() {
return authen;
}
/**
* 企业百科
*
* @return
*/
public BaikeService baike() {
return baike;
}
/**
* 云文档-多维表格
*
* @return
*/
public BitableService bitable() {
return bitable;
}
/**
* 小组件
*
* @return
*/
public BlockService block() {
return block;
}
/**
* 日历
*
* @return
*/
public CalendarService calendar() {
return calendar;
}
/**
* 通讯录
*
* @return
*/
public ContactService contact() {
return contact;
}
/**
* CoreHR
*
* @return
*/
public CorehrService corehr() {
return corehr;
}
/**
* 云文档-文档
*
* @return
*/
public DocxService docx() {
return docx;
}
/**
* 云文档-文件管理
*
* @return
*/
public DriveService drive() {
return drive;
}
/**
* 智能人事
*
* @return
*/
public EhrService ehr() {
return ehr;
}
/**
* 事件订阅
*
* @return
*/
public EventService event() {
return event;
}
/**
* @return
*/
public GrayTestOpenSgService grayTestOpenSg() {
return grayTestOpenSg;
}
/**
* 服务台
*
* @return
*/
public HelpdeskService helpdesk() {
return helpdesk;
}
/**
* 招聘
*
* @return
*/
public HireService hire() {
return hire;
}
/**
* 实名认证
*
* @return
*/
public HumanAuthenticationService humanAuthentication() {
return humanAuthentication;
}
/**
* 消息与群组
*
* @return
*/
public ImService im() {
return im;
}
/**
* @return
*/
public LingoService lingo() {
return lingo;
}
/**
* 邮箱
*
* @return
*/
public MailService mail() {
return mail;
}
/**
* 主数据
*
* @return
*/
public MdmService mdm() {
return mdm;
}
/**
* @return
*/
public MeetingRoomService meetingRoom() {
return meetingRoom;
}
/**
* OKR
*
* @return
*/
public OkrService okr() {
return okr;
}
/**
* AI能力
*
* @return
*/
public OpticalCharRecognitionService opticalCharRecognition() {
return opticalCharRecognition;
}
/**
* 帐号
*
* @return
*/
public PassportService passport() {
return passport;
}
/**
* 个人设置
*
* @return
*/
public PersonalSettingsService personalSettings() {
return personalSettings;
}
/**
* 搜索
*
* @return
*/
public SearchService search() {
return search;
}
/**
* @return
*/
public SecurityAndComplianceService securityAndCompliance() {
return securityAndCompliance;
}
/**
* 云文档-电子表格
*
* @return
*/
public SheetsService sheets() {
return sheets;
}
/**
* AI能力
*
* @return
*/
public SpeechToTextService speechToText() {
return speechToText;
}
/**
* 任务
*
* @return
*/
public TaskService task() {
return task;
}
/**
* 企业信息
*
* @return
*/
public TenantService tenant() {
return tenant;
}
/**
* AI能力
*
* @return
*/
public TranslationService translation() {
return translation;
}
/**
* 视频会议
*
* @return
*/
public VcService vc() {
return vc;
}
/**
* 云文档-知识库
*
* @return
*/
public WikiService wiki() {
return wiki;
}
/**
* @return
*/
public WorkplaceService workplace() {
return workplace;
}
public RawResponse post(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "POST", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse post(String httpPath
, Object body
, AccessTokenType accessTokenType
) throws Exception {
return Transport.send(config, null, "POST", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse get(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "GET", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse get(String httpPath
, Object body
, AccessTokenType accessTokenType) throws Exception {
return Transport.send(config, null, "GET", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse delete(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "DELETE", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse delete(String httpPath
, Object body
, AccessTokenType accessTokenType) throws Exception {
return Transport.send(config, null, "DELETE", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse put(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "PUT", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse put(String httpPath
, Object body
, AccessTokenType accessTokenType) throws Exception {
return Transport.send(config, null, "PUT", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse patch(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "PATCH", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse patch(String httpPath
, Object body
, AccessTokenType accessTokenType) throws Exception {
return Transport.send(config, null, "PATCH", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse options(String httpPath
, Object body
, AccessTokenType accessTokenType
, RequestOptions requestOptions) throws Exception {
return Transport.send(config, requestOptions, "OPTIONS", httpPath, Sets.newHashSet(accessTokenType), body);
}
public RawResponse options(String httpPath
, Object body, AccessTokenType accessTokenType) throws Exception {
return Transport.send(config, null, "OPTIONS", httpPath, Sets.newHashSet(accessTokenType), body);
}
public static final class Builder {
private Config config = new Config();
public Builder(String appId, String appSecret) {
config.setAppId(appId);
config.setAppSecret(appSecret);
config.setBaseUrl(BaseUrlEnum.FeiShu.getUrl());
config.setAppType(AppType.SELF_BUILT);
config.setDisableTokenCache(false);
}
public Builder helpDeskCredential(String helpDeskId, String helpDeskToken) {
config.setHelpDeskToken(helpDeskToken);
config.setHelpDeskID(helpDeskId);
if (Strings.isNotEmpty(helpDeskId) && Strings.isNotEmpty(helpDeskToken)) {
config.setHelpDeskAuthToken(java.util.Base64.getEncoder().encodeToString(String.format("%s:%s", helpDeskId, helpDeskToken).getBytes(StandardCharsets.UTF_8)));
}
return this;
}
public Builder appType(AppType appType) {
config.setAppType(appType);
return this;
}
public Builder marketplaceApp() {
config.setAppType(AppType.MARKETPLACE);
return this;
}
public Builder disableTokenCache() {
config.setDisableTokenCache(true);
return this;
}
public Builder logReqAtDebug(boolean logReqRespInfoAtDebugLevel) {
config.setLogReqAtDebug(logReqRespInfoAtDebugLevel);
return this;
}
public Builder openBaseUrl(String baseUrl) {
config.setBaseUrl(baseUrl);
return this;
}
public Builder openBaseUrl(BaseUrlEnum baseUrl) {
config.setBaseUrl(baseUrl.getUrl());
return this;
}
public Builder tokenCache(ICache cache) {
config.setCache(cache);
return this;
}
public Builder requestTimeout(long timeout, TimeUnit timeUnit) {
config.setRequestTimeOut(timeout);
config.setTimeOutTimeUnit(timeUnit);
return this;
}
public Builder httpTransport(IHttpTransport httpTransport) {
config.setHttpTransport(httpTransport);
return this;
}
private void initCache(Config config) {
if (config.getCache() != null) {
GlobalAppTicketManager.setAppTicketManager(new AppTicketManager(config.getCache()));
GlobalTokenManager.setTokenManager(new TokenManager(config.getCache()));
GlobalJsSdkTicketManager.setGlobalAppTicketManager(new JsSdkTicketManager(config.getCache()));
} else {
ICache cache = LocalCache.getInstance();
GlobalAppTicketManager.setAppTicketManager(new AppTicketManager(cache));
GlobalTokenManager.setTokenManager(new TokenManager(cache));
GlobalJsSdkTicketManager.setGlobalAppTicketManager(new JsSdkTicketManager(cache));
}
}
private void initHttpTransport(Config config) {
if (config.getHttpTransport() == null) {
if (config.getRequestTimeOut() > 0) {
config.setHttpTransport(new OkHttpTransport(OKHttps.create(config.getRequestTimeOut(), config.getTimeOutTimeUnit())));
} else {
config.setHttpTransport(new OkHttpTransport(OKHttps.defaultClient));
}
}
}
public Client build() {
Client client = new Client();
client.setConfig(config);
initCache(config);
initHttpTransport(config);
client.extService = new ExtService(config);
client.acs = new AcsService(config);
client.admin = new AdminService(config);
client.application = new ApplicationService(config);
client.approval = new ApprovalService(config);
client.attendance = new AttendanceService(config);
client.auth = new AuthService(config);
client.authen = new AuthenService(config);
client.baike = new BaikeService(config);
client.bitable = new BitableService(config);
client.block = new BlockService(config);
client.calendar = new CalendarService(config);
client.contact = new ContactService(config);
client.corehr = new CorehrService(config);
client.docx = new DocxService(config);
client.drive = new DriveService(config);
client.ehr = new EhrService(config);
client.event = new EventService(config);
client.grayTestOpenSg = new GrayTestOpenSgService(config);
client.helpdesk = new HelpdeskService(config);
client.hire = new HireService(config);
client.humanAuthentication = new HumanAuthenticationService(config);
client.im = new ImService(config);
client.lingo = new LingoService(config);
client.mail = new MailService(config);
client.mdm = new MdmService(config);
client.meetingRoom = new MeetingRoomService(config);
client.okr = new OkrService(config);
client.opticalCharRecognition = new OpticalCharRecognitionService(config);
client.passport = new PassportService(config);
client.personalSettings = new PersonalSettingsService(config);
client.search = new SearchService(config);
client.securityAndCompliance = new SecurityAndComplianceService(config);
client.sheets = new SheetsService(config);
client.speechToText = new SpeechToTextService(config);
client.task = new TaskService(config);
client.tenant = new TenantService(config);
client.translation = new TranslationService(config);
client.vc = new VcService(config);
client.wiki = new WikiService(config);
client.workplace = new WorkplaceService(config);
return client;
}
}
}