-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebAPIWrapper.java
More file actions
726 lines (600 loc) · 34.2 KB
/
WebAPIWrapper.java
File metadata and controls
726 lines (600 loc) · 34.2 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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class WebAPIWrapper {
//__init__
//HTTPCLIENT AND TOKEN Variables
private static HttpClient client = HttpClient.newHttpClient();
private static String token;
//Constructor to initialize token.
public WebAPIWrapper(String token) {
WebAPIWrapper.token = token;
}
//Getter for token
public String getToken() { return token; }
//<-------------------------------API FUNCTION CALLS START -- HERE -------------------------------------->//
public void getSystemInfo() throws IOException, InterruptedException {
sendPOST("getSystemInfo", token);
}
public void getProfileStatus() throws IOException, InterruptedException {
sendPOST("getProfileStatus", token);
}
public void setProfileStatus(String status, String mood) throws IOException, InterruptedException {
sendPOST("setProfileStatus", token);
}
public void getOwnContact() throws IOException, InterruptedException {
sendPOST("getOwnContact", token);
}
public void getContacts(String filter) throws IOException, InterruptedException {
String params = "\"filter\": \"" +
filter +
"\"";
sendPOSTWithParams("getContacts", params, token);
}
public void getContactAvatar(String pk, String coder, String format) throws IOException, InterruptedException {
String params = "\"pk\": \"" +
pk +
"\", " +
"\"coder\": \"" +
coder +
"\", " +
"\"format\": \"" +
format +
"\"";
sendPOSTWithParams("getContactsAvatar", params, token);
}
public void getChannelAvatar(String channelID, String coder, String format) throws IOException, InterruptedException {
String params = "\"channelid\": \"" +
channelID +
"\", " +
"\"coder\": \"" +
coder +
"\", " +
"\"format\": \"" +
"\"";
sendPOSTWithParams("getChannelAvatar", params, token);
}
public void setContactGroup(String pk, String groupName) throws IOException, InterruptedException {
String params = "\"contactPublicKey\": \"" +
pk +
"\", " +
"\"groupName\": \"" +
groupName +
"\"";
sendPOSTWithParams("setContactGroup", params, token);
}
public void setContactNick(String pk, String newNick) throws IOException, InterruptedException {
String params = "\"contactPublicKey\": \"" +
pk +
"\", " +
"\"newNick\": \"" +
newNick +
"\"";
sendPOSTWithParams("setContactNick", params, token);
}
public void sendInstantMessage(String to, String text) throws IOException, InterruptedException {
String params = "\"to\": \"" +
to +
"\", " +
"\"text\": \"" +
text +
"\"";
sendPOSTWithParams("sendInstantMessage", params, token);
}
public void sendInstantQuote(String to, String text, String id_message) throws IOException, InterruptedException {
String params = "\"to\": \"" +
to +
"\", " +
"\"text\": \"" +
text +
"\", " +
"\"id_message\": \"" +
id_message +
"\"";
sendPOSTWithParams("sendInstantQuote", params, token);
}
public void sendInstantSticker(String to, String collection, String name) throws IOException, InterruptedException {
String params = "\"to\": \"" +
to +
"\", " +
"\"collection\": \"" +
collection +
"\", " +
"\"name\": \"" +
name +
"\"";
sendPOSTWithParams("sendInstantSticker", params, token);
}
public void getStickerCollections() throws IOException, InterruptedException {
sendPOST("sendInstantSticker", token);
}
public void getStickerNamesByCollection(String collection_name) throws IOException, InterruptedException {
String params = "\"collecton_name\": \"" + collection_name + "\"";
sendPOSTWithParams("getStickerNamesByCollection", params, token);
}
public void getImageSticker(String collection_name, String sticker_name, String coder) throws IOException, InterruptedException {
String params = "\"collection_name\": \"" + collection_name + "\", " +
"\"sticker_name\": \"" + sticker_name + "\", " +
"\"coder\": \"" + coder + "\"";
sendPOSTWithParams("getImageSticker", params, token);
}
public void sendInstantBuzz(String to, String comments) throws IOException, InterruptedException {
String params = "\"to\": \"" + to + "\", " +
"\"comments\": \"" + comments + "\"";
sendPOSTWithParams("sendInstantBuzz", params, token);
}
public void sendInstantInvitation(String to, String channelID, String description, String comments) throws IOException, InterruptedException {
String params = "\to\": \"" + to + "\", " +
"\"channelid\": \" " + channelID + "\", " +
"\"description\": \"" + description + "\", " +
"\"comments\": \"" + comments + "\"";
sendPOSTWithParams("sendInstantInvitation", params, token);
}
public void removeInstantMessages(String hex_contact_public_key) throws IOException, InterruptedException {
String params = "\"hex_contact_public_key\": \"" + hex_contact_public_key + "\"";
sendPOSTWithParams("removeInstantMessage", params, token);
}
public void getContactMessages(String pk) throws IOException, InterruptedException {
String params = "\"pk\": \"" + pk + "\"";
sendPOSTWithParams("getContactMessages", params, token);
}
public void sendEmailMessage(String to, String subject, String body) throws IOException, InterruptedException {
String params = "\"to\": [ \"" + to + "\" ], " +
"\"subject\": \"" + subject + "\", " +
"\"body\": \"" + body + "\"";
sendPOSTWithParams("sendEmailMessage", params, token);
}
public void sendPayment(String cardid, String to, String amount, String comment, String fromCard) throws IOException, InterruptedException {
String params = "\"to\": \"" + to + "\", " +
"\"comment\": \"" + comment + "\", " +
"\"cardid\": \"" + cardid + "\", " +
"\"amount\": \"" + amount + "\"";
sendPOSTWithParams("sendPayment", params, token);
}
public void getEmailFolder(String folderType, String filter) throws IOException, InterruptedException {
String params = "\"folderType\": \"" + folderType + "\", " +
"\"filter\": \"" + filter + "\"";
sendPOSTWithParams("getEmailFolder", params, token);
}
public void getEmails(String folderType, String filter) throws IOException, InterruptedException {
String params = "\"folderType\": \"" + folderType + "\", " +
"\"filter\": \"" + filter + "\"";
sendPOSTWithParams("getEmailFolder", params, token);
}
public void getEmailsById(String id) throws IOException, InterruptedException {
String params = "\"id\": \"" + id + "\"";
sendPOSTWithParams("getEmailById", params, token);
}
public void deleteEmail(String id) throws IOException, InterruptedException {
String params = "\"id\": \"" + id + "\"";
sendPOSTWithParams("deleteEmail", params, token);
}
public void sendReplyEmailMessage(String id, String body, String subject) throws IOException, InterruptedException {
String params = "\"id\": \"" + id + "\", " +
"\"body\": \"" + body + "\", " +
"\"subject\": \"" + subject + "\"";
sendPOSTWithParams("sendReplyEmailMessage", params, token);
}
public void sendForwardEmailMessage(String id, String to, String body, String subject) throws IOException, InterruptedException {
String params = "\"id\": \"" + id + "\", " +
"\"to\": \"" + to + "\", " +
"\"body\": \"" + body + "\", " +
"\"subject\": \"" + subject + "\"";
sendPOSTWithParams("sendForwardEmailMessage", params, token);
}
public void getFinanceSystemInformation() throws IOException, InterruptedException {
sendPOST("getFinanceSystemInformation", token);
}
public void getBalance() throws IOException, InterruptedException {
sendPOST("getBalance", token);
}
public void getFinanceHistory(String filters, String referenceNumber, String toDate, String fromDate,
String batchId, String fromAmount, String toAmount) throws IOException, InterruptedException {
String params = "\"filters\": \"" + filters + "\", " +
"\"referenceNumber\": \"" + referenceNumber + "\", " +
"\"fromDate\": \"" + fromDate + "\", " +
"\"toDate\": \"" + toDate + "\", " +
"\"batchId\": \"" + batchId + "\", " +
"\"fromAmount\": \"" + fromAmount + "\", " +
"\"toAmount\": \"" + toAmount + "\"";
sendPOSTWithParams("getFinanceHistory", params, token);
}
public void getCards() throws IOException, InterruptedException {
sendPOST("getCards", token);
}
public void addCard(String name, String color, String numbers) throws IOException, InterruptedException {
String params = "\"color\": \"" + color + "\", " +
"\"name\": \"" + name + "\", " +
"\"preorderNumberInCard\": \"" + numbers + "\"";
sendPOSTWithParams("addCard", params, token);
}
public void deleteCard(String cardId) throws IOException, InterruptedException {
String params = "\"cardId\": \"" + cardId + "\"";
sendPOSTWithParams("deleteCard", params, token);
}
public void enableMining(String enabled) throws IOException, InterruptedException {
String params = "\"enable\": \"" + enabled + "\"";
sendPOSTWithParams("enableMining", params, token);
}
public void enableInterest(String enabled) throws IOException, InterruptedException {
String params = "\"enable\": \"" + enabled + "\"";
sendPOSTWithParams("enableInterest", params, token);
}
public void enableHistoryMining(String enabled) throws IOException, InterruptedException {
String params = "\"enable\": \"" + enabled + "\"";
sendPOSTWithParams("enableHistoryMining", params, token);
}
public void statusHistoryMining() throws IOException, InterruptedException {
sendPOST("statusHistoryMining", token);
}
public void getMiningBlocks() throws IOException, InterruptedException {
sendPOST("getMiningBlocks", token);
}
public void getMiningInfo() throws IOException, InterruptedException {
sendPOST("getMiningInfo", token);
}
public void getVouchers() throws IOException, InterruptedException {
sendPOST("getVouchers", token);
}
public void createVoucher(String amount) throws IOException, InterruptedException {
String params = "\"amount\": \"" + amount + "\"";
sendPOSTWithParams("createVoucher", params, token);
}
public void useVoucher(String voucherid) throws IOException, InterruptedException {
String params = "\"voucherid\": \"" + voucherid + "\"";
sendPOSTWithParams("useVoucher", params, token);
}
public void deleteVoucher(String voucherid) throws IOException, InterruptedException {
String params = "\"voucherid\": \"" + voucherid + "\"";
sendPOSTWithParams("deleteVoucher", params, token);
}
public void getInvoices(String cardId, String invoiceId, String pk, String transactionId, String status,
String startDateTime, String endDateTime, String referenceNumber) throws IOException, InterruptedException {
String params = "\"cardId\": \""+ cardId + "\", " +
"\"invoiceId\": \"" + invoiceId + "\", " +
"\"pk\": \"" + pk + "\", " +
"\"transactionId\": \"" + transactionId + "\", " +
"\"status\": \"" + status + "\", " +
"\"startDateTime\": \"" + startDateTime + "\", " +
"\"endDateTime\": \"" + endDateTime + "\", " +
"\"referenceNumber\": \"" + referenceNumber + "\"";
sendPOSTWithParams("getInvoices", params, token);
}
public void getInvoiceByReferenceNumber() throws IOException, InterruptedException {
sendPOST("getInvoiceByReferenceNumber", token);
}
public void getTransactionIdByReferenceNumber() throws IOException, InterruptedException {
sendPOST("getTransactionIdByReferenceNumber", token);
}
public void sendInvoice(String cardid, String amount, String comment) throws IOException, InterruptedException {
String params = "\"comment\": \"" + comment + "\", " +
"\"cardid\": \"" + cardid + "\", " +
"\"amount\": \"" + amount + "\", ";
sendPOSTWithParams("sendInvoice", params, token);
}
public void acceptInvoice(String invoiceid) throws IOException, InterruptedException {
String params = "\"invoiceid\": \"" + invoiceid + "\"";
sendPOSTWithParams("acceptInvoice", params, token);
}
public void declineInvoice(String invoiceid) throws IOException, InterruptedException {
String params = "\"invoiceid\": \"" + invoiceid + "\"";
sendPOSTWithParams("declineInvoice", params, token);
}
public void cancelInvoice(String invoiceid) throws IOException, InterruptedException {
String params = "\"invoiceid\": \"" + invoiceid + "\"";
sendPOSTWithParams("cancelInvoice", params, token);
}
public void requestUnsTransfer(String name, String hexNewOwnerPk) throws IOException, InterruptedException {
String params = "\"name\": \"" + name + "\", " +
"\"hexNewOwnerPk\": \"" + hexNewOwnerPk + "\"";
sendPOSTWithParams("requestUnsTransfer", params, token);
}
public void acceptUnsTransfer(String requestId) throws IOException, InterruptedException {
String params = "\"requestId\": \"" + requestId + "\"";
sendPOSTWithParams("acceptUnsTransfer", params, token);
}
public void declineUnsTransfer(String requestId) throws IOException, InterruptedException {
String params = "\"requestId\": \"" + requestId + "\"";
sendPOSTWithParams("declineUnsTransfer", params, token);
}
public void incomingUnsTransfer() throws IOException, InterruptedException {
sendPOST("incomingUnsTransfer", token);
}
public void outgoingUnsTransfer() throws IOException, InterruptedException {
sendPOST("outgoingUnsTransfer", token);
}
public void storageWipe() throws IOException, InterruptedException {
sendPOST("storageWipe", token);
}
public void sendAuthorizationRequest(String pk, String message) throws IOException, InterruptedException {
String params = "\"pk\": \"" + pk + "\", " +
"\"message\": \"" + message + "\"";
sendPOSTWithParams("sendAuthorizationRequest", params, token);
}
public void acceptAuthorizationRequest(String pk, String message) throws IOException, InterruptedException {
String params = "\"pk\": \"" + pk + "\", " +
"\"message\": \"" + message + "\"";
sendPOSTWithParams("acceptAuthorizationRequest", params, token);
}
public void rejectAuthorizationRequest(String pk, String message) throws IOException, InterruptedException {
String params = "\"pk\": \"" + pk + "\", " +
"\"message\": \"" + message + "\"";
sendPOSTWithParams("rejectAuthorizationRequest", params, token);
}
public void deleteContact(String pk) throws IOException, InterruptedException {
String params = "\"pk\": \"" + pk +"\"";
sendPOSTWithParams("deleteContact", params, token);
}
public void getChannels(String filter, String channel_type) throws IOException, InterruptedException {
String params = "\"filter\": \"" + filter + "\", " +
"\"channel_type\": \"" + channel_type + "\"";
sendPOSTWithParams("getChannels", params, token);
}
public void sendChannelMessage(String channelid, String message) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\", " +
"\"message\": \"" + message + "\"";
sendPOSTWithParams("sendChannelMessage", params, token);
}
public void sendChannelPicture(String channelid, String base64_image, String filename_image) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\", " +
"\"base64_image\": \"" + base64_image + "\", " +
"\"filename_image\": \"" + filename_image + "\"";
sendPOSTWithParams("sendChannelPicture", params, token);
}
public void joinChannel(String channelId, String password) throws IOException, InterruptedException {
String params = "\"ident\": \"" + channelId + "\"" +
"\"password\": \"" + password + "\"";
sendPOSTWithParams("joinChannel", params, token);
}
public void leaveChannel(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("leaveChannel", params, token);
}
public void getChannelMessages(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("getChannelMessage", params, token);
}
public void getChannelInfo(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("getChannelInfo", params, token);
}
public void getChannelModerators(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("getChannelModerators", params, token);
}
public void getChannelContacts(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("getChannelContacts", params, token);
}
public void getChannelModeratorRight(String channelid, String moderator) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\", " +
"\"moderator\": \"" + moderator + "\"";
sendPOSTWithParams("getChannelModeratorRight", params, token);
}
public void createChannel(String channel_name, String description, String read_only, String read_only_privacy,
String password, String languages, String hashtags, String geoTag,
String base64_avatar_image, String hide_in_UI) throws IOException, InterruptedException {
String params = "" +
"\"channel_name\": \"" + channel_name + "\", " +
"\"description\": \"" + description + "\", " +
"\read_only\": \"" + read_only + "\", " +
"\"read_only_privacy\": \"" + read_only_privacy +"\", " +
"\"password\": \"" + password + "\", " +
"\"languages\": \"" + languages + "\", " +
"\"hashtags\": \"" + hashtags + "\", " +
"\"geoTag\": \"" + geoTag + "\", " +
"\"base64_avatar_image\": \"" + base64_avatar_image + "\", " +
"\"hide_in_UI\": \"" + hide_in_UI + "\"";
sendPOSTWithParams("createChannel", params, token);
}
public void modifyChannel(String channel_name, String description, String read_only, String read_only_privacy,
String password, String languages, String hashtags, String geoTag,
String base64_avatar_image, String hide_in_UI) throws IOException, InterruptedException {
String params = "" +
"\"channel_name\": \"" + channel_name + "\", " +
"\"description\": \"" + description + "\", " +
"\read_only\": \"" + read_only + "\", " +
"\"read_only_privacy\": \"" + read_only_privacy +"\", " +
"\"password\": \"" + password + "\", " +
"\"languages\": \"" + languages + "\", " +
"\"hashtags\": \"" + hashtags + "\", " +
"\"geoTag\": \"" + geoTag + "\", " +
"\"base64_avatar_image\": \"" + base64_avatar_image + "\", " +
"\"hide_in_UI\": \"" + hide_in_UI + "\"";
sendPOSTWithParams("modifyChannel", params, token);
}
public void deleteChannel(String channelid) throws IOException, InterruptedException {
String params = "\"channelid\": \"" + channelid + "\"";
sendPOSTWithParams("deleteChannel", params, token);
}
public void getChannelSystemInfo() throws IOException, InterruptedException {
sendPOST("getChannelSystemInfo", token);
}
public void unsCreateRecordRequest(String nick, String valid, String isPrimary, String Channelid) throws IOException, InterruptedException {
String params = "\"nick\": \"" + nick + "\", " +
"\"valid\": \"" + valid + "\", " +
"\"isPrimary\": \"" + isPrimary + "\", " +
"\"channelId\": \"" + Channelid + "\"";
sendPOSTWithParams("unsCreateRecordRequest", params, token);
}
public void unsModifyRecordRequest(String nick, String valid, String isPrimary, String channelId) throws IOException, InterruptedException {
String params = "\"nick\": \"" + nick + "\", " +
"\"valid\": \"" + valid + "\", " +
"\"isPrimary\": \"" + isPrimary + "\", " +
"\"channelId\": \"" + channelId + "\"";
sendPOSTWithParams("unsModifyRecordRequest", params, token);
}
public void unsDeleteRecordRequest(String nick) throws IOException, InterruptedException {
String params = "\"nick\": \"" + nick + "\"";
sendPOSTWithParams("unsDeleteRecordRequest", params, token);
}
public void unsSearchByPk(String filter) throws IOException, InterruptedException {
String params = "\"filter\": \"" + filter + "\"";
sendPOSTWithParams("unsSearchByPk", params, token);
}
public void unsSearchByNick(String filter) throws IOException, InterruptedException {
String params = "\"filter\": \"" + filter + "\"";
sendPOSTWithParams("unsSearchByNick", params, token);
}
public void getUnsSyncInfo() throws IOException, InterruptedException {
sendPOST("getUnsSyncInfo", token);
}
public void unsRegisteredNames() throws IOException, InterruptedException {
sendPOST("unsRegisteredNames", token);
}
public void summaryUnsRegisteredNames(String date_from, String date_to) throws IOException, InterruptedException {
String params = "\"fromDate\": \"" + date_from + "\", " +
"\"toDate\": \"" + date_to + "\"";
sendPOSTWithParams("summaryUnsRegisteredNames", params, token);
}
public void clearTrayNotifications() throws IOException, InterruptedException {
sendPOST("clearTrayNotifications", token);
}
public void getNetworkConnections() throws IOException, InterruptedException {
sendPOST("getNetworkConnections", token);
}
public void getProxyMappings() throws IOException, InterruptedException {
sendPOST("getProxyMappings", token);
}
public void createProxyMapping(String srcHost, String srcPort, String dstHost, String dstPort, String enabled) throws IOException, InterruptedException {
String params = "\"srcHost\": \"" + srcHost + "\", " +
"\"srcPort\": \"" + srcPort + "\", " +
"\"dstHost\": \"" + dstHost + "\", " +
"\"dstPort\": \"" + dstPort + "\", " +
"\"enabled\": \"" + enabled + "\"";
sendPOSTWithParams("createProxyMapping", params, token);
}
public void enableProxyMapping(String mappingId) throws IOException, InterruptedException {
String params = "\"mappingId\": \"" + mappingId + "\"";
sendPOSTWithParams("enableProxyMapping", params, token);
}
public void disableProxyMapping(String mappingId) throws IOException, InterruptedException {
String params = "\"mappingId\": \"" + mappingId + "\"";
sendPOSTWithParams("disableProxyMapping", params, token);
}
public void removeProxyMapping(String mappingId) throws IOException, InterruptedException {
String params = "\"mappingId\": \"" + mappingId + "\"";
sendPOSTWithParams("removeProxyMapping", params, token);
}
public void lowTrafficMode() throws IOException, InterruptedException {
sendPOST("lowTrafficMode", token);
}
public void setLowTrafficMode(String enabled) throws IOException, InterruptedException {
String params = "\"enabled\": \"" + enabled + "\"";
sendPOSTWithParams("setLowTrafficMode", params, token);
}
public void getWhoIsInfo(String nick_or_pk) throws IOException, InterruptedException {
String params = "\"owner\": \"" + nick_or_pk + "\"";
sendPOSTWithParams("getWhoIsInfo", params, token);
}
public void requestTreasuryInterestRates() throws IOException, InterruptedException {
sendPOST("requestTreasuryInterestRates", token);
}
public void getTreasuryInterestRates() throws IOException, InterruptedException {
sendPOST("getTreasuryInterestRates", token);
}
public void requestTreasuryTransactionVolumes() throws IOException, InterruptedException {
sendPOST("requestTreasuryTransactionVolumes", token);
}
public void getTreasuryTransactionVolumes() throws IOException, InterruptedException {
sendPOST("getTreasuryTransactionVolumes", token);
}
public void ucodeEncode(String hex_code, String size_image, String coder, String format) throws IOException, InterruptedException {
String params = "\"hex_code\": \"" + hex_code + "\", " +
"\"size_image\": \"" + size_image + "\", " +
"\"coder\": \"" + coder + "\", " +
"\"format\": \"" + format + "\"";
sendPOSTWithParams("ucodeEncode", params, token);
}
public void ucodeDecode(String base64_image) throws IOException, InterruptedException {
String params = "\"base64_image\": \"" + base64_image + "\"";
sendPOSTWithParams("ucodeDecode", params, token);
}
public void getWebSocketState() throws IOException, InterruptedException {
sendPOST("getWebSocketState", token);
}
public void setWebSocketState(String enabled, String port) throws IOException, InterruptedException {
String params = "\"enabled\": \"" +
enabled +
"\", " +
"\"port\": \" " +
port +
"\"";
sendPOSTWithParams("getWebSocketState", params, token);
}
//<--------------------------------------------API FUNCTION CALLS END --------------------------------------->//
//Method to Send JSON POST request using HTTP client.
private void sendPOST(String method, String token) throws IOException, InterruptedException {
/*
Example: --
Request
{
"method": "getSystemInfo",
"token": "TEMPTOKEN"
}
*/
// json formatted data -- See the above format
String json = "{" +
"\"method\":" +
"\"" +
method +
"\", " +
"\"token\":" +
"\"" +
token +
"\"" +
"}";
HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString(json))
.uri(URI.create("http://127.0.0.1:20000/api/1.0"))
.setHeader("User-Agent", "Utopia API Wrapper Bot") // add request header
.header("Content-Type", "application/json")
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// print status code
System.out.println(response.statusCode());
// print response body
System.out.println(response.body());
}
private void sendPOSTWithParams(String method, String params, String token) throws IOException, InterruptedException {
/*
Example: --
Request
{
"method": "setProfileStatus",
"params": {
"status": "Available",
"mood": "Hi"
},
"token": "TEMPTOKEN"
}
*/
// json formatted data -- See the above format
String json = "{" +
"\"method\":" +
"\"" +
method +
"\", " +
"\"params\": { " +
params +
"}, " +
"\"token\":" +
"\"" +
token +
"\"" +
"}";
HttpRequest request = HttpRequest.newBuilder()
.POST(HttpRequest.BodyPublishers.ofString(json))
.uri(URI.create("http://127.0.0.1:20000/api/1.0"))
.setHeader("User-Agent", "Utopia API Wrapper Bot") // add request header
.header("Content-Type", "application/json")
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
// print status code
System.out.println(response.statusCode());
// print response body
System.out.println(response.body());
}
}