Merge lp:~mardy/unity-webapps-qml/oa-api2 into lp:unity-webapps-qml

Proposed by Alberto Mardegan
Status: Superseded
Proposed branch: lp:~mardy/unity-webapps-qml/oa-api2
Merge into: lp:unity-webapps-qml
Diff against target: 688 lines (+136/-386)
5 files modified
examples/api-bindings/online-accounts/www/index.html (+13/-4)
examples/api-bindings/online-accounts/www/js/app.js (+45/-36)
src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js (+23/-13)
src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js (+51/-333)
src/Ubuntu/UnityWebApps/common/js/unity-binding-bridge.js (+4/-0)
To merge this branch: bzr merge lp:~mardy/unity-webapps-qml/oa-api2
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+208369@code.launchpad.net

This proposal has been superseded by a proposal from 2014-02-26.

Commit message

API cleanups

Add a getAccounts() method, and remove the getAccountsInfoFor() and getAccessTokenFor() methods.

Description of the change

API cleanups

Add a getAccounts() method, and remove the getAccountsInfoFor() and getAccessTokenFor() methods.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/api-bindings/online-accounts/www/index.html'
2--- examples/api-bindings/online-accounts/www/index.html 2014-01-17 15:51:27 +0000
3+++ examples/api-bindings/online-accounts/www/index.html 2014-02-26 13:33:27 +0000
4@@ -8,15 +8,24 @@
5 <body>
6
7 <div>
8- Service: <input type="text" id="service"></input>
9- Get authentication token: <input type="button" id="getauth"></input>
10- </div>
11- <div>
12 Results:
13 <div id="results">
14 </div>
15 </div>
16
17+ <div style="margin-top: 30px">
18+ <div>
19+ Provider: <input type="text" id="provider"></input>
20+ Service: <input type="text" id="service"></input>
21+ <input type="button" id="refreshAccounts" value="List accounts"></input>
22+ </div>
23+ Accounts (click on an account to authenticate):
24+ <div id='accounts'>
25+ <ul>
26+ </ul>
27+ </div>
28+ </div>
29+
30 </body>
31
32 </html>
33
34=== modified file 'examples/api-bindings/online-accounts/www/js/app.js'
35--- examples/api-bindings/online-accounts/www/js/app.js 2014-02-09 15:35:36 +0000
36+++ examples/api-bindings/online-accounts/www/js/app.js 2014-02-26 13:33:27 +0000
37@@ -1,43 +1,52 @@
38 window.onload = function() {
39- document.getElementById('getauth').addEventListener('click', doGetAuth);
40+ document.getElementById('refreshAccounts').addEventListener('click', listAccounts);
41+
42+ var api = external.getUnityObject('1.0');
43+ var oa = api.OnlineAccounts;
44+
45+ function listAccounts() {
46+ var filters = {};
47+ var service = document.getElementById('service').value;
48+ if (service) {
49+ filters['service'] = service
50+ }
51+ var provider = document.getElementById('provider').value;
52+ if (provider) {
53+ filters['provider'] = provider
54+ }
55+
56+ oa.api.getAccounts(filters, function(accounts) {
57+ var ul = document.querySelector('#accounts ul');
58+ if (accounts.length === 0) {
59+ var li = document.createElement('li');
60+ li.appendChild(document.createTextNode('No accounts found'));
61+ ul.appendChild(li);
62+ }
63+ else {
64+ for(var i = 0; i < accounts.length; ++i) {
65+ var li = document.createElement('li');
66+ li.innerHTML = 'id: ' + accounts[i].accountId()
67+ + ', name: ' + accounts[i].displayName()
68+ + ', provider: ' + JSON.stringify(accounts[i].provider())
69+ + ', service: ' + JSON.stringify(accounts[i].service());
70+ ul.appendChild(li);
71+
72+ (function(i) {
73+ function authcallback(results) {
74+ setResults('Authentication result: ' + JSON.stringify(results));
75+ };
76+
77+ li.addEventListener('click', function() {
78+ accounts[i].authenticate(authcallback);
79+ });
80+ })(i);
81+ }
82+ }
83+ });
84+ }
85
86 function setResults(data) {
87 var results = document.getElementById('results');
88 results.innerHTML += data;
89 };
90-
91- function doGetAuth() {
92- setResults('');
93-
94- var api = external.getUnityObject('1.0');
95- var oa = api.OnlineAccounts;
96-
97- oa.api.getAccountsInfoFor(null, 'facebook', function(result) {
98- if (result.length != undefined && result.length === 0) {
99- setResults("No account found");
100- }
101- else {
102- for (var i = 0; i < result.length; ++i) {
103- setResults("name: " + result[i].displayName
104- + ', id: ' + result[i].accountId
105- + ', providerName: ' + result[i].providerName
106- + ', serviceName: ' + result[i].serviceName
107- + ', enabled: ' + (result[i].enabled ? "true" : "false")
108- + '<br>');
109- }
110- }
111-
112- oa.api.getAccessTokenFor(null, 'facebook', null, function(result) {
113- if (result.error) {
114- setAuthToken("Error: " + result.error);
115- return;
116- }
117-
118- setResults("<br><br>Authenticated: "
119- + result.authenticated
120- + ", token: "
121- + result.data);
122- });
123- });
124- }
125 };
126
127=== modified file 'src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js'
128--- src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js 2014-02-11 01:10:34 +0000
129+++ src/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js 2014-02-26 13:33:27 +0000
130@@ -155,8 +155,9 @@
131 return "";
132 var extracted = "";
133 for (var p in params) {
134- if (params.hasOwnProperty(p))
135+ if (params.hasOwnProperty(p) && params[p] != null) {
136 extracted += p + ":" + JSON.stringify(params[p]) + "; ";
137+ }
138 }
139 return extracted;
140 }
141@@ -621,7 +622,7 @@
142 onAuthenticated = function(reply) {
143 callback({error: null,
144 authenticated: true,
145- data: reply.AccessToken});
146+ data: reply});
147
148 self._object.onAuthenticated.disconnect(onAuthenticated);
149 self._object.onAuthenticationError.disconnect(onAuthenticationError);
150@@ -783,9 +784,9 @@
151 }
152 };
153
154- function AccountServiceModel() {
155+ function AccountServiceModel(filterParams) {
156 var result = backendDelegate.createQmlObject(
157- PLUGIN_URI, VERSION, 'AccountServiceModel');
158+ PLUGIN_URI, VERSION, 'AccountServiceModel', filterParams);
159 this._id = result.id;
160 this._object = result.object;
161
162@@ -901,7 +902,7 @@
163 internal: {
164
165 // special case for an object wrapper
166- accountServiceHandleAtIndex: function(self, idx) {
167+ accountServiceAtIndex: function(self, idx) {
168 self._validate();
169
170 var accountServiceHandle = self._modelAdaptor.itemAt(idx, "accountServiceHandle");
171@@ -961,15 +962,9 @@
172
173 // api
174 getAccountsInfoFor: function(service, provider, callback) {
175- var serviceModel = new AccountServiceModel();
176-
177- if (service)
178- serviceModel.setService(service);
179- if (provider)
180- serviceModel.setProvider(provider);
181+ var serviceModel = new AccountServiceModel({'service': service, 'provider': provider});
182
183 var count = serviceModel.internal.count(serviceModel);
184- console.log(count)
185 var accountsInfo = []
186 for (var i = 0; i < count; ++i) {
187 var displayName = serviceModel.internal.itemAt(serviceModel, i, "displayName");
188@@ -990,6 +985,21 @@
189 callback(accountsInfo);
190 },
191
192+ getAccounts: function(filters, callback) {
193+ var serviceModel = new AccountServiceModel(filters);
194+ var count = serviceModel.internal.count(serviceModel);
195+ var accounts = []
196+ for (var i = 0; i < count; ++i) {
197+ var service = serviceModel.internal.accountServiceAtIndex(serviceModel, i);
198+ if (service) {
199+ var s = service.serialize();
200+ console.debug(JSON.stringify(s.content))
201+ accounts.push(s);
202+ }
203+ }
204+ callback(accounts);
205+ },
206+
207 getAccountById: function(accountId, callback) {
208 var manager = new Manager();
209 var account = manager.internal.loadAccount(manager, accountId);
210@@ -1018,7 +1028,7 @@
211 callback(results);
212 };
213 serviceModel.internal
214- .accountServiceHandleAtIndex(serviceModel, accountIdx)
215+ .accountServiceAtIndex(serviceModel, accountIdx)
216 .authenticate(onAuthenticated);
217 }
218 else {
219
220=== modified file 'src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js'
221--- src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2014-02-10 19:03:49 +0000
222+++ src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js 2014-02-26 13:33:27 +0000
223@@ -8,33 +8,54 @@
224 var PLUGIN_URI = 'OnlineAccounts';
225
226 /**
227- * Account represents an single online account.
228+ * AccountService.
229
230- * @class Account
231+ * @class AccountService
232 * @constructor
233 */
234- function Account(id, content) {
235+ function AccountService(id, content) {
236 this._proxy = backendBridge.createRemoteObject(
237- PLUGIN_URI, 'Account', id);
238+ PLUGIN_URI, 'AccountService', id);
239
240 this._accountId = content && content.accountId
241 ? content.accountId : null;
242+ this._enabled = content && content.enabled
243+ ? content.enabled : null;
244+ this._serviceEnabled = content && content.serviceEnabled
245+ ? content.serviceEnabled : null;
246+ this._displayName = content && content.displayName
247+ ? content.displayName : null;
248 this._provider = content && content.provider
249 ? content.provider : null;
250+ this._service = content && content.service
251+ ? content.service : null;
252 };
253- Account.prototype = {
254-
255+ AccountService.prototype = {
256 // properties
257+ accountId: function(callback) {
258+ if (callback && typeof(callback) === 'function') {
259+ this._proxy.call('accountId', [], callback);
260+ return;
261+ }
262+ return this._accountId;
263+ },
264
265 enabled: function(callback) {
266- this._proxy.call('enabled', [], callback);
267+ if (callback && typeof(callback) === 'function') {
268+ this._proxy.call('enabled', [], callback);
269+ return;
270+ }
271+ return this._enabled;
272 },
273
274 displayName: function(callback) {
275- this._proxy.call('displayName', [], callback);
276+ if (callback && typeof(callback) === 'function') {
277+ this._proxy.call('displayName', [], callback);
278+ return;
279+ }
280+ return this._displayName;
281 },
282
283- // immutable
284 provider: function(callback) {
285 if (callback && typeof(callback) === 'function') {
286 this._proxy.call('provider', [], callback);
287@@ -43,86 +64,12 @@
288 return this._provider;
289 },
290
291- // immutable
292- accountId: function(callback) {
293+ service: function(callback) {
294 if (callback && typeof(callback) === 'function') {
295- this._proxy.call('accountId', [], callback);
296+ this._proxy.call('service', [], callback);
297 return;
298 }
299- return this._accountId;
300- },
301-
302- // method
303-
304- updateDisplayName: function(displayName) {
305- this._proxy.call('displayName', []);
306- },
307-
308- updateEnabled: function(enabled) {
309- this._proxy.call('updateEnabled', [enabled]);
310- },
311-
312- remove: function(enabled) {
313- this._proxy.call('remove', [enabled]);
314- },
315-
316- // extras
317-
318- destroy: function() {
319- this._proxy.call('destroy', []);
320- },
321- };
322-
323-/**
324- * AccountService.
325-
326- * @class AccountService
327- * @constructor
328- */
329- function AccountService(id) {
330- this._proxy = backendBridge.createRemoteObject(
331- PLUGIN_URI, 'AccountService', id);
332- };
333- AccountService.prototype = {
334- // properties
335- accountId: function(callback) {
336- this._proxy.call('accountId', [], callback);
337- },
338- setAccountId: function(accountId) {
339- this._proxy.call('setAccountId', [accountId]);
340- },
341-
342- enabled: function(callback) {
343- this._proxy.call('enabled', [], callback);
344- },
345- setEnabled: function(enabled) {
346- this._proxy.call('setEnabled', [enabled]);
347- },
348-
349- serviceEnabled: function(callback) {
350- this._proxy.call('serviceEnabled', [], callback);
351- },
352- setServiceEnabled: function(serviceEnabled) {
353- this._proxy.call('setServiceEnabled', [serviceEnabled]);
354- },
355-
356- autoSync: function(callback) {
357- this._proxy.call('autoSync', [], callback);
358- },
359- setAutoSync: function(autoSync) {
360- this._proxy.call('setAutoSync', [autoSync]);
361- },
362-
363- displayName: function(callback) {
364- this._proxy.call('displayName', [], callback);
365- },
366-
367- provider: function(callback) {
368- this._proxy.call('provider', [], callback);
369- },
370-
371- service: function(callback) {
372- this._proxy.call('service', [], callback);
373+ return this._service;
374 },
375
376 // methods
377@@ -138,151 +85,8 @@
378 },
379 };
380
381- function Manager(id) {
382- this._proxy = backendBridge.createRemoteObject(
383- PLUGIN_URI, 'Manager', id);
384- };
385- Manager.prototype = {
386- createAccount: function(providerName, callback) {
387- this._proxy.call('createAccount', [providerName], callback);
388- },
389- loadAccount: function(id, callback) {
390- this._proxy.call('loadAccount', [id], callback);
391- },
392-
393- // extras
394-
395- destroy: function() {
396- this._proxy.call('destroy', []);
397- },
398- };
399-
400- function ProviderModel(id) {
401- this._proxy = backendBridge.createRemoteObject(
402- PLUGIN_URI, 'ProviderModel', id);
403- };
404- ProviderModel.prototype = {
405- // properties
406- count: function(callback) {
407- this._proxy.call('count', [], callback);
408- },
409-
410- applicationId: function(callback) {
411- this._proxy.call('applicationId', [], callback);
412- },
413- setApplicationId: function(applicationId, callback) {
414- this._proxy.call('setApplicationId', [applicationId, callback]);
415- },
416-
417- // QAbtractListModel prototype
418-
419- at: function(idx, callback) {
420- this._proxy.call('at',
421- [idx],
422- callback);
423- },
424-
425- // extras
426-
427- destroy: function() {
428- this._proxy.call('destroy', []);
429- },
430- };
431-
432- function AccountServiceModel(id) {
433- this._proxy = backendBridge.createRemoteObject(
434- PLUGIN_URI, 'AccountServiceModel', id);
435- };
436- AccountServiceModel.prototype = {
437- // properties
438- count: function(callback) {
439- this._proxy.call('count', [], callback);
440- },
441-
442- service: function(callback) {
443- this._proxy.call('service', [], callback);
444- },
445- setService: function(service, callback) {
446- this._proxy.call('setService', [service, callback]);
447- },
448-
449- provider: function(callback) {
450- this._proxy.call('provider', [], callback);
451- },
452- setProvider: function(provider, callback) {
453- this._proxy.call('setProvider', [provider, callback]);
454- },
455-
456- serviceType: function(callback) {
457- this._proxy.call('serviceType', [], callback);
458- },
459- setServiceType: function(serviceType, callback) {
460- this._proxy.call('setServiceType', [serviceType, callback]);
461- },
462-
463- includeDisabled: function(callback) {
464- this._proxy.call('includeDisabled', [], callback);
465- },
466- setIncludeDisabled: function(includeDisabled, callback) {
467- this._proxy.call('setIncludeDisabled', [includeDisabled, callback]);
468- },
469-
470- accountId: function(callback) {
471- this._proxy.call('accountId', [], callback);
472- },
473- setAccountId: function(accountId, callback) {
474- this._proxy.call('setAccountId', [accountId, callback]);
475- },
476-
477- // QAbtractListModel prototype
478-
479- at: function(idx, callback) {
480- this._proxy.call('at',
481- [idx],
482- callback);
483- },
484-
485- // extras
486-
487- destroy: function() {
488- this._proxy.call('destroy', []);
489- },
490- };
491-
492- function ApplicationModel(id) {
493- this._proxy = backendBridge.createRemoteObject(
494- PLUGIN_URI, 'ApplicationModel', id);
495- };
496- ApplicationModel.prototype = {
497- // method
498- service: function(callback) {
499- this._proxy.call('service', [], callback);
500- },
501- setService: function(service, callback) {
502- this._proxy.call('setService', [service, callback]);
503- },
504-
505- // QAbtractListModel prototype
506-
507- at: function(idx, callback) {
508- this._proxy.call('at',
509- [idx],
510- callback);
511- },
512-
513- // extras
514-
515- destroy: function() {
516- this._proxy.call('destroy', []);
517- },
518- };
519-
520 function _constructorFromName(className) {
521 var constructorPerName = {
522- "AccountServiceModel": AccountServiceModel,
523- "Account": Account,
524- "ProviderModel": ProviderModel,
525- "Manager": Manager,
526 "AccountService": AccountService,
527 };
528 return className in constructorPerName
529@@ -301,126 +105,40 @@
530 var api = external.getUnityObject(1.0);
531 var oa = api.OnlineAccounts;
532
533- oa.api.getAccountsInfoFor(null, 'facebook', function(result) { [...] });
534+ oa.api.getAccounts({'provider': 'facebook'}, function(result) { [...] });
535 */
536 return {
537
538- Account: {
539- RemovalOptions: {
540- RemoveAccountOnly: 0,
541- RemoveCredentials: 1
542- }
543- },
544-
545- /**
546- * Creates a AccountServiceModel object.
547- *
548- * @method createAccountServiceModel
549- * @param callback {Function (ProviderModel)}
550- */
551- createAccountServiceModel: function(callback) {
552- backendBridge.call('OnlineAccounts.createAccountServiceModel'
553- , []
554- , callback);
555- },
556-
557- /**
558- * Creates a Manager object.
559- *
560- * @method createManager
561- * @param callback {Function (Manager)}
562- */
563- createManager: function(callback) {
564- backendBridge.call('OnlineAccounts.createManager'
565- , []
566- , callback);
567- },
568-
569- /**
570- * Creates a ProviderModel object.
571- *
572- * @method createProviderModel
573- * @param callback {Function (ProviderModel)}
574- */
575- createProviderModel: function(callback) {
576- backendBridge.call('OnlineAccounts.createProviderModel'
577- , []
578- , callback);
579- },
580-
581 api: {
582 /**
583- * Gets the access token for a given set of filtering parameters.
584- *
585- * @method api.getAccessTokenFor
586- * @param service {String} If set, the access token will be retrieved for the accounts that correspond to that specific service.
587- * @param provider {String} If set, the access token will be retrieved for the accounts that correspond to that specific service.
588- * @param accountId {Integer} If set, the access token will be retrieved for the accounts that correspond to that specific service.
589- * It is used when multiple accounts are found, otherwise the first account is selected.
590- * @param callback {Function(Object(error:, authenticated: Bool, data: ))} Callback that receives the result or null
591- *
592- * @example
593-
594- var api = external.getUnityObject(1.0);
595- var oa = api.OnlineAccounts;
596-
597- oa.api.getAccessTokenFor(null, 'facebook', null, function(result) {
598- if (result.error) {
599- console.log("Error: " + result.error);
600- return;
601- }
602- console.log("Authenticated: "
603- + result.authenticated
604- + ", token: "
605- + result.data);
606- });
607- */
608- getAccessTokenFor: function(service, provider, accountId, callback) {
609- backendBridge.call('OnlineAccounts.getAccessTokenFor'
610- , [service, provider, accountId]
611- , callback);
612- },
613-
614- /**
615- * Gets the account information for a given set of filtering parameters.
616- *
617- * @method api.getAccountsInfoFor
618- * @param service {String} If set, the access token will be retrieved for the accounts that correspond to that specific service.
619- * @param provider {String} If set, the access token will be retrieved for the accounts that correspond to that specific service.
620- * @param callback {Function(List of Object(displayName:, accountId: Bool, providerName: String, serviceName: String, enabled: Bool))} Callback that receives the result or null
621+ * Gets the configured accounts satisfying the given filters.
622+ *
623+ * @method api.getAccounts
624+ * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
625+ * - application: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
626+ * - provider: the ID of a provider (see /usr/share/accounts/providers/ or ~/.local/share/accounts/providers/ for a list of the available providers)
627+ * - service: the ID of a service (see /usr/share/accounts/services/ or ~/.local/share/accounts/services/ for a list of the available services)
628+ *
629+ * @param callback {Function(List of AccountService objects)} Callback that receives the result or null
630 *
631 * @example
632 var api = external.getUnityObject(1.0);
633 var oa = api.OnlineAccounts;
634
635- oa.api.getAccountsInfoFor(null, 'facebook', function(result) {
636+ oa.api.getAccounts({'provider': 'facebook'}, function(result) {
637 for (var i = 0; i < result.length; ++i) {
638- console.log("name: " + result[i].displayName
639- + ', id: ' + result[i].accountId
640- + ', providerName: ' + result[i].providerName
641- + ', serviceName: ' + result[i].serviceName
642- + ', enabled: ' + (result[i].enabled ? "true" : "false")
643+ console.log("name: " + result[i].displayName()
644+ + ', id: ' + result[i].accountId()
645+ + ', providerName: ' + result[i].provider().displayName
646+ + ', enabled: ' + (result[i].enabled() ? "true" : "false")
647 );
648 }
649 });
650
651 */
652- getAccountsInfoFor: function(service, provider, callback) {
653- backendBridge.call('OnlineAccounts.getAccountsInfoFor'
654- , [service, provider]
655- , callback);
656- },
657-
658- /**
659- * Gets the account that corresponds to a given id.
660- *
661- * @method api.getAccountById
662- * @param accountId {Integer} The account id.
663- * @param callback {Function(Account)} Callback that receives the result or null
664- */
665- getAccountById: function(accountId, callback) {
666- backendBridge.call('OnlineAccounts.getAccountById'
667- , [accountId]
668+ getAccounts: function(filters, callback) {
669+ backendBridge.call('OnlineAccounts.getAccounts'
670+ , [filters]
671 , callback);
672 },
673 },
674
675=== modified file 'src/Ubuntu/UnityWebApps/common/js/unity-binding-bridge.js'
676--- src/Ubuntu/UnityWebApps/common/js/unity-binding-bridge.js 2014-01-21 19:58:04 +0000
677+++ src/Ubuntu/UnityWebApps/common/js/unity-binding-bridge.js 2014-02-26 13:33:27 +0000
678@@ -172,6 +172,10 @@
679 arg.content);
680 return narg;
681 }
682+ else if (arg instanceof Array) {
683+ return self._translateArgs(arg);
684+ }
685+
686 return arg;
687 });
688 return _args;

Subscribers

People subscribed via source and target branches

to all changes: