/*
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.JSONException;
import org.json.JSONObject;
/**
* all responses extend this class
*/
public abstract class PlumberResponse {
public PlumberResponse() {}
public PlumberResponse(String json) {
fromJson(json);
}
public PlumberResponse(JSONObject json) {
fromJson(json);
}
/**
* extracts the fields from json relevant to this object
* @param json JSON object acquired from the HTTP response
*/
protected abstract void fromJson(JSONObject json);
protected void fromJson(String jsonStr) {
JSONObject json = null;
try {
json = new JSONObject(jsonStr);
} catch (JSONException e) {
if (BuildConfig.DEBUG) Log.e(Config.TAG, "failed to parse json", e);
} catch (NullPointerException e){
if (BuildConfig.DEBUG) Log.e(Config.TAG, "json was null", e);
}
fromJson(json);
}
}