/*
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 org.json.JSONException;
import org.json.JSONObject;
/**
* Created by cianci on 11.08.14.
*/
public class PlumberSubscriptionResponse extends PlumberResponse {
private String phone;
private String name;
private int id;
private int daysValid;
private boolean active;
private double price;
private String description;
private long validTill;
private PlumberStatus status;
public PlumberSubscriptionResponse() {
fromJson((JSONObject) null);
}
public PlumberSubscriptionResponse(String json) {
super(json);
}
public PlumberSubscriptionResponse(JSONObject json) {
super(json);
}
public String getPhone() {
return phone;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public int getDaysValid() {
return daysValid;
}
public boolean isActive() {
return active;
}
public double getPrice() {
return price;
}
public String getDescription() {
return description;
}
public long getValidTill() {
return validTill;
}
public PlumberStatus getStatus() {
return status;
}
@Override
public String toString() {
return "PlumberSubscriptionResponse{" +
"phone='" + phone + '\'' +
", name='" + name + '\'' +
", id=" + id +
", days_valid=" + daysValid +
", active=" + active +
", price=" + price +
", description='" + description + '\'' +
", validTill=" + validTill +
", status='" + status + '\'' +
'}';
}
@Override
protected void fromJson(JSONObject json) {
if (json == null) {
return;
}
phone = json.optString("phone");
validTill = json.optLong("valid_till", -1);
status = PlumberStatus.fromString(json.optString("status"));
//subscription list does not have the keyword subscription..
if (json.has("subscription")) {
try {
JSONObject jsonSubscr = json.getJSONObject("subscription");
daysValid = jsonSubscr.optInt("days_valid", -1);
name = jsonSubscr.optString("name");
active = jsonSubscr.optBoolean("active", false);
price = jsonSubscr.optDouble("price", -1);
id = jsonSubscr.optInt("id", -1);
description = jsonSubscr.optString("desc");
} catch (JSONException e) {
return;
}
} else {
daysValid = json.optInt("days_valid", -1);
name = json.optString("name");
active = json.optBoolean("active", false);
price = json.optDouble("price", -1);
id = json.optInt("id", -1);
description = json.optString("desc");
}
}
}