“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust. I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it. Currently working for InPay...”

Rob Lacey
Senior Software Engineer, UK

Day 2: differences between opensocial 0.7 and 0.8

In my playing yesterday I was trying to extract whether a viewing user had the app installed. The user attribute HAS_APP needed to be added to the request in order to return this, this caused some bother as it appears that HAS_APP is only available in opensocial 0.8 and the default on the MySpace platform is 0.7. However, upgrading to 0.8 required changing a few things.

opensocial.DataRequest.PersonId.OWNER;
opensocial.DataRequest.PersonId.VIEWER;

respectively become

opensocial.IdSpec.PersonId.OWNER;
opensocial.IdSpec.PersonId.VIEWER;

I then received the following error which hadn’t occured before.

data.get(opensocial.IdSpec.PersonId.OWNER) is undefined
[Break on this error] var owner = data.get(opensocial.IdSpec.PersonId.OWNER).getData();

It seems that request.add now takes two arguments, the second being a handle to extract the result from in the callback function.

dataReqObj = os.newDataRequest();
var viewerReq = os.newFetchPersonRequest(v);
//dataReqObj.add(viewerReq);
dataReqObj.add(viewerReq, 'viewer');
dataReqObj.send(viewerResponse);

function viewerResponse(data) {
//  var viewer = data.get(opensocial.IdSpec.PersonId.VIEWER).getData();
  var viewer = data.get('viewer').getData();
  heading = 'Hello, ' + viewer.getDisplayName();
  var has_app = viewer.getField(opensocial.Person.Field.HAS_APP);
  if (has_app) {
     heading += '<p>You have this app</p>';
  }
  document.getElementById('viewer').innerHTML = heading;
}

A detailed list of changes between 0.7 and 0.8 are listed here.

http://wiki.developer.myspace.com/index.php?title=OpenSocial_Version_0.8_Breaking_Changes

GPK of the Day TOMMY Tomb