diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2014-08-28 07:34:22 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2014-08-28 07:34:22 -0700 |
commit | 66469ff2f76ac916e289e066377570b38554fdcc (patch) | |
tree | 98c576775605bb46b012cc28646ca023f38da319 /src/com/p4square/f1oauth | |
parent | 6eba410e5eb53ee887e430f4f98ba03ffaa2a474 (diff) |
Rough outline of the F1 attribute logic.
Parts of addAttribute have been implemented in F1User, but I may move it
out into a general F1 API class.
Diffstat (limited to 'src/com/p4square/f1oauth')
-rw-r--r-- | src/com/p4square/f1oauth/F1OAuthHelper.java | 7 | ||||
-rw-r--r-- | src/com/p4square/f1oauth/F1User.java | 72 | ||||
-rw-r--r-- | src/com/p4square/f1oauth/SecondPartyVerifier.java | 2 |
3 files changed, 79 insertions, 2 deletions
diff --git a/src/com/p4square/f1oauth/F1OAuthHelper.java b/src/com/p4square/f1oauth/F1OAuthHelper.java index b5241c4..187fb6b 100644 --- a/src/com/p4square/f1oauth/F1OAuthHelper.java +++ b/src/com/p4square/f1oauth/F1OAuthHelper.java @@ -66,6 +66,13 @@ public class F1OAuthHelper extends OAuthHelper { } /** + * @return The base url for the F1 API, ending with a slash. + */ + public String getBaseUrl() { + return mBaseUrl; + } + + /** * @return the URL for the initial RequestToken request. */ protected String getRequestTokenUrl() { diff --git a/src/com/p4square/f1oauth/F1User.java b/src/com/p4square/f1oauth/F1User.java index e5ab487..942f534 100644 --- a/src/com/p4square/f1oauth/F1User.java +++ b/src/com/p4square/f1oauth/F1User.java @@ -19,6 +19,7 @@ public class F1User extends OAuthUser { public static final String LAST_NAME = "lastName"; public static final String ICODE = "@iCode"; + private final String mBaseUrl; private final Map mData; /** @@ -28,9 +29,10 @@ public class F1User extends OAuthUser { * @param data F1 Person Record. * @throws IllegalStateException if data.get("person") is null. */ - public F1User(OAuthUser user, Map data) { + public F1User(String baseUrl, OAuthUser user, Map data) { super(user.getLocation(), user.getToken()); + mBaseUrl = baseUrl; mData = (Map) data.get("person"); if (mData == null) { throw new IllegalStateException("Bad data"); @@ -67,4 +69,72 @@ public class F1User extends OAuthUser { public Object get(String key) { return mData.get(key); } + + /** + * @return the F1 API base url. + */ + public String getBaseUrl() { + return mBaseUrl; + } + + /* + public addAttribute(Attribute attribute, String comment) { + String baseUrl = getBaseUrl(); + Map newAttributeTemplate = null; + + // Get Attribute Template + Request request = new Request(Method.GET, + baseUrl + "People/" + getIdentifier() + "/Attributes/new.json"); + request.setChallengeResponse(getChallengeResponse()); + Response response = getContext().getClientDispatcher().handle(request); + + Representation representation = response.getEntity(); + try { + Status status = response.getStatus(); + if (status.isSuccess()) { + JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class); + newAttributeTemplate = entity.getObject(); + } + + } finally { + if (representation != null) { + representation.release(); + } + } + + if (newAttributeTemplate == null) { + LOG.error("Could not retrieve attribute template!"); + return; + } + + // Populate Attribute Template + + + // POST new attribute + Request request = new Request(Method.POST, + baseUrl + "People/" + getIdentifier() + "/Attributes.json"); + request.setChallengeResponse(getChallengeResponse()); + Response response = getContext().getClientDispatcher().handle(request); + + Representation representation = response.getEntity(); + try { + Status status = response.getStatus(); + if (status.isSuccess()) { + JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class); + newAttributeTemplate = entity.getObject(); + } + + } finally { + if (representation != null) { + representation.release(); + } + } + + if (newAttributeTemplate == null) { + LOG.error("Could retrieve attribute template!"); + return; + } + + } + */ } diff --git a/src/com/p4square/f1oauth/SecondPartyVerifier.java b/src/com/p4square/f1oauth/SecondPartyVerifier.java index b1afcfa..9fb771f 100644 --- a/src/com/p4square/f1oauth/SecondPartyVerifier.java +++ b/src/com/p4square/f1oauth/SecondPartyVerifier.java @@ -79,7 +79,7 @@ public class SecondPartyVerifier implements Verifier { if (status.isSuccess()) { JacksonRepresentation<Map> entity = new JacksonRepresentation<Map>(response.getEntity(), Map.class); Map data = entity.getObject(); - return new F1User(user, data); + return new F1User(mHelper.getBaseUrl(), user, data); } else { throw new OAuthException(status); |