|
12 | 12 | import okhttp3.Request;
|
13 | 13 | import okhttp3.RequestBody;
|
14 | 14 | import okhttp3.Response;
|
15 |
| -import utils.LocProperties; |
16 | 15 | import utils.entities.OCSpace;
|
17 | 16 | import utils.log.Log;
|
18 | 17 |
|
@@ -50,7 +49,22 @@ public OCSpace getPersonal() throws IOException {
|
50 | 49 | String url = urlServer + graphPath + myDrives;
|
51 | 50 | Request request = getRequest(url);
|
52 | 51 | Response response = httpClient.newCall(request).execute();
|
53 |
| - return getPersonal(response); |
| 52 | + String json = response.body().string(); |
| 53 | + OCSpace personal = new OCSpace(); |
| 54 | + JSONObject obj = new JSONObject(json); |
| 55 | + JSONArray value = obj.getJSONArray("value"); |
| 56 | + for (int i = 0; i < value.length(); i++) { |
| 57 | + JSONObject jsonObject = value.getJSONObject(i); |
| 58 | + String type = jsonObject.getString("driveType"); |
| 59 | + if (type.equals("personal")) { //Just for user created spaces |
| 60 | + personal.setType(jsonObject.getString("driveType")); |
| 61 | + personal.setId(jsonObject.getString("id")); |
| 62 | + personal.setName(jsonObject.getString("name")); |
| 63 | + Log.log(Level.FINE, "Space id returned: " + |
| 64 | + personal.getId() + " " + personal.getName()); |
| 65 | + } |
| 66 | + } |
| 67 | + return personal; |
54 | 68 | }
|
55 | 69 |
|
56 | 70 | private RequestBody createBodySpace(String name, String description) {
|
@@ -110,22 +124,6 @@ private Request deleteSpaceRequest(String url) {
|
110 | 124 | return request;
|
111 | 125 | }
|
112 | 126 |
|
113 |
| - private String getUserId(String user) throws IOException { |
114 |
| - Log.log(Level.FINE, "GET id OF: " + user); |
115 |
| - String url = urlServer + graphPath + "me"; |
116 |
| - Request request = getRequest(url); |
117 |
| - Response response = httpClient.newCall(request).execute(); |
118 |
| - return getIdFromResponse(response); |
119 |
| - } |
120 |
| - |
121 |
| - private String getIdFromResponse(Response httpResponse) throws IOException { |
122 |
| - String json = httpResponse.body().string(); |
123 |
| - JSONObject obj = new JSONObject(json); |
124 |
| - String id = obj.getString("id"); |
125 |
| - Log.log(Level.FINE, "ID of user: " + id); |
126 |
| - return id; |
127 |
| - } |
128 |
| - |
129 | 127 | private String getSpaceIdFromName(String name, String description) throws IOException {
|
130 | 128 | List<OCSpace> mySpaces = getMySpaces();
|
131 | 129 | for (OCSpace space : mySpaces) {
|
@@ -161,24 +159,4 @@ private List<OCSpace> getSpacesFromResponse(Response httpResponse) throws IOExce
|
161 | 159 | }
|
162 | 160 | return spaces;
|
163 | 161 | }
|
164 |
| - |
165 |
| - //Returns personal space. Assuming that there is only one personal space |
166 |
| - private OCSpace getPersonal(Response httpResponse) throws IOException { |
167 |
| - String json = httpResponse.body().string(); |
168 |
| - OCSpace personal = new OCSpace(); |
169 |
| - JSONObject obj = new JSONObject(json); |
170 |
| - JSONArray value = obj.getJSONArray("value"); |
171 |
| - for (int i = 0; i < value.length(); i++) { |
172 |
| - JSONObject jsonObject = value.getJSONObject(i); |
173 |
| - String type = jsonObject.getString("driveType"); |
174 |
| - if (type.equals("personal")) { //Just for user created spaces |
175 |
| - personal.setType(jsonObject.getString("driveType")); |
176 |
| - personal.setId(jsonObject.getString("id")); |
177 |
| - personal.setName(jsonObject.getString("name")); |
178 |
| - Log.log(Level.FINE, "Space id returned: " + |
179 |
| - personal.getId() + " " + personal.getName()); |
180 |
| - } |
181 |
| - } |
182 |
| - return personal; |
183 |
| - } |
184 | 162 | }
|
0 commit comments