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