-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSite.java
More file actions
92 lines (77 loc) · 1.88 KB
/
Copy pathSite.java
File metadata and controls
92 lines (77 loc) · 1.88 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
/**
* Traq Java API Client.
*
* @author Jack Polgar <jack@polgar.id.au>
* @license Apache-2.0
*/
package traq.models;
import java.io.IOException;
import java.util.ArrayList;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import traq.API;
/**
* Site model.
*/
public class Site {
private static String name;
private static String url;
/**
* @param url site URL
*/
public Site(String url) {
this.name = null;
this.url = url;
}
/**
* @param name site name
* @param url site URL
*/
public Site(String name, String url) {
this.name = name;
this.url = url;
}
/**
* @return sites name
*/
public String getName() {
return name;
}
/**
* @return sites URL
*/
public String getUrl() {
return url;
}
/**
* Fetch a JSON response from the specified path relative to the sites URL.
*
* @param path path to fetch
*
* @return JsonElement
*/
public JsonElement fetch(String path) {
try {
return API.fetch(this.url + path);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* Get an array list of projects the site contains.
*
* @return array of sites
*/
public ArrayList<Project> getProjects() {
ArrayList<Project> projects = new ArrayList<Project>();
JsonArray jsonProjects = fetch("/projects.json").getAsJsonArray();
for (JsonElement o: jsonProjects) {
JsonObject obj = o.getAsJsonObject();
Project project = new Project(obj.get("id").getAsInt(), obj.get("name").getAsString(), obj.get("slug").getAsString(), obj.get("info").getAsString());
projects.add(project);
}
return projects;
}
}