-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathexample.java
More file actions
92 lines (79 loc) · 2.67 KB
/
Copy pathexample.java
File metadata and controls
92 lines (79 loc) · 2.67 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
// Demonstrates how to get conferences list add new conference
// author Paweł Brydziński <pbrydzinski@clickmeeting.com>
// http://www.clickmeeting.com/
// usage: javac example.java && java example
import java.net.*;
import java.io.*;
import java.util.*;
import java.text.*;
public class example
{
static String api_key = "API KEY";
static String api_url = "https://api.clickmeeting.com/v1/";
public static void main(String[] args)
{
getConferences();
createConference();
}
public static void getConferences()
{
try
{
URL url = new URL(api_url+"conferences");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty( "X-Api-Key", api_key);
System.out.println(readOutput(connection));
}
catch(IOException e)
{
e.printStackTrace();
}
}
public static void createConference()
{
try
{
Date date = new Date((new Date()).getTime()+(1000 * 60 * 60 * 24 *2));
String data = "";
data += "&name=APItest";
data += "&room_type=meeting";
data += "&permanent_room=0";
data += "&access_type=1";
data += "&lobby_description=This is test for room created by API.";
data += "&starts_at="+(new SimpleDateFormat("yyyy-MM-dd hh:mm")).format(date)+"";
data += "&duration=1";
URL url = new URL(api_url+"conferences");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod( "POST" );
connection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded" );
connection.setRequestProperty( "Content-Length", String.valueOf(data.length()));
connection.setRequestProperty( "X-Api-Key", api_key);
OutputStream os = connection.getOutputStream();
os.write( data.getBytes() );
System.out.println(readOutput(connection));
}
catch(IOException e)
{
e.printStackTrace();
}
}
public static String readOutput(HttpURLConnection connection)
{
String string = "";
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String current;
while((current = in.readLine()) != null)
{
string += current;
}
}
catch(IOException e)
{
e.printStackTrace();
}
return string;
}
}