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/09/10 02:25:29 UTC

svn commit: r693669 - in /incubator/shindig/trunk/features/opensocial-current: feature.xml fieldtranslations.js jsonrpccontainer.js restfulcontainer.js

Author: doll
Date: Tue Sep  9 17:25:28 2008
New Revision: 693669

URL: http://svn.apache.org/viewvc?rev=693669&view=rev
Log:
Split out the field translations needed for the 0.8.1 server api changed into a new field. The restfulcontainer.js now depends on the code as well so that php will work until they transition over.


Added:
    incubator/shindig/trunk/features/opensocial-current/fieldtranslations.js
Modified:
    incubator/shindig/trunk/features/opensocial-current/feature.xml
    incubator/shindig/trunk/features/opensocial-current/jsonrpccontainer.js
    incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js

Modified: incubator/shindig/trunk/features/opensocial-current/feature.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/feature.xml?rev=693669&r1=693668&r2=693669&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/feature.xml (original)
+++ incubator/shindig/trunk/features/opensocial-current/feature.xml Tue Sep  9 17:25:28 2008
@@ -24,6 +24,7 @@
   <!-- Must include the "caja" feature to display samplecontainer -->
   <!-- gadgets when "use caja" is checked -->
   <gadget>
+    <script src="fieldtranslations.js"></script>
     <script src="jsonactivity.js"></script>
     <script src="jsonperson.js"></script>
     <script src="restfulcontainer.js"></script>

Added: incubator/shindig/trunk/features/opensocial-current/fieldtranslations.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/fieldtranslations.js?rev=693669&view=auto
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/fieldtranslations.js (added)
+++ incubator/shindig/trunk/features/opensocial-current/fieldtranslations.js Tue Sep  9 17:25:28 2008
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * @fileoverview Helper class used to translate from the 0.8 server apis to the 0.8 js apis
+ * (which are unfortunately not the same)
+ */
+
+var FieldTranslations = {};
+
+FieldTranslations.translateServerPersonToJsPerson = function(serverJson) {
+  if (serverJson.emails) {
+    for (var i = 0; i < serverJson.emails.length; i++) {
+      serverJson.emails[i].address = serverJson.emails[i].value;
+    }
+  }
+
+  if (serverJson.phoneNumbers) {
+    for (var p = 0; p < serverJson.phoneNumbers.length; p++) {
+      serverJson.phoneNumbers[p].number = serverJson.phoneNumbers[p].value;
+    }
+  }
+
+  if (serverJson.birthday) {
+    serverJson.dateOfBirth = serverJson.birthday;
+  }
+
+  if (serverJson.utcOffset) {
+    serverJson.timeZone = serverJson.utcOffset;
+  }
+
+  if (serverJson.addresses) {
+    for (var j = 0; j < serverJson.addresses.length; j++) {
+      serverJson.addresses[j].unstructuredAddress = serverJson.addresses[j].formatted;
+    }
+  }
+
+  if (serverJson.gender) {
+    var key = serverJson.gender == 'male' ? 'MALE' :
+              (serverJson.gender == 'female') ? 'FEMALE' :
+              null;
+    serverJson.gender = {key : key, displayValue : serverJson.gender};
+  }
+
+  FieldTranslations.translateUrlJson(serverJson.profileSong);
+  FieldTranslations.translateUrlJson(serverJson.profileVideo);
+
+  if (serverJson.urls) {
+    for (var u = 0; u < serverJson.urls.length; u++) {
+      FieldTranslations.translateUrlJson(serverJson.urls[u]);
+    }
+  }
+
+  FieldTranslations.translateEnumJson(serverJson.drinker);
+  FieldTranslations.translateEnumJson(serverJson.lookingFor);
+  FieldTranslations.translateEnumJson(serverJson.networkPresence);
+  FieldTranslations.translateEnumJson(serverJson.smoker);
+
+  if (serverJson.organizations) {
+    serverJson.jobs = [];
+    serverJson.schools = [];
+
+    for (var o = 0; o < serverJson.organizations.length; o++) {
+      var org = serverJson.organizations[o];
+      if (org.type == 'job') {
+        serverJson.jobs.push(org);
+      } else if (org.type == 'school') {
+        serverJson.schools.push(org);
+      }
+    }
+  }
+
+  if (serverJson.name) {
+    serverJson.name.unstructured = serverJson.name.formatted;
+  }
+
+}
+
+FieldTranslations.translateEnumJson = function(enumJson) {
+  if (enumJson) {
+    enumJson.key = enumJson.value;
+  }
+}
+
+FieldTranslations.translateUrlJson = function(urlJson) {
+  if (urlJson) {
+    urlJson.address = urlJson.value;
+  }
+}
+
+
+FieldTranslations.translateJsPersonFieldsToServerFields = function(fields) {
+  for (var i = 0; i < fields.length; i++) {
+    if (fields[i] == 'dateOfBirth') {
+      fields[i] = 'birthday';
+    } else if (fields[i] == 'timeZone') {
+      fields[i] = 'utcOffset';
+    }
+  }
+
+  // displayName and id always need to be requested
+  fields.push("id");
+  fields.push("displayName");
+}
+

Modified: incubator/shindig/trunk/features/opensocial-current/jsonrpccontainer.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/jsonrpccontainer.js?rev=693669&r1=693668&r2=693669&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/jsonrpccontainer.js (original)
+++ incubator/shindig/trunk/features/opensocial-current/jsonrpccontainer.js Tue Sep  9 17:25:28 2008
@@ -217,7 +217,7 @@
   var rpc = { method : "people.get" };
   rpc.params = this.translateIdSpec(idSpec);
   if (opt_params['profileDetail']) {
-    this.translateProfileDetails(opt_params['profileDetail']);
+    FieldTranslations.translateJsPersonFieldsToServerFields(opt_params['profileDetail']);
     rpc.params.fields = opt_params['profileDetail'];
   }
   if (opt_params['first']) {
@@ -257,103 +257,11 @@
       });
 };
 
-JsonRpcContainer.prototype.translateProfileDetails = function(profileDetails) {
-  for (var i = 0; i < profileDetails.length; i++) {
-    if (profileDetails[i] == 'dateOfBirth') {
-      profileDetails[i] = 'birthday';
-    } else if (profileDetails[i] == 'timeZone') {
-      profileDetails[i] = 'utcOffset';
-    }
-  }
-
-  // displayName and id always need to be requested
-  profileDetails.push("id");
-  profileDetails.push("displayName");
-}
-
 JsonRpcContainer.prototype.createPersonFromJson = function(serverJson) {
-  // We need to translate from the new person fields to the old ones
-  // TODO(doll): Pull this out into a separate file
-  if (serverJson.emails) {
-    for (var i = 0; i < serverJson.emails.length; i++) {
-      serverJson.emails[i].address = serverJson.emails[i].value;
-    }
-  }
-
-  if (serverJson.phoneNumbers) {
-    for (var p = 0; p < serverJson.phoneNumbers.length; p++) {
-      serverJson.phoneNumbers[p].number = serverJson.phoneNumbers[p].value;
-    }
-  }
-
-  if (serverJson.birthday) {
-    serverJson.dateOfBirth = serverJson.birthday;
-  }
-
-  if (serverJson.utcOffset) {
-    serverJson.timeZone = serverJson.utcOffset;
-  }
-
-  if (serverJson.addresses) {
-    for (var j = 0; j < serverJson.addresses.length; j++) {
-      serverJson.addresses[j].unstructuredAddress = serverJson.addresses[j].formatted;
-    }
-  }
-
-  if (serverJson.gender) {
-    var key = serverJson.gender == 'male' ? 'MALE' : 
-             (serverJson.gender == 'female') ? 'FEMALE' :
-             null;
-    serverJson.gender = {key : key, displayValue : serverJson.gender};
-  }
-
-  this.translateUrlJson(serverJson.profileSong);
-  this.translateUrlJson(serverJson.profileVideo);
-
-  if (serverJson.urls) {
-    for (var u = 0; u < serverJson.urls.length; u++) {
-      this.translateUrlJson(serverJson.urls[u]);
-    }
-  }
-
-  this.translateEnumJson(serverJson.drinker);
-  this.translateEnumJson(serverJson.lookingFor);
-  this.translateEnumJson(serverJson.networkPresence);
-  this.translateEnumJson(serverJson.smoker);
-
-  if (serverJson.organizations) {
-    serverJson.jobs = [];
-    serverJson.schools = [];
-
-    for (var o = 0; o < serverJson.organizations.length; o++) {
-      var org = serverJson.organizations[o];
-      if (org.type == 'job') {
-        serverJson.jobs.push(org);
-      } else if (org.type == 'school') {
-        serverJson.schools.push(org);
-      }
-    }
-  }
-
-  if (serverJson.name) {
-    serverJson.name.unstructured = serverJson.name.formatted;
-  }
-
+  FieldTranslations.translateServerPersonToJsPerson(serverJson);
   return new JsonPerson(serverJson);
 };
 
-JsonRpcContainer.prototype.translateEnumJson = function(enumJson) {
-  if (enumJson) {
-    enumJson.key = enumJson.value;
-  }
-}
-
-JsonRpcContainer.prototype.translateUrlJson = function(urlJson) {
-  if (urlJson) {
-    urlJson.address = urlJson.value;
-  }
-}
-
 JsonRpcContainer.prototype.getFieldsList = function(keys) {
   // datarequest.js guarantees that keys is an array
   if (this.hasNoKeys(keys) || this.isWildcardKey(keys[0])) {

Modified: incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js?rev=693669&r1=693668&r2=693669&view=diff
==============================================================================
--- incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js (original)
+++ incubator/shindig/trunk/features/opensocial-current/restfulcontainer.js Tue Sep  9 17:25:28 2008
@@ -215,6 +215,7 @@
     opt_params) {
   var url = "/people/" + this.translateIdSpec(idSpec);
 
+  FieldTranslations.translateJsPersonFieldsToServerFields(opt_params['profileDetail']);
   url += "?fields=" + (opt_params['profileDetail'].join(','));
   url += "&startIndex=" + (opt_params['first'] || 0);
   url += "&count=" + (opt_params['max'] || 20);
@@ -245,6 +246,7 @@
 };
 
 RestfulContainer.prototype.createPersonFromJson = function(serverJson) {
+  FieldTranslations.translateServerPersonToJsPerson(serverJson);
   return new JsonPerson(serverJson);
 };