diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2016-04-09 15:53:24 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2016-04-09 15:53:24 -0700 |
commit | 371ccae3d1f31ec38f4af77fb7fcd175d49b3cd5 (patch) | |
tree | 38c4f1e8828f9af9c4b77a173bee0d312b321698 /src/main/java/com/p4square/f1oauth/F1User.java | |
parent | bbf907e51dfcf157bdee24dead1d531122aa25db (diff) | |
parent | 3102d8bce3426d9cf41aeaf201c360d342677770 (diff) |
Merge pull request #10 from PuyallupFoursquare/maven
Switching from Ivy+Ant to Maven.
Diffstat (limited to 'src/main/java/com/p4square/f1oauth/F1User.java')
-rw-r--r-- | src/main/java/com/p4square/f1oauth/F1User.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/com/p4square/f1oauth/F1User.java b/src/main/java/com/p4square/f1oauth/F1User.java new file mode 100644 index 0000000..e5ab487 --- /dev/null +++ b/src/main/java/com/p4square/f1oauth/F1User.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014 Jesse Morgan + */ + +package com.p4square.f1oauth; + +import java.util.Map; + +import com.p4square.restlet.oauth.OAuthException; +import com.p4square.restlet.oauth.OAuthUser; + +/** + * + * @author Jesse Morgan <jesse@jesterpm.net> + */ +public class F1User extends OAuthUser { + public static final String ID = "@id"; + public static final String FIRST_NAME = "firstName"; + public static final String LAST_NAME = "lastName"; + public static final String ICODE = "@iCode"; + + private final Map mData; + + /** + * Copy the user information from user into a new F1User. + * + * @param user Original user. + * @param data F1 Person Record. + * @throws IllegalStateException if data.get("person") is null. + */ + public F1User(OAuthUser user, Map data) { + super(user.getLocation(), user.getToken()); + + mData = (Map) data.get("person"); + if (mData == null) { + throw new IllegalStateException("Bad data"); + } + + setIdentifier(getString(ID)); + setFirstName(getString(FIRST_NAME)); + setLastName(getString(LAST_NAME)); + } + + /** + * Get a String from the map. + * + * @param key The map key. + * @return The value associated with the key, or null. + */ + public String getString(String key) { + Object blob = get(key); + + if (blob instanceof String) { + return (String) blob; + + } else { + return null; + } + } + + /** + * Fetch an object from the F1 record. + * + * @param key The map key + * @return The object in the map or null. + */ + public Object get(String key) { + return mData.get(key); + } +} |