-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMachine.java
More file actions
45 lines (32 loc) · 1.08 KB
/
Machine.java
File metadata and controls
45 lines (32 loc) · 1.08 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
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
class Machine {
private String rawStats;
Machine() {
rawStats = "";
}
//updates raw stats and returns them
String updateStats(String userName, String userID) {
try {
BufferedReader in;
URL url = new URL(constructURL(userName, userID));
URLConnection uc = url.openConnection();
uc.addRequestProperty("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
HttpsURLConnection con = (HttpsURLConnection) uc;
in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
rawStats = in.readLine();
} catch (IOException e) {
//Do we have internet?
}
return rawStats;
}
String getRawStats() {
return rawStats;
}
private String constructURL(String userName, String userID) {
return "https://owapi.net/api/v3/u/" + userName + "-" + userID + "/stats";
}
}