package eu.hsrw.ias.ggd; import Credentials.UserCredentials; import Files.WriteFile; import JSON_Unpack.ReadSensors4Partner; import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; public class ApiCall { private static String token = "0"; private static String oldId = "1"; public static HashMap FetchDataFromApi() throws Exception { UserCredentials userCredentials = new UserCredentials(); final String username = userCredentials.getUsername(); final String password = userCredentials.getPassword(); final String homeRoot = UserCredentials.getHomeRoot(); String outputToken; WriteFile writingIntoFile = new WriteFile(); Date now; // to display current time now = new Date(); HashMap finalOutput = new HashMap(); if (token.equals(oldId)) { //do nothing } else { try { outputToken = SecurityToken.OnCallMethod(username, password); JSONObject obj = new JSONObject(outputToken); token = obj.getString("id"); writingIntoFile.WriteFile(homeRoot + "securityToken.txt", token); oldId = token; } catch (Exception e) { e.printStackTrace(); } } ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner(); ArrayList outputValue = (readSensors4Partner.FetchSensor4Box("Germes", token)); for(int i=0;i