RIAction Social Applications in the Cloud 20090226
1. Gadgets and Social Applications
With OpenSocial
Vinoaj Vijeyakumaar
Customer Solutions Engineer
Google Southeast Asia
http://friendfeed.com/vinoaj
1
Google Confidential and Proprietary
21. First Stop
OpenSocial.org
Also a social network (surprise surprise!)
21
22. A day in the life of a social app developer
22
23. A day in the life of a social app developer
23
24. A day in the life of a social app developer
24
25. A day in the life of a social app developer
25
26. A day in the life of a social app developer
26
27. Gadgets
A gadget spec:
ā¢ Is an XML file.
ā¢ Defines metadata about an OpenSocial app.
ā¢ Is highly cacheable and does not need a high performance server.
Gadgets use existing web standards
ā¢ XML to define metadata.
ā¢ HTML for markup.
ā¢ JavaScript for interactivity.
ā¢ CSS for presentation.
27
28. Gadgets
Example gadget XML spec:
ā¢ Uses HTML to print āHello Worldā.
ā¢ Colors the text red with CSS.
ā¢ Dynamically adjusts the height of the gadget with JavaScript.
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?>
<Module>
<ModulePrefs title=quot;Hello World!quot;>
<Require feature=quot;dynamic-heightquot; />
</ModulePrefs>
<Content type=quot;htmlquot;>
<![CDATA[
<h1>Hello World</h1>
<style type=quot;text/cssquot;>
h1 { color: #dd0000; }
</style>
<script type=quot;text/javascriptquot;>
gadgets.window.adjustHeight();
</script> ]]> </Content></Module>
28
29. Gadgets
JavaScript utility functions for gadgets:
ā¢gadgets.io.makeRequest()
Make cross-domain AJAX calls to remote servers.
ā¢gadgets.json.parse() and gadgets.json.stringify()
Native JSON support.
ā¢gadgets.util.escapeString()
Make text safe for display via innerHTML.
ā¢gadgets.util.registerOnLoadHandler()
Execute code when the page is finished loading.
29
30. Gadgets
Add extra features to your gadget:
ā¢ dynamic-height - Change the size of your gadget in the container.
ā¢ views - Navigate between different surfaces of the container.
ā¢ skins - Make your gadget change its styles to match the container.
ā¢ Containers may offer custom features...
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?>
<Module>
<ModulePrefs title=quot;Hello World!quot;>
<Require feature=quot;dynamic-heightquot; />
</ModulePrefs>
<Content type=quot;htmlquot;>
<![CDATA[ ... ]]>
</Content>
</Module>
30
31. Gadgets
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot; ?>
<Module>
<ModulePrefs title=quot;Hello Social!quot;>
<Require feature=quot;opensocial-0.8quot; />
</ModulePrefs>
<Content type=quot;htmlquot;>
<![CDATA[ ... ]]>
</Content>
</Module>
The OpenSocial JavaScript API is a gadget feature, too!
31
37. The OpenSocial JavaScript API
Working with people:
ā¢ A Collection represents many opensocial.Person objects.
37
38. The OpenSocial JavaScript API
Working with data:
ā¢ Persistent data gives apps key, value storage directly on the container.
ā¢ String only, but conversion to JSON allows for storage of complex
objects.
ā¢ Storage per app per user - scales well with growth.
ā¢ Ideal for settings, customizations.
38
39. The OpenSocial JavaScript API
Working with activities:
ā¢ API to post information about what users are doing with your app.
ā¢ Many containers have support for images and some HTML.
ā¢ Channel to grow your application.
orkut MySpace hi5
39
40. The OpenSocial JavaScript API
Post an activity:
function postActivity(text) {
var params = {};
params[opensocial.Activity.Field.TITLE] = text;
var activity = opensocial.newActivity(params);
opensocial.requestCreateActivity(activity,
opensocial.CreateActivityPriority.HIGH, callback);
};
ā¢ Assign the activity text to the TITLE field.
ā¢ Call opensocial.newActivity() to create a new Activity instance.
ā¢ Call opensocial.requestCreateActivity() to post the activity to the
container.
40
42. RESTful and RPC protocols
Opens new development models
ā¢Background processing.
ā¢Easier Flash integration.
ā¢Mobile applications.
42
43. RESTful and RPC protocols
Communication methods:
ā¢ RESTful (Representational State Transfer)
ā¢ RPC (Remote Procedure Call)
Formats:
ā¢ XML
ā¢ JSON
ā¢ AtomPub
43
44. RESTful and RPC protocols
REST:
ā¢ Resources are URLs.
Example - People:
ā¢ All people connected to the given user:
/people/{guid}/@all
ā¢ All friends of the given user:
/people/{guid}/@friends
ā¢ Profile of the given user:
/people/{guid}/@self
ā¢ Profile of the authenticated user:
/people/@me/@self
ā¢ Supported Person fields:
/people/@supportedFields
44
47. RESTful and RPC protocols
Authentication:
ā¢ Both protocols use OAuth to identify users and apps.
ā¢ Depending on what the application needs to do, it can use two-legged
or three-legged OAuth.
47
49. Shindig
Writing a gadget server is difficult:
ā¢ Fast changing API - hard to keep up.
ā¢ Standardization is hard to get right.
ā¢ Costs $ / Ā„ / å !
49
56. Challenges
Cross container development is still tricky:
ā¢ Containers may not follow the standard.
ā¢ Containers may follow the standard but have different policies.
ā¢ Follow best practices: http://tinyurl.com/4nuzll
56
57. Challenges
No central directory
ā¢ Hard for apps to spread to many containers.
ā¢ Apps need to work with different install processes.
ā¢ Directory approval requirements vary from container to container.
57