-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Sample
More file actions
111 lines (97 loc) · 5.07 KB
/
Java Sample
File metadata and controls
111 lines (97 loc) · 5.07 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
public class JavaAPISample {
public static void main(String[] args) throws IOException {
JavaAPISample apiEvent = new JavaAPISample();
apiEvent.GetEvent();
apiEvent.CreateorUpdateEvent();
}
//Get an Event
private void GetEvent() throws IOException {
String url = "https://{customerid}.api2.test.queue-it.net/2_0/event/{myEventId}";
String apiKey = "Your api key available at /account/security page under APi-keys tab in Go platform";
try {
//make connection
URL resource = new URL(url);
URLConnection connection = resource.openConnection();
//It Content Type is so importan to support JSON call
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("api-key", apiKey);
//get result
BufferedReader result = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String inputLine;
while ((inputLine = result.readLine()) != null) {
response.append(inputLine);
System.out.println("Success! " + inputLine);
}
result.close();
}
catch (IOException ex) {
System.out.println("Error! " + ex);
//Use your favorit logging framework to log the exceptoin
}
}
//Create or update an Event
private void CreateorUpdateEvent() throws IOException {
String url = "https://{customerid}.api2.test.queue-it.net/2_0/event/{myEventId}";
String apiKey = "Your api key available at /account/security page under APi-keys tab in Go platform";
String eventData = "{\n"
+ " \"DisplayName\": \"My event display name\",\n"
+ " \"RedirectUrl\": \"https://www.ticketania.com/supersale\",\n"
+ " \"Description\": \"My event description\",\n"
+ " \"TimeZone\": \"UTC\",\n"
+ " \"TimeZonePostfix\": \"DST\",\n"
+ " \"PreQueueStartTime\": \"2018-05-05T08:47:34.0518179Z\",\n"
+ " \"EventStartTime\": \"2018-05-05T09:17:34.0518179Z\",\n"
+ " \"EventEndTime\": \"2018-05-09T09:17:34.0518179Z\",\n"
+ " \"EventCulture\": \"en-US\",\n"
+ " \"MaxNoOfRedirectsPrQueueId\": \"3\",\n"
+ " \"QueueNumberValidityInMinutes\": \"10\",\n"
+ " \"AfterEventLogic\": \"RedirectUsersToSpecialPage\",\n"
+ " \"AfterEventRedirectPage\": \"https://www.ticketania.com\",\n"
+ " \"AfterEventEndUserRedirectsEnabled\": null,\n"
+ " \"UseSSL\": \"Auto\",\n"
+ " \"JavaScriptSupportEnabled\": \"False\",\n"
+ " \"TargetUrlSupportEnabled\": \"True\",\n"
+ " \"SafetyNetMode\": \"OutputThroughput\",\n"
+ " \"KnowUserSecurity\": \"KnownUserV3\",\n"
+ " \"KnowUserSecretKey\": \"skfsdfjsgjfghsfjgjriwery83476weyf\",\n"
+ " \"CustomLayout\": \"Default layout by Queue-it\",\n"
+ " \"TargetUrlValidationRegex\": \"(?#validationrule)(^https?://([^/]*\\\\.)?ticketania\\\\.com($|/))\",\n"
+ " \"DomainAlias\": \"ttsale\",\n"
+ " \"BrowserCultureEnabled\": \"True\",\n"
+ " \"IdleQueueLogic\": \"RedirectUsersToSpecialPage\",\n"
+ " \"IdleQueueRedirectPage\": \"https://www.ticketania.com\",\n"
+ " \"CaptchaType\": null,\n"
+ " \"IsTest\": \"False\",\n"
+ " \"RequireKey\": null\n}";
try {
//It change the apostrophe char to double colon char, to form a correct JSON string
eventData = eventData.replace("'", "\"");
//make connection
URL resource = new URL(url);
HttpURLConnection connection = (HttpURLConnection) resource.openConnection();
//It Content Type is so importan to support JSON call
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("api-key", apiKey);
//use post mode
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
byte[] outputInBytes = eventData.getBytes("UTF-8");
OutputStream result = connection.getOutputStream();
result.write(outputInBytes);
result.close();
connection.getInputStream();
}
catch (IOException ex) {
System.out.println("Error! " + ex);
//Use your favorit logging framework to log the exceptoin
}
}
}