/* Swisscom Safe Connect Copyright (C) 2014 Swisscom This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.model; import android.util.Log; import com.swisscom.safeconnect.BuildConfig; import com.swisscom.safeconnect.utils.Config; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.Arrays; /** * Created by cianci on 9/22/14. */ public class PlumberLastConnectionLogResponseList extends PlumberResponse { private PlumberLastConnectionLogResponse[] connectionLogs; private String deviceId; private String internalIp; private String internalPublicIp; private double latitude; private double longitude; private String countryCode; private String city; private PlumberStatus status; public PlumberLastConnectionLogResponseList(String json) { super(json); } @Override protected void fromJson(JSONObject json) { if (json == null) { status = PlumberStatus.FAILURE; connectionLogs = new PlumberLastConnectionLogResponse[0]; return; } deviceId = json.optString("device_id"); internalIp = json.optString("ip_int"); internalPublicIp = json.optString("ip_ext"); latitude = json.optDouble("latitude"); longitude = json.optDouble("longitude"); countryCode = json.optString("country_code"); city = json.optString("city"); try { JSONArray jsonArray = json.getJSONArray("connections"); if (jsonArray != null) { connectionLogs = new PlumberLastConnectionLogResponse[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { connectionLogs[i] = new PlumberLastConnectionLogResponse(jsonArray.optJSONObject(i)); } } else { connectionLogs = new PlumberLastConnectionLogResponse[0]; } status = PlumberStatus.SUCCESS; } catch (JSONException e) { if (BuildConfig.DEBUG) Log.e(Config.TAG, "Error parsing json", e); connectionLogs = new PlumberLastConnectionLogResponse[0]; status = PlumberStatus.FAILURE; } } public PlumberLastConnectionLogResponse[] getConnectionLogs() { return connectionLogs; } public PlumberStatus getPlumberStatus() { return status; } public String getDeviceId() { return deviceId; } public String getInternalIp() { return internalIp; } public String getInternalPublicIp() { return internalPublicIp; } public double getLatitude() { return latitude; } public double getLongitude() { return longitude; } public String getCountryCode() { return countryCode; } public String getCity() { return city; } @Override public String toString() { return "PlumberLastConnectionLogResponseList{" + "connectionLogs=" + Arrays.toString(connectionLogs) + ", deviceId='" + deviceId + '\'' + ", internalIp='" + internalIp + '\'' + ", internalPublicIp='" + internalPublicIp + '\'' + ", latitude=" + latitude + ", longitude=" + longitude + ", countryCode='" + countryCode + '\'' + ", city='" + city + '\'' + ", status=" + status + '}'; } }