|
| 1 | +package pl.smsapi.api.action.contacts; |
| 2 | + |
| 3 | +import org.json.JSONArray; |
| 4 | +import org.json.JSONObject; |
| 5 | +import pl.smsapi.api.action.contacts.groups.Groups; |
| 6 | +import pl.smsapi.api.response.Response; |
| 7 | + |
| 8 | +public class Contact implements Response { |
| 9 | + |
| 10 | + public final String id; |
| 11 | + public final String firstName; |
| 12 | + public final String lastName; |
| 13 | + public final String birthdayDate; |
| 14 | + public final String phoneNumber; |
| 15 | + public final String email; |
| 16 | + public final String gender; |
| 17 | + public final String city; |
| 18 | + public final String country; |
| 19 | + public final String dateCreated; |
| 20 | + public final String dateUpdated; |
| 21 | + public final String description; |
| 22 | + public final Groups groups; |
| 23 | + public final String source; |
| 24 | + |
| 25 | + private Contact(String id, String firstName, String lastName, String birthdayDate, String phoneNumber, String email, String gender, String city, String country, String dateCreated, String dateUpdated, String description, JSONArray groups, String source) { |
| 26 | + this.id = id; |
| 27 | + this.firstName = firstName; |
| 28 | + this.lastName = lastName; |
| 29 | + this.birthdayDate = birthdayDate; |
| 30 | + this.phoneNumber = phoneNumber; |
| 31 | + this.email = email; |
| 32 | + this.gender = gender; |
| 33 | + this.city = city; |
| 34 | + this.country = country; |
| 35 | + this.dateCreated = dateCreated; |
| 36 | + this.dateUpdated = dateUpdated; |
| 37 | + this.description = description; |
| 38 | + this.groups = new Groups.GroupsFromJsonFactory().createFrom(groups); |
| 39 | + this.source = source; |
| 40 | + } |
| 41 | + |
| 42 | + public static class ContactFromJsonFactory { |
| 43 | + public Contact createFrom(JSONObject jsonObject) { |
| 44 | + return new Contact( |
| 45 | + jsonObject.getString("id"), |
| 46 | + jsonObject.optString("first_name", null), |
| 47 | + jsonObject.optString("last_name", null), |
| 48 | + jsonObject.optString("birthday_date", null), |
| 49 | + jsonObject.optString("phone_number", null), |
| 50 | + jsonObject.optString("email", null), |
| 51 | + jsonObject.getString("gender"), |
| 52 | + jsonObject.optString("city", null), |
| 53 | + jsonObject.optString("country", null), |
| 54 | + jsonObject.getString("date_created"), |
| 55 | + jsonObject.getString("date_updated"), |
| 56 | + jsonObject.optString("description", null), |
| 57 | + jsonObject.getJSONArray("groups"), |
| 58 | + jsonObject.optString("source", null) |
| 59 | + ); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments