~abreu-alexandre/unity-webapps-qml/rtm-backport-oa-api-requestaccount

« back to all changes in this revision

Viewing changes to src/Ubuntu/UnityWebApps/bindings/online-accounts/client/online-accounts.js

  • Committer: Alexandre Abreu
  • Date: 2015-03-06 15:15:15 UTC
  • Revision ID: alexandre.abreu@canonical.com-20150306151515-jgna0xohbfb3itu3
backport requestAccount() for OA API

Show diffs side-by-side

added added

removed removed

Lines of Context:
161
161
             *
162
162
             * @method api.getAccounts
163
163
             * @param filters {Object} A dictionary of parameters to filter the result. The filtering keys are:
164
 
             * - application: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
 
164
             * - applicationId: the ID of a application (see /usr/share/accounts/applications/ or ~/.local/share/accounts/applications/ for a list of the available applications)
165
165
             * - provider: the ID of a provider (see /usr/share/accounts/providers/ or ~/.local/share/accounts/providers/ for a list of the available providers)
166
166
             * - service: the ID of a service (see /usr/share/accounts/services/ or ~/.local/share/accounts/services/ for a list of the available services)
167
167
             *
215
215
                                   , [filters]
216
216
                                   , callback);
217
217
            },
 
218
            /**
 
219
             * Requests access to an account.
 
220
             *
 
221
             * Applications must invoke this method in order to obtain access
 
222
             * to an account.  The user will be prompted to grant access to
 
223
             * either an existing account, to create a new one or to decline
 
224
             * the request.
 
225
             *
 
226
             * @method api.requestAccount
 
227
             * @param applicationId {String} The ID of the application
 
228
             * requesting the account (see /usr/share/accounts/applications/ or
 
229
             * ~/.local/share/accounts/applications/ for a list of the
 
230
             * available applications)
 
231
             * @param providerId {String} The ID of the provider of the desired
 
232
             * account (see /usr/share/accounts/providers/ or
 
233
             * ~/.local/share/accounts/providers/ for a list of the available
 
234
             * providers)
 
235
             * @param callback {Function()} Callback which will be invoked
 
236
             * after the access request has been decided (either with the
 
237
             * access to an account being granted, or with a refusal).
 
238
             *
 
239
             * @example
 
240
               var api = external.getUnityObject(1.0);
 
241
               var oa = api.OnlineAccounts;
 
242
 
 
243
               var appId = 'com.ubuntu.developer.me.MyPackage_MyApp';
 
244
               oa.api.requestAccount(appId,
 
245
                                     'facebook',
 
246
                                     function() {
 
247
                 oa.api.getAccounts({ 'application': appId }, function(result) {
 
248
                   for (var i = 0; i < result.length; ++i) {
 
249
                     console.log("name: " + result[i].displayName()
 
250
                                 + ', id: ' + result[i].accountId()
 
251
                                 + ', providerName: ' + result[i].provider().displayName
 
252
                                 + ', enabled: ' + (result[i].enabled() ? "true" : "false")
 
253
                                 );
 
254
                   }
 
255
                 });
 
256
               });
 
257
             */
 
258
            requestAccount: function(applicationId, providerId, callback) {
 
259
                backendBridge.call('OnlineAccounts.Client.requestAccount',
 
260
                                   [ applicationId, providerId],
 
261
                                   callback);
 
262
            },
218
263
        },
219
264
 
220
265