Author: doll
Date: Tue May 6 09:11:21 2008
New Revision: 653824
URL: http://svn.apache.org/viewvc?rev=653824&view=rev
Log:
The javascript restfulcontainer now properly handles fetchPerson calls!
You can enable the restful container by using the new config in container.js.
More calls will hopefully be implemented soon.
Modified:
incubator/shindig/trunk/config/container.js
incubator/shindig/trunk/features/opensocial-0.7/feature.xml
incubator/shindig/trunk/features/opensocial-0.7/restfulcontainer.js
Modified: incubator/shindig/trunk/config/container.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/config/container.js?rev=653824&r1=653823&r2=653824&view=diff
==============================================================================
--- incubator/shindig/trunk/config/container.js (original)
+++ incubator/shindig/trunk/config/container.js Tue May 6 09:11:21 2008
@@ -102,7 +102,12 @@
"supportedFields" : {
"person" : ["id", "name", "thumbnailUrl", "profileUrl"],
"activity" : ["id", "title"]
- }
+ },
+ // If true, the restful wire format will be used.
+ // Otherwise, uses the json wire format.
+ // If you are using the default Shindig setup and want to use rest, don't
+ // forget to change the "path" config to /social/rest
+ "useRestful" : false
}
}}
Modified: incubator/shindig/trunk/features/opensocial-0.7/feature.xml
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-0.7/feature.xml?rev=653824&r1=653823&r2=653824&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-0.7/feature.xml (original)
+++ incubator/shindig/trunk/features/opensocial-0.7/feature.xml Tue May 6
09:11:21 2008
@@ -26,12 +26,14 @@
<script src="jsonactivity.js"></script>
<script src="jsoncontainer.js"></script>
<script src="batchrequest.js"></script>
+ <script src="restfulcontainer.js"></script>
<script>
var requiredConfig = {
"path": gadgets.config.NonEmptyStringValidator,
"domain": gadgets.config.NonEmptyStringValidator,
"enableCaja": gadgets.config.BooleanValidator,
- "supportedFields": gadgets.config.ExistsValidator
+ "supportedFields": gadgets.config.ExistsValidator,
+ "useRestful": gadgets.config.BooleanValidator
};
gadgets.config.register("opensocial-0.7", requiredConfig,
@@ -44,12 +46,23 @@
};
ShindigContainer.inherits(JsonContainer);
- opensocial.Container.setContainer(new ShindigContainer());
+ RestfulShindigContainer = function() {
+ RestfulContainer.call(this, configParams.path,
+ configParams.domain, configParams.supportedFields);
+ };
+ RestfulShindigContainer.inherits(RestfulContainer);
+
+ if (configParams.useRestful) {
+ opensocial.Container.setContainer(new RestfulShindigContainer());
+ } else {
+ opensocial.Container.setContainer(new ShindigContainer());
+ }
if (configParams.enableCaja) {
opensocial.Container.get().enableCaja();
}
});
+
</script>
</gadget>
</feature>
Modified: incubator/shindig/trunk/features/opensocial-0.7/restfulcontainer.js
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-0.7/restfulcontainer.js?rev=653824&r1=653823&r2=653824&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-0.7/restfulcontainer.js
(original)
+++ incubator/shindig/trunk/features/opensocial-0.7/restfulcontainer.js Tue May
6 09:11:21 2008
@@ -76,19 +76,24 @@
var globalError = false;
var responsesReceived = 0;
- // may need multiple urls for one response but lets ignore that for now
- for (var i = 0; i < totalRequests; i++) {
- var requestObject = requestObjects[i];
+ var checkIfFinished = function() {
+ responsesReceived++;
+ if (responsesReceived == totalRequests) {
+ var dataResponse = new opensocial.DataResponse(responseMap, globalError);
+ callback(dataResponse);
+ }
+ }
+ var makeProxiedRequest = function(requestObject, baseUrl, st) {
var makeRequestParams = {
- "CONTENT_TYPE" : "JSON",
+ "CONTENT_TYPE" : "DOM",
"METHOD" : requestObject.request.method
// TODO: Handle post data
};
// TODO: Use batching instead of doing this one by one
gadgets.io.makeNonProxiedRequest(
- requestObject.request.url + "st=" + this.securityToken,
+ baseUrl + requestObject.request.url + "&st=" + st,
function(result) {
result = result.data;
@@ -98,30 +103,24 @@
globalError = globalError || processedData.hadError();
responseMap[requestObject.key] = processedData;
- responsesReceived++;
- if (responsesReceived == totalRequests) {
- var dataResponse = new opensocial.DataResponse(responseMap,
- globalError);
- callback(dataResponse);
- }
+ checkIfFinished();
},
makeRequestParams);
}
-};
-
-RestfulContainer.prototype.newFetchPersonRequest = function(id, opt_params) {
- var peopleRequest = this.newFetchPeopleRequest(id, opt_params);
+ // may need multiple urls for one response but lets ignore that for now
+ for (var i = 0; i < totalRequests; i++) {
+ makeProxiedRequest(requestObjects[i], this.baseUrl_, this.securityToken_);
+ }
- var me = this;
- return new RequestItem(peopleRequest.url, peopleRequest.method, null,
- function(rawJson) {
- return me.createPersonFromJson(rawJson['items'][0]);
- });
};
RestfulContainer.prototype.translateIdSpec = function(idSpec) {
// This will get cleaner in 0.8 because idSpec will be an object
+
+ // TODO: Some of these rest urls return "feeds" and some return "entries"..
+ // this is going to get complicated unless we can get them all in the same
+ // format
if (idSpec == "VIEWER") {
return this.viewerId_ + "/@self";
} else if (idSpec == "VIEWER_FRIENDS") {
@@ -130,7 +129,7 @@
return this.ownerId_ + "/@self";
} else if (idSpec == "OWNER_FRIENDS") {
return this.ownerId_ + "/@friends";
- } else if (this.isArray(idSpec)) {
+ } else if (opensocial.Container.isArray(idSpec)) {
for (var i = 0; i < idSpec.length; i++) {
// TODO: We will need multiple urls here....don't want to think about
// that yet
@@ -140,6 +139,16 @@
}
};
+RestfulContainer.prototype.newFetchPersonRequest = function(id, opt_params) {
+ var peopleRequest = this.newFetchPeopleRequest(id, opt_params);
+
+ var me = this;
+ return new RestfulRequestItem(peopleRequest.url, peopleRequest.method, null,
+ function(rawJson) {
+ return me.createPersonFromJson(rawJson);
+ });
+};
+
RestfulContainer.prototype.newFetchPeopleRequest = function(idSpec,
opt_params) {
var url = "/people/" + this.translateIdSpec(idSpec);
@@ -148,12 +157,12 @@
// 'sortOrder': opt_params['sortOrder'] || 'topFriends',
// 'filter': opt_params['filter'] || 'all',
- url += "fields=" + (opt_params['profileDetail'].join(','));
- url += "startPage=" + (opt_params['first'] || 0);
- url += "count=" + (opt_params['max'] || 20);
+ url += "?fields=" + (opt_params['profileDetail'].join(','));
+ url += "&startPage=" + (opt_params['first'] || 0);
+ url += "&count=" + (opt_params['max'] || 20);
var me = this;
- return new RequestItem(url, "GET", null,
+ return new RestfulRequestItem(url, "GET", null,
function(rawJson) {
var jsonPeople = rawJson['items'];
var people = [];
@@ -173,7 +182,7 @@
keys) {
var url = "/appdata/" + this.translateIdSpec(idSpec) + "/" + this.appId_
+ "?fields=" + keys.join(',');
- return new RequestItem(url, "GET", null,
+ return new RestfulRequestItem(url, "GET", null,
function (appData) {
return gadgets.util.escape(appData, true);
});
@@ -184,14 +193,14 @@
var url = "/appdata/" + this.translateIdSpec(idSpec) + "/" + this.appId_
+ "?fields=" + key;
// TODO: Or should we use POST?
- return new RequestItem(url, "PUT", {key: value});
+ return new RestfulRequestItem(url, "PUT", {key: value});
};
RestfulContainer.prototype.newFetchActivitiesRequest = function(idSpec,
opt_params) {
var url = "/activities/" + this.translateIdSpec(idSpec)
+ "?app=" + this.appId_;
- return new RequestItem(url, "GET", null,
+ return new RestfulRequestItem(url, "GET", null,
function(rawJson) {
var activities = [];
for (var i = 0; i < rawJson.length; i++) {
@@ -204,10 +213,10 @@
RestfulContainer.prototype.newCreateActivityRequest = function(idSpec,
activity) {
// TODO: no idea how to do this yet
- return new RequestItem("TODO", "POST", {});
+ return new RestfulRequestItem("TODO", "POST", {});
};
-RequestItem = function(url, method, postData, processData) {
+RestfulRequestItem = function(url, method, postData, processData) {
this.url = url;
this.method = method;
this.postData = postData;
@@ -216,8 +225,19 @@
return rawJson;
};
- this.processResponse = function(originalDataRequest, rawJson, error,
+ this.processResponse = function(originalDataRequest, rawXml, error,
errorMessage) {
+
+ var rawJson;
+ if (!error) {
+ var contentNode = rawXml.getElementsByTagName("content")[0];
+ if (contentNode) {
+ rawJson = gadgets.json.parse(contentNode.childNodes[0].nodeValue);
+ } else {
+ error = true;
+ }
+ }
+
return new opensocial.ResponseItem(originalDataRequest,
error ? null : this.processData(rawJson), error, errorMessage);
}