You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by do...@apache.org on 2008/05/21 09:15:53 UTC
svn commit: r658573 - in /incubator/shindig/trunk:
features/opensocial-current/restfulcontainer.js
java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java
Author: doll
Date: Wed May 21 00:15:53 2008
New Revision: 658573
URL: http://svn.apache.org/viewvc?rev=658573&view=rev
Log:
Updated the restfulcontainer to work with the newly correct json format for people and activities. Added a new test for activity friend data.
Modified:
incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js
incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java
Modified: incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js?rev=658573&r1=658572&r2=658573&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js (original)
+++ incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js Wed May 21 00:15:53 2008
@@ -86,7 +86,7 @@
var makeProxiedRequest = function(requestObject, baseUrl, st) {
var makeRequestParams = {
- "CONTENT_TYPE" : "DOM",
+ "CONTENT_TYPE" : "JSON",
"METHOD" : requestObject.request.method
// TODO: Handle post data
};
@@ -145,7 +145,7 @@
var me = this;
return new RestfulRequestItem(peopleRequest.url, peopleRequest.method, null,
function(rawJson) {
- return me.createPersonFromJson(rawJson[0]);
+ return me.createPersonFromJson(rawJson);
});
};
@@ -164,14 +164,13 @@
var me = this;
return new RestfulRequestItem(url, "GET", null,
function(rawJson) {
- var jsonPeople = rawJson;
+ var jsonPeople = rawJson['entry'];
var people = [];
for (var i = 0; i < jsonPeople.length; i++) {
people.push(me.createPersonFromJson(jsonPeople[i]));
}
- return new opensocial.Collection(people);
- // TODO: Bring this back once the restful url supports it
- // rawJson['offset'],rawJson['totalSize']);
+ return new opensocial.Collection(people,
+ rawJson['startIndex'], rawJson['totalResults']);
});
};
@@ -203,6 +202,7 @@
+ "?app=" + this.appId_;
return new RestfulRequestItem(url, "GET", null,
function(rawJson) {
+ rawJson = rawJson['entry'];
var activities = [];
for (var i = 0; i < rawJson.length; i++) {
activities.push(new JsonActivity(rawJson[i]));
@@ -226,27 +226,9 @@
return rawJson;
};
- this.processResponse = function(originalDataRequest, rawXml, error,
+ this.processResponse = function(originalDataRequest, rawJson, error,
errorMessage) {
- if (!rawXml) {
- error = true;
- errorMessage = "Invalid request url";
- }
-
- var rawJson = [];
- if (!error) {
- var contentNodes = rawXml.getElementsByTagName("content");
- if (contentNodes) {
- for (var i = 0; i < contentNodes.length; i++) {
- var xmlValue = contentNodes[i].childNodes[0].nodeValue;
- rawJson.push(gadgets.json.parse(xmlValue));
- }
- } else {
- error = true;
- }
- }
-
return new opensocial.ResponseItem(originalDataRequest,
error ? null : this.processData(rawJson), error, errorMessage);
}
Modified: incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java?rev=658573&r1=658572&r2=658573&view=diff
==============================================================================
--- incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java (original)
+++ incubator/shindig/trunk/java/social-api/src/test/java/org/apache/shindig/social/abdera/RestfulJsonActivityTest.java Wed May 21 00:15:53 2008
@@ -105,6 +105,37 @@
result.getJSONArray("entry").getJSONObject(0));
}
+ /**
+ * Expected response for a list of activities in json:
+ * TODO: Fix the question marks...
+ *
+ * {
+ * "author" : "<???>",
+ * "link" : {"rel" : "next", "href" : "<???>"},
+ * "totalResults" : 1,
+ * "startIndex" : 0
+ * "itemsPerPage" : 10 // Note: the js doesn't support paging. Should rest?
+ * "entry" : [
+ * {<activity>} // layed out like above
+ * ]
+ * }
+ *
+ * @throws Exception if test encounters an error
+ */
+ @Test
+ public void testGetFriendsActivitiesJson() throws Exception {
+ // TODO: test that the ids passed into the activities service are correct
+ // TODO: change this test to use different people
+ resp = client.get(BASEURL + "/activities/john.doe/@friends");
+ checkForGoodJsonResponse(resp);
+ JSONObject result = getJson(resp);
+
+ assertEquals(1, result.getInt("totalResults"));
+ assertEquals(0, result.getInt("startIndex"));
+ assertActivitiesEqual(activity,
+ result.getJSONArray("entry").getJSONObject(0));
+ }
+
private void assertActivitiesEqual(Activity activity, JSONObject result)
throws JSONException {
assertEquals(activity.getId(), result.getString("id"));
@@ -115,5 +146,4 @@
// TODO: Add tests for the fields= parameter
// TODO: Add tests for post
- // TODO: Add tests for @friends
}