5
<title>online-accounts.js - Online Accounts JS API</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.8.0pr2/build/cssgrids/cssgrids-min.css">
7
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
9
<script src="http://yui.yahooapis.com/combo?3.8.0pr2/build/yui/yui-min.js"></script>
11
<body class="yui3-skin-sam">
14
<div id="hd" class="yui3-g header">
15
<div class="yui3-u-3-4">
16
<h1><a href="../index.html"><img src="../assets/css/logo.png">Online Accounts JS API: online-accounts.js</a></h1>
18
<div class="yui3-u-1-4 version">
19
<em>API Docs for: 0.1</em>
24
<div id="sidebar" class="yui3-u">
25
<div id="modules" class="sidebox">
27
<h2 class="no-toc">Modules</h2>
31
<li><a href="../modules/OnlineAccounts.html">OnlineAccounts</a>
37
<div id="classes" class="sidebox">
39
<h2 class="no-toc">Classes</h2>
43
<li><a href="../classes/AccountService.html">AccountService</a></li>
44
<li><a href="../classes/OnlineAccounts.html">OnlineAccounts</a></li>
53
<div id="fileTree" class="sidebox">
55
<h2 class="no-toc">Files</h2>
58
<ul><li>online-accounts.js/<ul></ul></li></ul>
64
<div id="main" class="yui3-u">
65
<div class="content"><h4>online-accounts.js</h4>
67
<pre class="code prettyprint linenums">
69
* OnlineAccounts is the entry point to online accounts service access.
71
* @module OnlineAccounts
74
function createOnlineAccountsApi(backendBridge) {
75
var PLUGIN_URI = 'OnlineAccounts';
78
* AccountService represents an instance of a service in an Online Accounts.
80
* The AcountService object is not directly constructible but returned as a result of
81
* OnlineAccounts api calls.
83
* @class AccountService
85
function AccountService(id, content) {
86
this._proxy = backendBridge.createRemoteObject(
87
PLUGIN_URI, 'AccountService', id);
89
this._accountId = content && content.accountId
90
? content.accountId : null;
91
this._enabled = content && content.enabled
92
? content.enabled : null;
93
this._serviceEnabled = content && content.serviceEnabled
94
? content.serviceEnabled : null;
95
this._displayName = content && content.displayName
96
? content.displayName : null;
97
this._provider = content && content.provider
98
? content.provider : null;
99
this._service = content && content.service
100
? content.service : null;
102
AccountService.prototype = {
106
* Returns the account's numeric ID; note that all
107
* AccountService objects which work on the same online account will have the same ID.
110
* @return {String} Value for the accountId
112
accountId: function() {
113
return this._accountId;
117
* This read-only property returns whether the AccountService is enabled.
118
* An application shouldn't use an AccountService which is disabled
121
* @return {Boolean} Value for the enabled flag
123
enabled: function() {
124
return this._enabled;
128
* Returns The account's display name (usually the user's login or ID).
129
* Note that all AccountService objects which work on the same online account
130
* will share the same display name.
132
* @method displayName
133
* @return {String} Value of the displayName
135
displayName: function() {
136
return this._displayName;
140
* Returns an object representing the provider which provides the account.
142
* The returned object will have at least these properties:
143
* - 'id' is the unique identifier for this provider
144
* - 'displayName'
145
* - 'iconName'
148
* @return {Object} Value object for the provider
150
provider: function() {
151
return this._provider;
155
* Returns an object representing the service which this AccountService instantiates
157
* The returned object will have at least these properties:
158
* - 'id' is the unique identifier for this service
159
* - 'displayName'
160
* - 'iconName'
161
* - 'serviceTypeId' identifies the provided service type
164
* @return {Object} Value object for the service
166
service: function() {
167
return this._service;
173
* Perform the authentication on this account.
175
* The callback will be called with the authentication result object which will have
177
* - 'error': error message if the authentication was a failure
178
* - 'authenticated': boolean value that identifies if the operation was a success
179
* - 'data': Object with the data returned by the authentication process. An 'AccessToken' property can be usually found (when it applies) with the OAuth access token.
181
* If the callback parameter is not set, the current "local" value is retrieved.
183
* @method authenticate
184
* @param callback {Function(Object)}
186
authenticate: function(callback) {
187
this._proxy.call('authenticate', [callback]);
193
* Destroys the remote object. This proxy object is not valid anymore.
197
destroy: function() {
198
this._proxy.call('destroy', []);
202
function _constructorFromName(className) {
203
var constructorPerName = {
204
"AccountService": AccountService,
206
return className in constructorPerName
207
? constructorPerName[className]
212
* The OnlineAccounts object is the entry point to online accounts service access.
214
* @class OnlineAccounts
218
var api = external.getUnityObject(1.0);
219
var oa = api.OnlineAccounts;
221
oa.api.getAccounts({'provider': 'facebook'}, function(result) { [...] });
227
* Gets the configured accounts satisfying the given filters.
229
* @method api.getAccounts
230
* @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
231
* - applicationId: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
232
* - provider: the ID of a provider (see /usr/share/accounts/providers/ or ~/.local/share/accounts/providers/ for a list of the available providers)
233
* - service: the ID of a service (see /usr/share/accounts/services/ or ~/.local/share/accounts/services/ for a list of the available services)
235
* @param callback {Function(List of AccountService objects)} Callback that receives the result or null
238
var api = external.getUnityObject(1.0);
239
var oa = api.OnlineAccounts;
241
oa.api.getAccounts({'provider': 'facebook'}, function(result) {
242
for (var i = 0; i < result.length; ++i) {
243
console.log("name: " + result[i].displayName()
244
+ ', id: ' + result[i].accountId()
245
+ ', providerName: ' + result[i].provider().displayName
246
+ ', enabled: ' + (result[i].enabled() ? "true" : "false")
252
getAccounts: function(filters, callback) {
253
backendBridge.call('OnlineAccounts.getAccounts'
258
* Gets list of available providers.
260
* @method api.getProviders
261
* @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
262
* - applicationId: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
263
* @param callback {Function(List of AccountService objects)} Callback that receives the result or null.
264
* The result is a dictionary with the following keys:
265
* - displayName: the display name for the corresponding provider
266
* - providerId: the provider id
269
var api = external.getUnityObject(1.0);
270
var oa = api.OnlineAccounts;
272
oa.api.getProviders({}, function(result) {
273
for (var i = 0; i < result.length; ++i) {
274
console.log("displayName: " + result[i].displayName
275
+ ', providerId: ' + result[i].providerId);
280
getProviders: function(filters, callback) {
281
backendBridge.call('OnlineAccounts.getProviders'
286
* Requests access to an account.
288
* Applications must invoke this method in order to obtain access
289
* to an account. The user will be prompted to grant access to
290
* either an existing account, to create a new one or to decline
293
* @method api.requestAccount
294
* @param applicationId {String} The ID of the application
295
* requesting the account (see /usr/share/accounts/applications/ or
296
* ~/.local/share/accounts/applications/ for a list of the
297
* available applications)
298
* @param providerId {String} The ID of the provider of the desired
299
* account (see /usr/share/accounts/providers/ or
300
* ~/.local/share/accounts/providers/ for a list of the available
302
* @param callback {Function()} Callback which will be invoked
303
* after the access request has been decided (either with the
304
* access to an account being granted, or with a refusal).
307
var api = external.getUnityObject(1.0);
308
var oa = api.OnlineAccounts;
310
var appId = 'com.ubuntu.developer.me.MyPackage_MyApp';
311
oa.api.requestAccount(appId,
312
'facebook',
314
oa.api.getAccounts({ 'application': appId }, function(result) {
315
for (var i = 0; i < result.length; ++i) {
316
console.log("name: " + result[i].displayName()
317
+ ', id: ' + result[i].accountId()
318
+ ', providerName: ' + result[i].provider().displayName
319
+ ', enabled: ' + (result[i].enabled() ? "true" : "false")
325
requestAccount: function(applicationId, providerId, callback) {
326
backendBridge.call('OnlineAccounts.Client.requestAccount',
327
[ applicationId, providerId],
339
createObjectWrapper: function(objectType, objectId, content) {
340
var Constructor = _constructorFromName(objectType);
341
return new Constructor(objectId, content);
354
<script src="../assets/vendor/prettify/prettify-min.js"></script>
355
<script>prettyPrint();</script>
356
<script src="../assets/js/yui-prettify.js"></script>
357
<script src="../assets/js/tabs.js"></script>