-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathInvite.java
More file actions
72 lines (61 loc) · 2.47 KB
/
Invite.java
File metadata and controls
72 lines (61 loc) · 2.47 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package slackinvite;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.*;
/**
*
* @author mage
*/
public final class Invite {
public final String TOKEN = "";
public final String[] EMAILS = new String[]{"email1","email2","email3"};
public final String MENTORS = "CHANNELID1,CHANNELID2,CHANNELID3,CHANNELID4";
public String charset = "UTF-8";
public final String FACILITATORS = "CHANNELID1,CHANNELID2,CHANNELID3,CHANNELID4";
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new Invite().sendInvites();
}
public void sendInvites() {
for (String email : this.EMAILS) {
String slackUrl = "https://slack.com/api/users.admin.invite";
try {
String query = String.format("token=%s&email=%s&channels=%s&resend=%s",
URLEncoder.encode(TOKEN, charset),
URLEncoder.encode(email, charset),
URLEncoder.encode(MENTORS, charset),
URLEncoder.encode("true", charset));
URLConnection connection = new URL(slackUrl + "?" + query).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
InputStream response = connection.getInputStream();
//Parse JSON Response
JSONObject obj = new JSONObject(convertStreamToString(response));
//write out the response body
System.out.println("*** Response for '"+email+"' ***");
System.out.println(obj);
System.out.println('\n');
}
catch (JSONException ex) {
Logger.getLogger(Invite.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ioE) {
throw new UncheckedIOException(ioE);
}
}
}
public static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
}