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