|
@@ -1,18 +1,18 @@
|
1
|
|
-package idtest;
|
|
1
|
+package id;
|
2
|
2
|
|
3
|
3
|
import shellutilities.Console;
|
4
|
4
|
import shellutilities.RequestType;
|
5
|
5
|
import shellutilities.YouAreEll;
|
6
|
6
|
|
7
|
|
-import java.io.IOException;
|
8
|
|
-
|
9
|
7
|
public class IdController {
|
|
8
|
+
|
10
|
9
|
private YouAreEll url;
|
11
|
10
|
private final String MAIN_URL = "/ids";
|
12
|
11
|
private Console c;
|
13
|
12
|
private String[] userLine;
|
14
|
13
|
private int size;
|
15
|
14
|
|
|
15
|
+
|
16
|
16
|
public IdController(String [] cmds) {
|
17
|
17
|
c = new Console();
|
18
|
18
|
url = new YouAreEll();
|
|
@@ -20,12 +20,14 @@ public class IdController {
|
20
|
20
|
size = cmds.length;
|
21
|
21
|
}
|
22
|
22
|
|
23
|
|
- public void idController() throws IOException {
|
|
23
|
+ public void setUrl(YouAreEll url) {
|
|
24
|
+ this.url = url;
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ public void idController() {
|
24
|
28
|
|
25
|
29
|
if (size > 1) {
|
26
|
|
- Id tempId = idCreator(getSpecificId(userLine[2]).replaceAll("^\"|\"$", ""),
|
27
|
|
- userLine[1],
|
28
|
|
- userLine[2]);
|
|
30
|
+ Id tempId = idCreator();
|
29
|
31
|
|
30
|
32
|
if (!idExists(userLine[2])) {
|
31
|
33
|
c.print("Putting updated entry");
|
|
@@ -38,33 +40,33 @@ public class IdController {
|
38
|
40
|
} else {
|
39
|
41
|
try {
|
40
|
42
|
PrettyPrintId.prettyPrintJsonArray(get_ids());
|
41
|
|
- } catch (IOException e) {
|
|
43
|
+ } catch (Exception e) {
|
42
|
44
|
c.print("Could not gather Id's try again?");
|
43
|
45
|
}
|
44
|
46
|
}
|
45
|
47
|
}
|
46
|
48
|
|
47
|
|
- public boolean idExists(String github) throws IOException {
|
|
49
|
+ public boolean idExists(String github) {
|
48
|
50
|
return (getSpecificId(github).equals(""));
|
49
|
51
|
}
|
50
|
52
|
|
51
|
|
- public static Id idCreator(String id, String name, String github) {
|
52
|
|
- return new Id(id, name, github);
|
|
53
|
+ public Id idCreator() {
|
|
54
|
+ return new Id("", userLine[1], userLine[2]);
|
53
|
55
|
}
|
54
|
56
|
|
55
|
|
- private String get_ids() throws IOException {
|
|
57
|
+ private String get_ids() {
|
56
|
58
|
return url.MakeURLCall(MAIN_URL, RequestType.GET, "");
|
57
|
59
|
}
|
58
|
60
|
|
59
|
|
- private String getSpecificId(String github) throws IOException {
|
|
61
|
+ private String getSpecificId(String github){
|
60
|
62
|
return url.MakeURLCall(MAIN_URL + "/" + github, RequestType.GET, "");
|
61
|
63
|
}
|
62
|
64
|
|
63
|
|
- private String post_id(String payload) throws IOException {
|
|
65
|
+ private String post_id(String payload) {
|
64
|
66
|
return url.MakeURLCall(MAIN_URL, RequestType.POST, payload);
|
65
|
67
|
}
|
66
|
68
|
|
67
|
|
- private String put_id(String payload) throws IOException {
|
|
69
|
+ private String put_id(String payload) {
|
68
|
70
|
return url.MakeURLCall(MAIN_URL, RequestType.PUT, payload);
|
69
|
71
|
}
|
70
|
72
|
|