MySpace / OpenSocial makeRequest examples

I just refactored some of my MySpace code this afternoon, to contact an outside server from an OpenSocial app you have to use the makeRequest call, here’s how my makeRequest wrapper looks like:

function makeRequestWrapper(target, callback) {
  try {
    var server_base_url = "http://dev-host.yourdomain.com/myspace"
    var params = {
      METHOD : 'GET',
      AUTHORIZATION : gadgets.io.AuthorizationType.SIGNED
    };
    gadgets.io.makeRequest(server_base_url + target, callback, params)
  } catch(er) {
    console.log(er.message);
  }
}

Here’s how you call this from the MySpace canvas surface:

function submitForm() {
  makeRequestWrapper(
    "/form_submit?" + $("#user_info_form").formSerialize(),
    function (data) {
      submitFormCallback(gadgets.json.parse(data.text));
    }
  )
}

In the userFormCallBack method, you can access the JSON object as arg.foo.

Method to perform makeRequest from the home and profile surfaces (I have no idea why they are different, but this works):

function retrieveHistory() {
  makeRequestWrapper("/show_history",
    function (data) { displayHistory(data); }
  )
}

Notice here you don’t need use data.text like you have to in the canvas surface. I found out that MySpace ignores the request type, on canvas it always returns a JSON object and if your server endpoint returns a JSON encoded object (like with render :json => my_hash.to_json in Rails ), it is stored in data.text, so you have to parse that with gadget.json.parse() to get another JSON object. On the home and profile surfaces it always returns HTML, you can parse the data as it (no need to use data.text), or you can just display the html returned with something like $(“div#blah”).html(data), if you use jQuery.

Building a Social Network Site in Rails | Jim Neath

This is pretty useful, I am working on another site but it won’t be much of a social site, but I am definitely using quite a few of the plugins in this list. (instead of acts_as_taggable_on_steroids we’re trying to use acts_as_taggable_on). I also think cache_fu will be a must-have if you ever think the site is gonna have real traffic.


Building a Social Network Site in Rails | Jim Neath

spectacles for humans: New brand alert

This is pretty awesome, and yeah, Oliver People sucks and this stuff is probably gonna suck more. Sadly, they will probably still sell well just because lots of people will still buy them.

There are some styles in the sunglass collection that are mildly attractive, with semi-original (as in “forgotten”) touches, but the ophthalmic line-up needs complete and serious reforestation.

THE VERDICT: Never coming to Spectacles for Humans.

UPDATE: Well…Few hours after the post went online, we received a polite phone call from BartonPerreira people saying they could not help but notice the write up and asking if they can show us the collection in person.

O….K….Sure. We’ll look, but we not changing our minds. And besides, you will do well in stores that you’re already in.

[From spectacles for humans: New brand alert]