~webapps/unity-webapps-qml/15.04

« back to all changes in this revision

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

  • Committer: CI Train Bot
  • Author(s): Daniel Holbach
  • Date: 2015-04-09 13:29:10 UTC
  • mfrom: (148.1.5 unity-webapps-qml)
  • Revision ID: ci-train-bot@canonical.com-20150409132910-mmui8imfjseapg7f
Add ./update-docs script which generates API docs locally. We can't make this part of the build as not all node dependencies of yuidocsjs are packaged in the archive.
Approved by: PS Jenkins bot, David Barth

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!DOCTYPE html>
 
2
<html lang="en">
 
3
<head>
 
4
    <meta charset="utf-8">
 
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>
 
10
</head>
 
11
<body class="yui3-skin-sam">
 
12
 
 
13
<div id="doc">
 
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>
 
17
        </div>
 
18
        <div class="yui3-u-1-4 version">
 
19
            <em>API Docs for: 0.1</em>
 
20
        </div>
 
21
    </div>
 
22
    <div class="yui3-g">
 
23
 
 
24
        <div id="sidebar" class="yui3-u">
 
25
            <div id="modules" class="sidebox">
 
26
                <div class="hd">
 
27
                    <h2 class="no-toc">Modules</h2>
 
28
                </div>
 
29
                <div class="bd">
 
30
                    <ul>
 
31
                            <li><a href="../modules/OnlineAccounts.html">OnlineAccounts</a>
 
32
                            </li>
 
33
                    </ul>
 
34
                </div>
 
35
            </div>
 
36
            
 
37
            <div id="classes" class="sidebox">
 
38
                <div class="hd">
 
39
                    <h2 class="no-toc">Classes</h2>
 
40
                </div>
 
41
                <div class="bd">
 
42
                    <ul>
 
43
                            <li><a href="../classes/AccountService.html">AccountService</a></li>
 
44
                            <li><a href="../classes/OnlineAccounts.html">OnlineAccounts</a></li>
 
45
                    </ul>
 
46
                </div>
 
47
            </div>
 
48
            
 
49
            
 
50
            
 
51
            
 
52
            
 
53
            <div id="fileTree" class="sidebox">
 
54
                <div class="hd">
 
55
                    <h2 class="no-toc">Files</h2>
 
56
                </div>
 
57
                <div class="bd">
 
58
                    <ul><li>online-accounts.js/<ul></ul></li></ul>
 
59
                </div>
 
60
            </div>
 
61
            
 
62
        </div>
 
63
 
 
64
        <div id="main" class="yui3-u">
 
65
            <div class="content"><h4>online-accounts.js</h4>
 
66
 
 
67
<pre class="code prettyprint linenums">
 
68
    /**
 
69
 * OnlineAccounts is the entry point to online accounts service access.
 
70
 
 
71
 * @module OnlineAccounts
 
72
 */
 
