~ubuntuone-client-engineering/ubuntu-sso-java-library/trunk

« back to all changes in this revision

Viewing changes to src/main/com/ubuntu/sso/entry/AccountResponse.java

  • Committer: Michał Karnicki
  • Date: 2012-07-05 11:27:18 UTC
  • Revision ID: mkarnicki@gmail.com-20120705112718-i4kyb1a7qwte3bh9
Moved files around for better directory structure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ubuntu Single Sign On Java Client
 
3
 * 
 
4
 * Copyright (C) 2011 Canonical Ltd.
 
5
 * Author: Michał Karnicki <michal.karnicki@canonical.com>
 
6
 *   
 
7
 * This file is part of Ubuntu SSO Java Client.
 
8
 *  
 
9
 * This program is free software: you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Affero General Public License as
 
11
 * published by the Free Software Foundation, either version 3 of the
 
12
 * License, or (at your option) any later version.
 
13
 *  
 
14
 * This program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Affero General Public License for more details.
 
18
 *  
 
19
 * You should have received a copy of the GNU Affero General Public License
 
20
 * along with this program. If not, see http://www.gnu.org/licenses 
 
21
 */
 
22
 
 
23
package com.ubuntu.sso.entry;
 
24
 
 
25
import java.util.ArrayList;
 
26
 
 
27
import org.json.JSONException;
 
28
import org.json.JSONObject;
 
29
 
 
30
import com.ubuntu.sso.util.JsonUtil;
 
31
 
 
32
public class AccountResponse extends ServerResponse {
 
33
        protected static final String JSON_DISPLAYNAME_KEY = "displayname";
 
34
        protected static final String JSON_OPENID_IDENTIFIER_KEY = "openid_identifier";
 
35
        protected static final String JSON_PREFERRED_EMAIL_KEY = "preferred_email";
 
36
        protected static final String JSON_VERIFIED_EMAILS = "verified_emails";
 
37
        protected static final String JSON_UNVERIFIED_EMAILS = "unverified_emails";
 
38
        
 
39
        private final String displayname;
 
40
        private final String openidIdentifier;
 
41
        private final String preferredEmail;
 
42
        private final ArrayList<String> verifiedEmails;
 
43
        private final ArrayList<String> unverifiedEmails;
 
44
 
 
45
        public AccountResponse(JSONObject json) throws JSONException {
 
46
                super(json);
 
47
                displayname = json.getString(JSON_DISPLAYNAME_KEY);
 
48
                openidIdentifier = json.getString(JSON_OPENID_IDENTIFIER_KEY);
 
49
                preferredEmail = json.getString(JSON_PREFERRED_EMAIL_KEY);
 
50
                verifiedEmails = JsonUtil.jsonArrayToArrayList(
 
51
                                json.getJSONArray(JSON_VERIFIED_EMAILS));
 
52
                unverifiedEmails = JsonUtil.jsonArrayToArrayList(
 
53
                                json.getJSONArray(JSON_UNVERIFIED_EMAILS));
 
54
        }
 
55
 
 
56
        public String getDisplayname() {
 
57
                return displayname;
 
58
        }
 
59
 
 
60
        public String getOpenidIdentifier() {
 
61
                return openidIdentifier;
 
62
        }
 
63
 
 
64
        public String getPreferredEmail() {
 
65
                return preferredEmail;
 
66
        }
 
67
 
 
68
        public ArrayList<String> getVerifiedEmails() {
 
69
                return verifiedEmails;
 
70
        }
 
71
 
 
72
        public ArrayList<String> getUnverifiedEmails() {
 
73
                return unverifiedEmails;
 
74
        }
 
75
 
 
76
        @Override
 
77
        public String toString() {
 
78
                StringBuilder builder = new StringBuilder();
 
79
                builder.append("AccountResponse [displayname=");
 
80
                builder.append(displayname);
 
81
                builder.append(", openidIdentifier=");
 
82
                builder.append(openidIdentifier);
 
83
                builder.append(", preferredEmail=");
 
84
                builder.append(preferredEmail);
 
85
                builder.append(", unverifiedEmails=");
 
86
                builder.append(unverifiedEmails);
 
87
                builder.append(", verifiedEmails=");
 
88
                builder.append(verifiedEmails);
 
89
                builder.append(", status=");
 
90
                builder.append(status);
 
91
                builder.append(", message=");
 
92
                builder.append(message);
 
93
                builder.append(", errors=");
 
94
                builder.append(errors);
 
95
                builder.append("]");
 
96
                return builder.toString();
 
97
        }
 
98
}