/* 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; /** * Created by vadim on 16.07.14. */ public class PlumberIncidentsResponseList extends PlumberResponse { private PlumberIncidentsResponse[] incidents; private PlumberStatus status; public PlumberIncidentsResponseList(String json) { super(json); } @Override protected void fromJson(String json) { JSONArray jsonArr = null; if (json == null) { status = PlumberStatus.FAILURE; incidents = new PlumberIncidentsResponse[0]; return; } try { jsonArr = new JSONArray(json); incidents = new PlumberIncidentsResponse[jsonArr.length()]; for (int i = 0; i < jsonArr.length(); i++) { incidents[i] = new PlumberIncidentsResponse(jsonArr.optJSONObject(i)); } status = PlumberStatus.SUCCESS; } catch (JSONException e) { if (BuildConfig.DEBUG) Log.e(Config.TAG, "Error parsing json", e); incidents = new PlumberIncidentsResponse[0]; status = PlumberStatus.FAILURE; } } @Override protected void fromJson(JSONObject json) { // nothing, because we need to override the version with String } public PlumberIncidentsResponse[] getIncidents() { return incidents; } public PlumberStatus getStatus() { return status; } }