73
 
 
74
function createOnlineAccountsApi(backendBridge) {
 
75
    var PLUGIN_URI = &#x27;OnlineAccounts&#x27;;
 
76
 
 
77
/**
 
78
 * AccountService represents an instance of a service in an Online Accounts.
 
79
 * 
 
80
 * The AcountService object is not directly constructible but returned as a result of
 
81
 * OnlineAccounts api calls.
 
82
 *
 
83
 * @class AccountService
 
84
 */
 
85
    function AccountService(id, content) {
 
86
        this._proxy = backendBridge.createRemoteObject(
 
87
            PLUGIN_URI, &#x27;AccountService&#x27;, id);
 
88
 
 
89
        this._accountId = content &amp;&amp; content.accountId
 
90
             ? content.accountId : null;
 
91
        this._enabled = content &amp;&amp; content.enabled
 
92
             ? content.enabled : null;
 
93
        this._serviceEnabled = content &amp;&amp; content.serviceEnabled
 
94
             ? content.serviceEnabled : null;
 
95
        this._displayName = content &amp;&amp; content.displayName
 
96
             ? content.displayName : null;
 
97
        this._provider = content &amp;&amp; content.provider
 
98
             ? content.provider : null;
 
99
        this._service = content &amp;&amp; content.service
 
100
             ? content.service : null;
 
101
    };
 
102
    AccountService.prototype = {
 
103
        // properties
 
104
 
 
105
        /**
 
106
         * Returns the account&#x27;s numeric ID; note that all
 
107
         * AccountService objects which work on the same online account will have the same ID.
 
108
         *
 
109
         * @method accountId
 
110
         * @return {String} Value for the accountId
 
111
         */
 
112
        accountId: function() {
 
113
            return this._accountId;
 
114
        },
 
115
 
 
116
        /**
 
117
         * This read-only property returns whether the AccountService is enabled.
 
118
         * An application shouldn&#x27;t use an AccountService which is disabled
 
119
         *
 
120
         * @method enabled
 
121
         * @return {Boolean} Value for the enabled flag
 
122
         */
 
123
        enabled: function() {
 
124
            return this._enabled;
 
125
        },
 
126
 
 
127
        /**
 
128
         * Returns The account&#x27;s display name (usually the user&#x27;s login or ID).
 
129
         * Note that all AccountService objects which work on the same online account
 
130
         * will share the same display name.
 
131
         *
 
132
         * @method displayName
 
133
         * @return {String} Value of the displayName
 
134
         */
 
135
        displayName: function() {
 
136
            return this._displayName;
 
137
        },
 
138
 
 
139
        /**
 
140
         * Returns an object representing the provider which provides the account.
 
141
         * 
 
142
         * The returned object will have at least these properties:
 
143
         *   - &#x27;id&#x27; is the unique identifier for this provider
 
144
         *   - &#x27;displayName&#x27;
 
145
         *   - &#x27;iconName&#x27;
 
146
         * 
 
147
         * @method provider
 
148
         * @return {Object} Value object for the provider
 
149
         */
 
150
        provider: function() {
 
151
            return this._provider;
 
152
        },
 
153
 
 
154
        /**
 
155
         * Returns an object representing the service which this AccountService instantiates
 
156
         * 
 
157
         * The returned object will have at least these properties:
 
158
         *   - &#x27;id&#x27; is the unique identifier for this service
 
159
         *   - &#x27;displayName&#x27;
 
160
         *   - &#x27;iconName&#x27;
 
161
         *   - &#x27;serviceTypeId&#x27; identifies the provided service type
 
162
         * 
 
163
         * @method service
 
164
         * @return {Object} Value object for the service
 
165
         */
 
166
        service: function() {
 
167
            return this._service;
 
168
        },
 
169
 
 
170
        // methods
 
171
 
 
172
        /**
 
173
         * Perform the authentication on this account.
 
174
         * 
 
175
         * The callback will be called with the authentication result object which will have
 
176
         * these properties:
 
177
         *   - &#x27;error&#x27;: error message if the authentication was a failure
 
178
         *   - &#x27;authenticated&#x27;: boolean value that identifies if the operation was a success
 
179
         *   - &#x27;data&#x27;: Object with the data returned by the authentication process. An &#x27;AccessToken&#x27; property can be usually found (when it applies) with the OAuth access token.
 
180
         * 
 
181
         * If the callback parameter is not set, the current &quot;local&quot; value is retrieved.
 
182
         *
 
183
         * @method authenticate
 
184
         * @param callback {Function(Object)}
 
185
         */
 
186
        authenticate: function(callback) {
 
187
            this._proxy.call(&#x27;authenticate&#x27;, [callback]);
 
188
        },
 
189
 
 
190
        // extras
 
191
 
 
192
        /**
 
193
         * Destroys the remote object. This proxy object is not valid anymore.
 
194
         *
 
195
         * @method destroy
 
196
         */
 
197
        destroy: function() {
 
198
            this._proxy.call(&#x27;destroy&#x27;, []);
 
199
        },
 
200
    };
 
201
 
 
202
    function _constructorFromName(className) {
 
203
        var constructorPerName = {
 
204
            &quot;AccountService&quot;: AccountService,
 
205
        };
 
206
        return className in constructorPerName
 
207
                ? constructorPerName[className]
 
208
                : null;
 
209
    };
 
210
 
 
211
/**
 
212
 * The OnlineAccounts object is the entry point to online accounts service access.
 
213
 
 
214
 * @class OnlineAccounts
 
215
 * 
 
216
 * @example
 
217
 
 
218
        var api = external.getUnityObject(1.0);
 
219
        var oa = api.OnlineAccounts;
 
220
 
 
221
        oa.api.getAccounts({&#x27;provider&#x27;: &#x27;facebook&#x27;}, function(result) { [...] });
 
222
 */
 
223
   return {
 
224
 
 
225
        api: {
 
226
            /**
 
227
             * Gets the configured accounts satisfying the given filters.
 
228
             *
 
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)
 
234
             *
 
235
             * @param callback {Function(List of AccountService objects)} Callback that receives the result or null
 
236
             *
 
237
             * @example
 
238
               var api = external.getUnityObject(1.0);
 
239
               var oa = api.OnlineAccounts;
 
240
             
 
241
               oa.api.getAccounts({&#x27;provider&#x27;: &#x27;facebook&#x27;}, function(result) {
 
242
                 for (var i = 0; i &lt; result.length; ++i) {
 
243
                   console.log(&quot;name: &quot; + result[i].displayName()
 
244
                               + &#x27;, id: &#x27; + result[i].accountId()
 
245
                               + &#x27;, providerName: &#x27; + result[i].provider().displayName
 
246
                               + &#x27;, enabled: &#x27; + (result[i].enabled() ? &quot;true&quot; : &quot;false&quot;)
 
247
                               );
 
248
                 }               
 
249
               });
 
250
 
 
251
             */
 
252
            getAccounts: function(filters, callback) {
 
253
                backendBridge.call(&#x27;OnlineAccounts.getAccounts&#x27;
 
254
                                   , [filters]
 
255
                                   , callback);
 
256
            },
 
257
            /**
 
258
             * Gets list of available providers.
 
259
             *
 
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
 
267
             *
 
268
             * @example
 
269
               var api = external.getUnityObject(1.0);
 
270
               var oa = api.OnlineAccounts;
 
271
 
 
272
               oa.api.getProviders({}, function(result) {
 
273
                 for (var i = 0; i &lt; result.length; ++i) {
 
274
                   console.log(&quot;displayName: &quot; + result[i].displayName
 
275
                               + &#x27;, providerId: &#x27; + result[i].providerId);
 
276
                 }
 
277
               });
 
278
 
 
279
             */
 
280
            getProviders: function(filters, callback) {
 
281
                backendBridge.call(&#x27;OnlineAccounts.getProviders&#x27;
 
282
                                   , [filters]
 
283
                                   , callback);
 
284
            },
 
285
            /**
 
286
             * Requests access to an account.
 
287
             *
 
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
 
291
             * the request.
 
292
             *
 
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
 
301
             * providers)
 
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).
 
305
             *
 
306
             * @example
 
307
               var api = external.getUnityObject(1.0);
 
308
               var oa = api.OnlineAccounts;
 
309
 
 
310
               var appId = &#x27;com.ubuntu.developer.me.MyPackage_MyApp&#x27;;
 
311
               oa.api.requestAccount(appId,
 
312
                                     &#x27;facebook&#x27;,
 
313
                                     function() {
 
314
                 oa.api.getAccounts({ &#x27;application&#x27;: appId }, function(result) {
 
315
                   for (var i = 0; i &lt; result.length; ++i) {
 
316
                     console.log(&quot;name: &quot; + result[i].displayName()
 
317
                                 + &#x27;, id: &#x27; + result[i].accountId()
 
318
                                 + &#x27;, providerName: &#x27; + result[i].provider().displayName
 
319
                                 + &#x27;, enabled: &#x27; + (result[i].enabled() ? &quot;true&quot; : &quot;false&quot;)
 
320
                                 );
 
321
                   }
 
322
                 });
 
323
               });
 
324
             */
 
325
            requestAccount: function(applicationId, providerId, callback) {
 
326
                backendBridge.call(&#x27;OnlineAccounts.Client.requestAccount&#x27;,
 
327
                                   [ applicationId, providerId],
 
328
                                   callback);
 
329
            },
 
330
        },
 
331
 
 
332
 
 
333
        // Internal
 
334
 
 
335
        /**
 
336
         * @private
 
337
         *
 
338
         */
 
339
        createObjectWrapper: function(objectType, objectId, content) {
 
340
            var Constructor = _constructorFromName(objectType);
 
341
            return new Constructor(objectId, content);
 
342
        },
 
343
    };
 
344
};
 
345
 
 
346
 
 
347
 
 
348
</pre>
 
349
 
 
350
</div>
 
351
        </div>
 
352
    </div>
 
353
</div>
 
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>
 
358
</body>
 
359
</html>