As well as updated some myspace specific endpoints. Added a new endpoint
which allows users
to get comments from their profile.
http://code.google.com/p/opensocial-java-client/source/detail?r=119
Added:
/trunk/java/samples/ProfileCommentsExample.java
/trunk/java/src/org/opensocial/client/OpenSocialRequestParameter.java
/trunk/java/src/org/opensocial/client/Token.java
/trunk/java/src/org/opensocial/data/MySpaceComment.java
/trunk/java/src/org/opensocial/data/OpenSocialField.java
/trunk/java/src/org/opensocial/data/OpenSocialObject.java
/trunk/java/src/org/opensocial/services/myspace/ProfileCommentsService.java
Deleted:
/trunk/java/src/org/opensocial/client/OpenSocialResponse.java
Modified:
/trunk/java/samples/StatusMoodExample.java
/trunk/java/src/org/opensocial/client/OpenSocialBatch.java
/trunk/java/src/org/opensocial/client/OpenSocialClient.java
/trunk/java/src/org/opensocial/client/OpenSocialHttpResponseMessage.java
/trunk/java/src/org/opensocial/client/OpenSocialUrl.java
/trunk/java/src/org/opensocial/providers/MySpaceProvider.java
/trunk/java/src/org/opensocial/services/myspace/StatusMoodService.java
=======================================
--- /dev/null
+++ /trunk/java/samples/ProfileCommentsExample.java Wed Oct 28 13:41:39 2009
@@ -0,0 +1,83 @@
+/* Copyright (c) 2008 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.opensocial.client.OpenSocialBatch;
+import org.opensocial.client.OpenSocialClient;
+import org.opensocial.client.OpenSocialHttpResponseMessage;
+import org.opensocial.data.MySpaceComment;
+import org.opensocial.providers.MySpaceProvider;
+
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+
+public class ProfileCommentsExample {
+
+ public static void main(String[] args) {
+
+ // Setup Client
+ OpenSocialClient c = new OpenSocialClient(new MySpaceProvider());
+ c.setProperty(OpenSocialClient.Property.DEBUG, "false");
+ c.setProperty(OpenSocialClient.Property.RPC_ENDPOINT, null);
+
c.setProperty(OpenSocialClient.Property.CONSUMER_SECRET, "20ab52223e684594a8050a8bfd4b06693ba9c9183ee24e1987be87746b1b03f8");
+
c.setProperty(OpenSocialClient.Property.CONSUMER_KEY, "http://www.myspace.com/495182150");
+ c.setProperty(OpenSocialClient.Property.VIEWER_ID, "495184236");
+
+ // Create Batch handler
+ OpenSocialBatch batch = new OpenSocialBatch();
+ Map<String, String> params = null;
+
+ try {
+ params = new HashMap<String, String>();
+ params.put("userId", "@me");
+ params.put("groupId", "@self");
+
+
batch.addRequest(c.getProfileCommentsService().get(params), "fetchProfileComment");
+ batch.send(c);
+
+ // Get a list of all response in request queue
+ Set<String> responses = batch.getResponseQueue();
+
+ // Interate through each response
+ for(Object id : responses) {
+ OpenSocialHttpResponseMessage resp =
batch.getResponse(id.toString());
+ System.out.println("\n"+id+" responded with
status: "+resp.getStatusCode()+" with "+resp.getTotalResults()+" results");
+
System.out.println("==============================================");
+
+ if(resp.getStatusCode() > 201) {
+ System.out.println(resp.getBodyString());
+ }else {
+ List<MySpaceComment> comments = resp.getCommentCollection();
+ MySpaceComment comment = null;
+ System.out.println(resp.getBodyString());
+ for(int i=0; i < comments.size(); i++) {
+ comment = comments.get(i);
+ System.out.println(comment.getField("postedDate"));
+ System.out.println(comment.getField("commentId"));
+ System.out.println(comment.getField("body"));
+ }
+ }
+ }
+ } catch (org.opensocial.client.OpenSocialRequestException e) {
+ System.out.println("OpenSocialRequestException thrown: " +
e.getMessage());
+ e.printStackTrace();
+ } catch (java.io.IOException e) {
+ System.out.println("IOException thrown: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+}
=======================================
--- /dev/null
+++ /trunk/java/src/org/opensocial/client/OpenSocialRequestParameter.java
Wed Oct 28 13:41:39 2009
@@ -0,0 +1,116 @@
+/* Copyright (c) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensocial.client;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.json.JSONObject;
+
+/**
+ * An object which represents an OpenSocial data request parameter.
Parameters
+ * can be single- or multi-valued (e.g. count is single-valued while
fields can
+ * have one or more values) or single- or multi-keyed.
+ *
+ * @author apij...@google.com (Jason Cooper)
+ */
+public class OpenSocialRequestParameter {
+ private List<String> valuesList = null;
+ private Map<String, String> valuesMap = null;
+
+ public OpenSocialRequestParameter(Map<String, String> valuesMap) {
+ this.valuesMap = valuesMap;
+ }
+
+ public OpenSocialRequestParameter(String[] values) {
+ valuesList = new ArrayList<String>(values.length);
+ this.addValues(values);
+ }
+
+ public OpenSocialRequestParameter(String value) {
+ valuesList = new ArrayList<String>(1);
+ this.addValue(value);
+ }
+
+ private void addValues(String[] values) {
+ this.valuesList.addAll(Arrays.asList(values));
+ }
+
+ private void addValue(String value) {
+ this.valuesList.add(value);
+ }
+
+ public Map<String, String> getValuesMap() {
+ return valuesMap;
+ }
+
+ public List<String> getValuesList() {
+ return valuesList;
+ }
+
+ public String getValuesString() {
+ if (valuesList != null) {
+ return getValuesListAsString();
+ }
+ else if (valuesMap != null) {
+ return getValuesMapAsString();
+ }
+ else {
+ return null;
+ }
+ }
+
+ public String getValuesListAsString() {
+ StringBuilder list = new StringBuilder();
+
+ for (int i = 0; i < valuesList.size(); i++) {
+ if (i != 0) {
+ list.append(",");
+ }
+
+ list.append(valuesList.get(i));
+ }
+
+ return list.toString();
+ }
+
+ public String getValuesMapAsString() {
+ JSONObject json = new JSONObject(valuesMap);
+ if (json == null) {
+ return null;
+ }
+
+ return json.toString();
+ }
+
+ /**
+ * @return true if the number of stored values is greater than one, false
+ * otherwise.
+ */
+ public boolean isMultivalued() {
+ return valuesList.size() > 1;
+ }
+
+ /**
+ * @return true if there are one or more key-value pairs associated with
this
+ * parameter.
+ */
+ public boolean isMultikeyed() {
+ return valuesMap != null;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/java/src/org/opensocial/client/Token.java Wed Oct 28 13:41:39
2009
@@ -0,0 +1,28 @@
+/* Copyright (c) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensocial.client;
+
+/**
+ * @author do...@google.com (Cassandra Doll)
+*/
+public class Token {
+ public String token, secret;
+
+ public Token(String token, String secret) {
+ this.token = token;
+ this.secret = secret;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/java/src/org/opensocial/data/MySpaceComment.java Wed Oct 28
13:41:39 2009
@@ -0,0 +1,12 @@
+package org.opensocial.data;
+
+import org.json.JSONException;
+
+ public class MySpaceComment extends OpenSocialModel {
+
+ public MySpaceComment(){}
+
+ public MySpaceComment(String json) throws JSONException {
+ super(json);
+ }
+}
=======================================
--- /dev/null
+++ /trunk/java/src/org/opensocial/data/OpenSocialField.java Wed Oct 28
13:41:39 2009
@@ -0,0 +1,144 @@
+/* Copyright (c) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.opensocial.data;
+
+import java.util.Collection;
+import java.util.Vector;
+
+/**
+ * An object representing a single property of an OpenSocial entity. These
+ * properties may have a single value or multiple values and these values
+ * can either consist of simple character strings or complex entities;
+ * for example, the "name" field of a Person instance can be modeled
+ * as an OpenSocialObject with "givenName" and "familyName" fields.
+ *
+ * @author Jason Cooper
+ */
+public class OpenSocialField {
+
+ private Collection<Object> values;
+ private boolean complex;
+
+ public OpenSocialField(boolean complex) {
+ this.complex = complex;
+
+ this.values = new Vector<Object>();
+ }
+
+ /**
+ * Stores passed object as a value.
+ */
+ public void addValue(Object o) {
+ this.values.add(o);
+ }
+
+ /**
+ * Returns the first stored value as a String. Returns null if no values
+ * have been associated with the instance.
+ */
+ public String getStringValue() {
+ if (this.values.size() == 0) {
+ return null;
+ }
+
+ Object[] objectValues = this.values.toArray();
+
+ if (this.complex == true) {
+ return objectValues[0].toString();
+ }
+
+ return (String) objectValues[0];
+ }
+
+ /**
+ * Returns the first stored value as an OpenSocialObject. Returns null if
+ * no values have been associated with the instance.
+ *
+ * @throws OpenSocialException if the complex instance variable is false,
+ * indicating that the values are stored as simple String
objects.
+ */
+ public OpenSocialObject getValue() throws OpenSocialException {
+ if (this.values.size() == 0) {
+ return null;
+ }
+ if (this.complex == false) {
+ throw new OpenSocialException(
+ "String-based field cannot be returned as an OpenSocialObject");
+ }
+
+ Object[] objectValues = this.values.toArray();
+ return (OpenSocialObject) objectValues[0];
+ }
+
+ /**
+ * Returns all stored values as a Java Collection of String objects.
+ */
+ public Collection<String> getStringValues() {
+ Collection<String> stringCollection =
+ new Vector<String>(this.values.size());
+
+ for (Object o : values) {
+ if (this.complex == true) {
+ stringCollection.add(o.toString());
+ } else {
+ stringCollection.add((String) o);
+ }
+ }
+
+ return stringCollection;
+ }
+
+ /**
+ * Returns all stored values as a Java Collection of OpenSocialObject
+ * instances.
+ *
+ * @throws OpenSocialException if the complex instance variable is false,
+ * indicating that the values are stored as simple String
objects.
+ */
+ public Collection<OpenSocialObject> getValues() throws
OpenSocialException {
+ if (this.complex == false) {
+ throw new OpenSocialException(
+ "String-based fields cannot be returned as an OpenSocialObject "
+
+ "collection");
+ }
+
+ Collection<OpenSocialObject> objectCollection =
+ new Vector<OpenSocialObject>(this.values.size());
+
+ for (Object o: this.values) {
+ objectCollection.add((OpenSocialObject) o);
+ }
+
+ return objectCollection;
+ }
+
+ /**
+ * Returns true if the number of stored values is greater than one, false
+ * otherwise.
+ */
+ public boolean isMultivalued() {
+ return (values.size() > 1);
+ }
+
+ /**
+ * Returns false if values are stored as simple String objects, true if
+ * OpenSocialObject instances are stored instead.
+ */
+ public boolean isComplex() {
+ return this.complex;
+ }
+}
=======================================
--- /dev/null
+++ /trunk/java/src/org/opensocial/data/OpenSocialObject.java Wed Oct 28
13:41:39 2009
@@ -0,0 +1,112 @@
+/* Copyright (c) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.opensocial.data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An object representing a generic, extensible OpenSocial entity.
Virtually
+ * every object, both concrete (person) or abstract (data), having
arbitrary
+ * properties is modeled as an OpenSocialObject instance. Instance methods
+ * provide an interface for associating strings with objects representing
+ * properties or attributes of that object. These fields can in turn
+ * reference other OpenSocialObject instances.
+ *
+ * @author Jason Cooper
+ */
+public class OpenSocialObject {
+
+ protected Map<String,OpenSocialField> fields;
+
+ public OpenSocialObject() {
+ this.fields = new HashMap<String,OpenSocialField>();
+ }
+
+ /**
+ * Instantiates a new OpenSocialObject object with the passed Map of
+ * OpenSocialField objects keyed on strings, replicating these
+ * correspondences in its own fields Map.
+ *
+ * @param properties Map of OpenSocialField objects keyed on field name
+ * which should be "imported" upon instantiation
+ */
+ public OpenSocialObject(Map<String,OpenSocialField> properties) {
+ this();
+
+ for (Map.Entry<String,OpenSocialField> e : properties.entrySet()) {
+ this.setField(e.getKey(), e.getValue());
+ }
+ }
+
+ /**
+ * Returns {@code true} if a field with the passed key is associated with
+ * the current instance, {@code false} otherwise.
+ */
+ public boolean hasField(String key) {
+ return this.fields.containsKey(key);
+ }
+
+ /**
+ * Returns field mapped to the passed key.
+ *
+ * @param key Key associated with desired field
+ */
+ public OpenSocialField getField(String key) {
+ return this.fields.get(key);
+ }
+
+ /**
+ * Creates a new entry in fields Map, associating the passed
OpenSocialField
+ * object with the passed key.
+ *
+ * @param key Field name
+ * @param value OpenSocialField object to associate with key
+ */
+ public void setField(String key, OpenSocialField value) {
+ this.fields.put(key, value);
+ }
+
+ /**
+ * Returns the names of all properties associated with the instance as an
+ * array of Java String objects.
+ */
+ public String[] fieldNames() {
+ Object[] keys = this.fields.keySet().toArray();
+ String[] fieldNames = new String[this.fields.size()];
+
+ for (int i = 0; i < this.fields.size(); i++) {
+ fieldNames[i] = (String) keys[i];
+ }
+
+ return fieldNames;
+ }
+
+ @Override
+ public String toString() {
+ String allFields = "";
+ for (Map.Entry<String, OpenSocialField> entry : fields.entrySet()) {
+ OpenSocialField value = entry.getValue();
+ String valueString = value.getStringValue();
+ if (value.isComplex()) {
+ valueString = value.getStringValues().toString();
+ }
+ allFields += entry.getKey() + ": " + valueString + "\n";
+ }
+ return allFields;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/java/src/org/opensocial/services/myspace/ProfileCommentsService.java
Wed Oct 28 13:41:39 2009
@@ -0,0 +1,137 @@
+/* Copyright (c) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensocial.services.myspace;
+
+import java.util.ArrayList;
+import java.util.Map;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.opensocial.client.OpenSocialHttpResponseMessage;
+import org.opensocial.client.OpenSocialRequest;
+import org.opensocial.client.OpenSocialRequestException;
+import org.opensocial.data.MySpaceComment;
+import org.opensocial.services.OpenSocialService;
+
+/**
+ * ProfileCommentsService - service class for profilecomments endpoint.
+ * @author jle.e...@gmail.com (Jesse Edwards)
+ *
+ */
+public class ProfileCommentsService extends OpenSocialService {
+
+ /**
+ * getSupportedFields - sends request for supported fields.
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest getSupportedFields()
+ throws OpenSocialRequestException {
+ throw new OpenSocialRequestException("This method is not supported.");
+ }
+
+ /**
+ * get - method used for fetching items in this service.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest get(Map<String, String> params)
+ throws OpenSocialRequestException {
+
+ if(!params.containsKey("groupId"))
+ params.put("groupId", "@self");
+ if(!params.containsKey("userId"))
+ params.put("groupId", "@me");
+
+ OpenSocialRequest r = new OpenSocialRequest("profilecomments",
+ "GET", "profilecomments.get");
+ _addParamsToRequest(r, params);
+ return r;
+ }
+
+ /**
+ * update - method used for updating items in this service.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest update(Map<String, String> params)
+ throws OpenSocialRequestException {
+ throw new OpenSocialRequestException("This method is not supported.");
+ }
+
+ /**
+ * create - method used for creating items in this service.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest create(Map<String, String> params)
+ throws OpenSocialRequestException {
+ throw new OpenSocialRequestException("This method is not supported.");
+ }
+
+ /**
+ * delete - method used for deleting items in this service.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest delete(Map<String, String> params)
+ throws OpenSocialRequestException {
+ throw new OpenSocialRequestException("This method is not supported.");
+ }
+
+ /**
+ * convertResponse - function used to convert response json into the
expected
+ * collection of objects or object.
+ */
+ public void formatResponse(OpenSocialHttpResponseMessage response) {
+
+ super.formatResponse(response);
+
+ String data = response.getOpenSocialDataString();
+ MySpaceComment item = new MySpaceComment();
+ ArrayList<MySpaceComment> collection = new ArrayList<MySpaceComment>();
+
+ try{
+ if(data.startsWith("{") && data.endsWith("}")) {
+ JSONObject obj = new JSONObject(data);
+
+ if(obj.has("entry")) {
+ if(obj.getString("entry").startsWith("[") &&
+ obj.getString("entry").endsWith("]")) {
+
+ JSONArray entry = obj.getJSONArray("entry");
+
+ for(int i=0; i<entry.length(); i++) {
+ item = new MySpaceComment(entry.getJSONObject(i).toString());
+ collection.add(item);
+ }
+ }else {
+ collection.add(new MySpaceComment(obj.getString("entry")));
+ }
+ response.setCollection(collection);
+ }
+ }
+ }catch(JSONException e) {
+ e.printStackTrace();
+ System.out.println(data);
+ }
+ }
+}
=======================================
--- /trunk/java/src/org/opensocial/client/OpenSocialResponse.java Wed Sep
16 11:52:56 2009
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (c) 2009 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.opensocial.client;
-
-import org.opensocial.data.OpenSocialActivity;
-import org.opensocial.data.OpenSocialAppData;
-import org.opensocial.data.OpenSocialPerson;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * An object which represents the response from an OpenSocial container
after
- * one or more requests for data. Objects should not be instantiated
directly
- * by clients -- instead, instances are generated by calling the send
method
- * of OpenSocialBatch objects. This class simply contains wrapper methods
- * which parse a particular response item and return the appropriate
- * OpenSocialObject type.
- *
- * @author apij...@google.com (Jason Cooper)
- */
-public class OpenSocialResponse {
-
- private Map<String, String> items;
-
- public OpenSocialResponse() {
- items = new HashMap<String, String>();
- }
-
- /**
- * Retrieves and parses the JSON-encoded response item with the passed
ID and
- * returns the parsed item as an OpenSocialPerson object.
- *
- * @param id ID of the response item to parse
- * @throws OpenSocialRequestException
- */
- public OpenSocialPerson getItemAsPerson(String id) throws
- OpenSocialRequestException {
- String item = items.get(id);
- return OpenSocialJsonParser.parseAsPerson(item);
- }
-
- /**
- * Retrieves and parses the JSON-encoded response item with the passed
ID and
- * returns the parsed item as a List of OpenSocialPerson objects.
- *
- * @param id ID of the response item to parse
- * @throws OpenSocialRequestException
- */
- public List<OpenSocialPerson> getItemAsPersonCollection(String id) throws
- OpenSocialRequestException {
- String item = items.get(id);
-
- return OpenSocialJsonParser.parseAsPersonCollection(item);
- }
-
- /**
- * Retrieves and parses the JSON-encoded response item with the passed
ID and
- * returns the parsed item as an OpenSocialAppData object.
- *
- * @param id ID of the response item to parse
- * @throws OpenSocialRequestException
- */
- public OpenSocialAppData getItemAsAppData(String id) throws
- OpenSocialRequestException {
- String item = items.get(id);
-
- return OpenSocialJsonParser.parseAsAppData(item);
- }
-
- /**
- * Retrieves and parses the JSON-encoded response item with the passed
ID and
- * returns the parsed item as a List of OpenSocialActivity objects.
- *
- * @param id
- * @throws OpenSocialRequestException
- */
- public List<OpenSocialActivity> getItemAsActivityCollection(String id)
- throws OpenSocialRequestException {
- String item = items.get(id);
-
- return OpenSocialJsonParser.parseAsActivityCollection(item);
- }
-
- /**
- * Creates a new entry in items Map with the passed ID as key and JSON
object
- * string as value.
- *
- * @param id Response item ID
- * @param objectString JSON object string to associate with the passed
ID
- */
- public void addItem(String id, String objectString) {
- items.put(id, objectString);
- }
-
- public Set<String> getResponseIds() {
- return items.keySet();
- }
-
- public String getResponseItem(String id) {
- return items.get(id);
- }
-}
=======================================
--- /trunk/java/samples/StatusMoodExample.java Mon Oct 12 14:22:13 2009
+++ /trunk/java/samples/StatusMoodExample.java Wed Oct 28 13:41:39 2009
@@ -34,6 +34,7 @@
c.setProperty(OpenSocialClient.Property.RPC_ENDPOINT, null);
c.setProperty(OpenSocialClient.Property.CONSUMER_SECRET, "20ab52223e684594a8050a8bfd4b06693ba9c9183ee24e1987be87746b1b03f8");
c.setProperty(OpenSocialClient.Property.CONSUMER_KEY, "http://www.myspace.com/495182150");
+ c.setProperty(OpenSocialClient.Property.VIEWER_ID, "495184236");
// Create Batch handler
OpenSocialBatch batch = new OpenSocialBatch();
@@ -61,18 +62,35 @@
// Fetch supportedMood
params = new HashMap<String, String>();
- params.put("userId", "495184236");
- params.put("groupId", "@supportedMood");
params.put("moodId", "90");
batch.addRequest(c.getStatusMoodService().getSupportedMoods(params), "fetchStatusMoodsSingle");
// End Fetch StatusMood
// Fetch supportedMoods
+
batch.addRequest(c.getStatusMoodService().getSupportedMoods(), "fetchStatusMoods");
+ // End Fetch StatusMoods
+
+ // Fetch statusMood history self
params = new HashMap<String, String>();
params.put("userId", "495184236");
- params.put("groupId", "@supportedMood");
-
batch.addRequest(c.getStatusMoodService().getSupportedMoods(params), "fetchStatusMoods");
- // End Fetch StatusMoods
+ params.put("groupId", "@self");
+
batch.addRequest(c.getStatusMoodService().getHistory(params), "fetchHistorySelf");
+ // End fetchStatusMood history self
+
+ // Fetch statusMood history friends
+ params = new HashMap<String, String>();
+ params.put("userId", "495184236");
+ params.put("groupId", "@friends");
+
batch.addRequest(c.getStatusMoodService().getHistory(params), "fetchHistoryFriends");
+ // End fetchStatusMood friends
+
+ // Fetch statusMood history specific friend
+ params = new HashMap<String, String>();
+ params.put("userId", "495184236");
+ params.put("groupId", "@friends");
+ params.put("friendId", "myspace.com.person.63129100");
+
batch.addRequest(c.getStatusMoodService().getHistory(params), "fetchHistoryFriend");
+ // End fetchStatusMood history specific friend
batch.send(c);
// Get a list of all response in request queue
=======================================
--- /trunk/java/src/org/opensocial/client/OpenSocialBatch.java Mon Oct 12
14:22:13 2009
+++ /trunk/java/src/org/opensocial/client/OpenSocialBatch.java Wed Oct 28
13:41:39 2009
@@ -276,6 +276,7 @@
return client.getNotificationsService();
if(service.equals("people")) return client.getPeopleService();
if(service.equals("statusmood")) return client.getStatusMoodService();
+ if(service.equals("profilecomments")) return
client.getProfileCommentsService();
return null;
}
=======================================
--- /trunk/java/src/org/opensocial/client/OpenSocialClient.java Mon Oct 12
14:22:13 2009
+++ /trunk/java/src/org/opensocial/client/OpenSocialClient.java Wed Oct 28
13:41:39 2009
@@ -26,8 +26,8 @@
// Services - will update this once we finalize where this include should
// live and how it should be handled.
import org.opensocial.services.*;
-import org.opensocial.services.myspace.NotificationsService;
-import org.opensocial.services.myspace.StatusMoodService;
+import org.opensocial.services.myspace.*;
+
import java.io.IOException;
import java.util.ArrayList;
@@ -82,7 +82,7 @@
private AppDataService appData = null;
private PeopleService people = null;
private MessagesService messages = null;
-
+ private ProfileCommentsService profilecomments = null;
/**
* Lazy load getter for mediaItems
*
@@ -142,6 +142,18 @@
}
return statusmood;
}
+
+ /**
+ * Lazy load getter for profilecomments
+ *
+ * @return StatusMoodService
+ */
+ public ProfileCommentsService getProfileCommentsService() {
+ if(profilecomments == null) {
+ profilecomments = new ProfileCommentsService();
+ }
+ return profilecomments;
+ }
/**
* Lazy load getter for activities
@@ -523,14 +535,19 @@
groupId.equals("")) {
throw new OpenSocialRequestException("Invalid request parameters");
}
-
- OpenSocialRequest r =
OpenSocialClient.newFetchActivitiesRequest(userId,
- groupId, appId);
+
+ HashMap<String,String>params = new HashMap<String,String>();
+ params.put("userId", userId);
+ params.put("groupId", groupId);
+ params.put("appId", appId);
+
OpenSocialBatch batch = new OpenSocialBatch();
- batch.addRequest(r, "activities");
-
- OpenSocialResponse response = batch.send(this);
- return response.getItemAsActivityCollection("activities");
+ batch.addRequest(getActivitiesService().get(params), "fetchActivity");
+ batch.send(this);
+
+ OpenSocialHttpResponseMessage response =
batch.getResponse("fetchActivity");
+
+ return response.getActivityCollection();
}
/**
@@ -618,13 +635,15 @@
* @throws OpenSocialRequestException
* @throws IOException
*/
- private OpenSocialResponse removeAppData(String userId, List<String>
keys)
+ private OpenSocialHttpResponseMessage removeAppData(String userId,
List<String> keys)
throws OpenSocialRequestException, IOException {
OpenSocialRequest r =
OpenSocialClient.newRemovePersonAppDataRequest(userId, keys);
OpenSocialBatch batch = new OpenSocialBatch();
batch.addRequest(r, "appdata");
- return batch.send(this);
+ batch.send(this);
+ OpenSocialHttpResponseMessage response = batch.getResponse("appdata");
+ return response;
}
/**
=======================================
---
/trunk/java/src/org/opensocial/client/OpenSocialHttpResponseMessage.java
Mon Oct 12 14:22:13 2009
+++
/trunk/java/src/org/opensocial/client/OpenSocialHttpResponseMessage.java
Wed Oct 28 13:41:39 2009
@@ -25,6 +25,7 @@
import org.json.JSONException;
import org.json.JSONObject;
+import org.opensocial.data.MySpaceComment;
import org.opensocial.data.MySpaceNotification;
import org.opensocial.data.MySpaceStatusMood;
import org.opensocial.data.OpenSocialActivity;
@@ -255,4 +256,9 @@
public ArrayList<OpenSocialGroup> getGroupCollection() {
return osCollection;
}
-}
+
+ @SuppressWarnings("unchecked")
+ public ArrayList<MySpaceComment> getCommentCollection() {
+ return osCollection;
+ }
+}
=======================================
--- /trunk/java/src/org/opensocial/client/OpenSocialUrl.java Mon Oct 12
14:22:13 2009
+++ /trunk/java/src/org/opensocial/client/OpenSocialUrl.java Wed Oct 28
13:41:39 2009
@@ -66,10 +66,12 @@
urlTemplates.put("albums", "albums/{userId}/{groupId}/{albumId}");
urlTemplates.put("mediaItems",
"mediaItems/{userId}/{groupId}/{albumId}/{mediaItemId}");
- urlTemplates.put("statusmood", "statusmood/{userId}/{groupId}/{moodId}");
+ urlTemplates.put("statusmood",
+ "statusmood/{userId}/{groupId}/{friendId}/{moodId}/{history}");
urlTemplates.put("notifications", "notifications/{userId}/{groupId}");
urlTemplates.put("groups", "/groups/{userId}/{groupId}");
-
+
urlTemplates.put("profilecomments", "profilecomments/{userId}/{groupId}");
+
// Pos Aliases
postAliases.put("activities", "activity");
postAliases.put("albums", "album");
@@ -79,6 +81,7 @@
postAliases.put("notifications", "notification");
postAliases.put("people", "person");
postAliases.put("statusmood", "statusMood");
+ postAliases.put("profilecomments", "profileComment");
}
public Map<String, String> getPostAliases() {
=======================================
--- /trunk/java/src/org/opensocial/providers/MySpaceProvider.java Tue Oct
13 14:20:58 2009
+++ /trunk/java/src/org/opensocial/providers/MySpaceProvider.java Wed Oct
28 13:41:39 2009
@@ -69,6 +69,8 @@
if(data.startsWith("{")) {
JSONObject obj = new JSONObject(data);
+
+
if(obj.has("entry") ){
if(obj.getString("entry").startsWith("[")) {
JSONArray tmp = new JSONArray();
@@ -76,9 +78,12 @@
int length = entry.length();
for(int i=0; i< length; i++) {
- tmp.put(entry.getJSONObject(i).getJSONObject(model));
- }
-
+ if(entry.getJSONObject(i).has(model)) {
+ tmp.put(entry.getJSONObject(i).getJSONObject(model));
+ }else{
+ tmp.put(entry.getJSONObject(i));
+ }
+ }
obj.put("entry", tmp);
response.setOpenSocialDataString(obj.toString());
}
=======================================
--- /trunk/java/src/org/opensocial/services/myspace/StatusMoodService.java
Mon Oct 12 14:22:13 2009
+++ /trunk/java/src/org/opensocial/services/myspace/StatusMoodService.java
Wed Oct 28 13:41:39 2009
@@ -16,6 +16,7 @@
package org.opensocial.services.myspace;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
@@ -44,15 +45,52 @@
throw new OpenSocialRequestException("This method is not supported.");
}
+ /**
+ * getSupportedMoods - override for requesting without parameters
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest getSupportedMoods()
+ throws OpenSocialRequestException {
+ Map<String, String> params = new HashMap<String, String>();
+
+ return this.getSupportedMoods(params);
+ }
+
+ /**
+ * getSupportedMoods() convience method for requesting
+ * statusmood supported moods.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
public OpenSocialRequest getSupportedMoods(Map<String, String> params)
throws OpenSocialRequestException {
-
- OpenSocialRequest r = new OpenSocialRequest("statusmood",
- "GET", "statusmood.getSupportedMoods");
- _addParamsToRequest(r, params);
- return r;
- }
-
+
+ if(!params.containsKey("userId"))
+ params.put("userId", "@me");
+
+ params.put("groupId", "@supportedMood");
+
+ OpenSocialRequest r = new OpenSocialRequest("statusmood",
+ "GET", "statusmood.getSupportedMoods");
+ _addParamsToRequest(r, params);
+ return r;
+ }
+
+ /**
+ * getHistory() convience method for requesting statusmood history.
+ * @param Map<String, String> params
+ * @return OpenSocialRequest
+ * @throws OpenSocialRequestException
+ */
+ public OpenSocialRequest getHistory(Map<String, String> params) {
+ OpenSocialRequest r = new OpenSocialRequest("statusmood",
+ "GET", "statusmood.get");
+ params.put("history", "history");
+ _addParamsToRequest(r, params);
+ return r;
+ }
/**
* get - method used for fetching items in this service.
@@ -129,9 +167,16 @@
}else if(data.startsWith("{") && data.endsWith("}")) {
JSONObject obj = new JSONObject(data);
- if(obj.has("entry")) {
+ if(obj.has("entry") && obj.getString("entry").startsWith("{")) {
collection.add(new MySpaceStatusMood(obj.getString("entry")));
- }else{
+ }else if(obj.has("entry") &&
obj.getString("entry").startsWith("[")) {
+ JSONArray entry = obj.getJSONArray("entry");
+
+ for(int i=0; i<entry.length(); i++) {
+ item = new
MySpaceStatusMood(entry.getJSONObject(i).toString());
+ collection.add(item);
+ }
+ } else{
collection.add(new MySpaceStatusMood(obj.toString()));
}
}