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/07/23 03:03:00 UTC

svn commit: r678962 - in /incubator/shindig/trunk/features: opensocial-0.7/opensocial7to8.js opensocial-current/restfulcontainer.js

Author: doll
Date: Tue Jul 22 18:02:59 2008
New Revision: 678962

URL: http://svn.apache.org/viewvc?rev=678962&view=rev
Log:
Deleted old unused non-batching restful code.
Fixed fetchPeople responses to allow for the single person response in addition to the array of people response. 
The dataResponse now properly parses any http errors and creates empty response items for developer convenience. 


Modified:
    incubator/shindig/trunk/features/opensocial-0.7/opensocial7to8.js
    incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js

Modified: incubator/shindig/trunk/features/opensocial-0.7/opensocial7to8.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-0.7/opensocial7to8.js?rev=678962&r1=678961&r2=678962&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-0.7/opensocial7to8.js (original)
+++ incubator/shindig/trunk/features/opensocial-0.7/opensocial7to8.js Tue Jul 22 18:02:59 2008
@@ -58,7 +58,7 @@
 opensocial.Person.prototype.getFieldOld = opensocial.Person.prototype.getField;
 opensocial.Person.prototype.getField = function(key, opt_params) {
   var value =  this.getFieldOld(key, opt_params);
-  if (key == 'lookingFor') {
+  if (key == 'lookingFor' && value) {
     // The lookingFor field used to return a string instead of an enum
     return value.getDisplayValue();
   } else {

Modified: incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js?rev=678962&r1=678961&r2=678962&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js (original)
+++ incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js Tue Jul 22 18:02:59 2008
@@ -68,51 +68,6 @@
     return;
   }
 
-  var responseMap = {};
-  var globalError = false;
-  var responsesReceived = 0;
-
-  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",
-      "METHOD" : requestObject.request.method
-    };
-
-    if (requestObject.request.postData) {
-      makeRequestParams["POST_DATA"] = gadgets.json.stringify(requestObject.request.postData);
-    }
-
-    var url = requestObject.request.url;
-    var separator = url.indexOf("?") != -1 ? "&" : "?";
-
-    gadgets.io.makeNonProxiedRequest(
-        baseUrl + url + separator + "st=" + st,
-        function(result) {
-          var error;
-          if (result.errors) {
-            error = RestfulContainer.translateHttpError(result.errors[0]);
-          }
-
-          // TODO: get error messages
-          var processedData = requestObject.request.processResponse(
-              requestObject.request, result.data, error, null);
-          globalError = globalError || processedData.hadError();
-          responseMap[requestObject.key] = processedData;
-
-          checkIfFinished();
-        },
-        makeRequestParams,
-        "application/json");
-  }
-
   var jsonBatchData = {};
   var systemKeyIndex = 0;
 
@@ -135,15 +90,14 @@
     }
   }
 
-  // This is slightly different than jsonContainer
   var sendResponse = function(result) {
-    result = result.data;
-
-    if (!result || result['error']) {
-      callback(new opensocial.DataResponse({}, true));
+    if (result.errors[0] || result.data.error) {
+      RestfulContainer.generateErrorResponse(result, requestObjects, callback);
       return;
     }
 
+    result = result.data;
+
     var responses = result['responses'] || [];
     var globalError = false;
 
@@ -180,6 +134,18 @@
     sendResponse, makeRequestParams, "application/json");
 };
 
+RestfulContainer.generateErrorResponse = function(result, requestObjects, callback) {
+  var globalErrorCode = RestfulContainer.translateHttpError(result.errors[0] || result.data.error)
+      || opensocial.ResponseItem.Error.INTERNAL_ERROR;
+
+  var errorResponseMap = {};
+  for (var i = 0; i < requestObjects.length; i++) {
+    errorResponseMap[requestObjects[i].key] = new opensocial.ResponseItem(
+        requestObjects[i].request, null, globalErrorCode);
+  }
+  callback(new opensocial.DataResponse(errorResponseMap, true));
+};
+
 RestfulContainer.translateHttpError = function(httpError) {
   if (httpError == "Error 501") {
     return opensocial.ResponseItem.Error.NOT_IMPLEMENTED;
@@ -197,11 +163,11 @@
   // } else if (httpError == "Error ???") {
   //   return opensocial.ResponseItem.Error.LIMIT_EXCEEDED;
   }
-}
+};
 
 RestfulContainer.prototype.makeIdSpec = function(id) {
   return new opensocial.IdSpec({'userId' : id});
-}
+};
 
 RestfulContainer.prototype.translateIdSpec = function(newIdSpec) {
   var userId = newIdSpec.getField('userId');
@@ -256,9 +222,17 @@
   var me = this;
   return new RestfulRequestItem(url, "GET", null,
       function(rawJson) {
-        var jsonPeople = rawJson['entry'];
+        var jsonPeople;
+        if (rawJson['entry']) {
+          // For the array of people response
+          jsonPeople = rawJson['entry'];
+        } else {
+          // For the single person response
+          jsonPeople = [rawJson];
+        }
+
         var people = [];
-        for (var i = 0; i < jsonPeople.length; i++) {	
+        for (var i = 0; i < jsonPeople.length; i++) {
           people.push(me.createPersonFromJson(jsonPeople[i]));
         }
         return new opensocial.Collection(people,