3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 * @fileoverview Object used to request social information from the container.
18 * This includes data for friends, profiles, app data, and activities.
20 * All apps that require access to people information should send a dataRequest
21 * in order to receieve a dataResponse
28 * Used to request social information from the container.
29 * This includes data for friends, profiles, app data, and activities.
30 * All apps that require access to people information
31 * should send a DataRequest.
35 * Here's an example of creating, initializing, sending, and handling
36 * the results of a data request:
39 * <pre>function requestMe() {
40 var req = opensocial.newDataRequest();
41 req.add(req.newFetchPersonRequest(
42 opensocial.IdSpec.PersonId.VIEWER),
44 req.send(handleRequestMe);
47 function handleRequestMe(data) {
48 var viewer = data.get("viewer");
49 if (viewer.hadError()) {
50 <em>//Handle error using viewer.getError()...</em>
54 <em>//No error. Do something with viewer.getData()...</em>
59 * <a href="opensocial.html#newDataRequest"><code>
60 * opensocial.newDataRequest()</code></a>
63 * @name opensocial.DataRequest
67 * Do not create a DataRequest directly, instead use
68 * opensocial.createDataRequest();
73 opensocial.DataRequest = function() {};
77 * Get the requested objects
79 * @return {Array.<{key:String, request:BaseDataRequest}>}
80 * requestObjects An array of data requests that the container should fetch
84 opensocial.DataRequest.prototype.getRequestObjects = function() {};
88 * Adds an item to fetch (get) or update (set) data from the server.
89 * A single DataRequest object can have multiple items.
90 * As a rule, each item is executed in the order it was added,
91 * starting with the item that was added first.
92 * However, items that can't collide might be executed in parallel.
94 * @param {Object} request Specifies which data to fetch or update
95 * @param {String} opt_key A key to map the generated response data to
97 opensocial.DataRequest.prototype.add = function(request, opt_key) {};
101 * Sends a data request to the server in order to get a data response.
102 * Although the server may optimize these requests,
103 * they will always be executed
104 * as though they were serial.
106 * @param {Function} opt_callback The function to call with the
107 * <a href="opensocial.DataResponse.html">data response</a>
108 * generated by the server
110 opensocial.DataRequest.prototype.send = function(opt_callback) {};
116 * The sort orders available for ordering person objects.
118 * @name opensocial.DataRequest.SortOrder
120 opensocial.DataRequest.SortOrder = {
122 * When used will sort people by the container's definition of top friends.
123 * This field may be used interchangeably with the string 'topFriends'.
124 * @member opensocial.DataRequest.SortOrder
126 TOP_FRIENDS : 'topFriends',
128 * When used will sort people alphabetically by the name field.
129 * This field may be used interchangeably with the string 'name'.
130 * @member opensocial.DataRequest.SortOrder
139 * The filters available for limiting person requests.
141 * @name opensocial.DataRequest.FilterType
143 opensocial.DataRequest.FilterType = {
145 * Retrieves all friends.
146 * This field may be used interchangeably with the string 'all'.
147 * @member opensocial.DataRequest.FilterType
151 * Retrieves all friends that use this application.
153 * Note: Containers may define "use" in any manner they deem appropriate for
154 * their functionality, and it is not expected that this field will have
155 * the exact same semantics across containers.
156 * This field may be used interchangeably with the string 'hasApp'.
157 * @member opensocial.DataRequest.FilterType
161 * Retrieves only the user's top friends as defined by the container.
162 * Container support for this filter type is OPTIONAL.
163 * This field may be used interchangeably with the string 'topFriends'.
164 * @member opensocial.DataRequest.FilterType
166 TOP_FRIENDS : 'topFriends',
168 * Will filter the people requested by checking if they are friends with
169 * the given <a href="opensocial.IdSpec.html">idSpec</a>. Expects a filterOptions parameter to be passed with the
170 * following fields defined:
171 * - idSpec The <a href="opensocial.IdSpec.html">idSpec</a> that each person must be friends with.
172 * This field may be used interchangeably with the string 'isFriendsWith'.
173 * @member opensocial.DataRequest.FilterType
175 IS_FRIENDS_WITH: 'isFriendsWith'
182 * @name opensocial.DataRequest.PeopleRequestFields
184 opensocial.DataRequest.PeopleRequestFields = {
187 * <a href="opensocial.Person.Field.html">
188 * <code>opensocial.Person.Field</code></a>
189 * specifying what profile data to fetch
190 * for each of the person objects. The server will always include
191 * ID, NAME, and THUMBNAIL_URL.
192 * This field may be used interchangeably with the string 'profileDetail'.
193 * @member opensocial.DataRequest.PeopleRequestFields
195 PROFILE_DETAILS : 'profileDetail',
198 * A sort order for the people objects; defaults to TOP_FRIENDS.
199 * Possible values are defined by
200 * <a href="opensocial.DataRequest.SortOrder.html">SortOrder</a>.
201 * This field may be used interchangeably with the string 'sortOrder'.
202 * @member opensocial.DataRequest.PeopleRequestFields
204 SORT_ORDER : 'sortOrder',
207 * How to filter the people objects; defaults to ALL.
208 * Possible values are defined by
209 * <a href="opensocial.DataRequest.FilterType.html">FilterType</a>.
210 * This field may be used interchangeably with the string 'filter'.
211 * @member opensocial.DataRequest.PeopleRequestFields
216 * Additional options to be passed into the filter,
217 * specified as a Map<String, Object>.
218 * This field may be used interchangeably with the string 'filterOptions'.
219 * @member opensocial.DataRequest.PeopleRequestFields
221 FILTER_OPTIONS: 'filterOptions',
224 * When paginating, the index of the first item to fetch;
225 * specified as a number.
226 * This field may be used interchangeably with the string 'first'.
227 * @member opensocial.DataRequest.PeopleRequestFields
232 * The maximum number of items to fetch,
233 * specified as a number; defaults to 20. If set to a larger
234 * number, a container may honor the request, or may limit the number to a
235 * container-specified limit of at least 20.
236 * This field may be used interchangeably with the string 'max'.
237 * @member opensocial.DataRequest.PeopleRequestFields
244 * Creates an item to request a profile for the specified person ID.
245 * When processed, returns a
246 * <a href="opensocial.Person.html"><code>Person</code></a> object.
248 * @param {String} id The ID of the person to fetch; can be the standard
249 * <a href="opensocial.DataRequest.PersonId.html">person ID</a>
251 * @param {Map.<opensocial.DataRequest.PeopleRequestFields, Object>}
254 * <a href="opensocial.DataRequest.PeopleRequestFields.html">parameters</a>
255 * to pass to the request; this request supports PROFILE_DETAILS
256 * @return {Object} A request object
258 opensocial.DataRequest.prototype.newFetchPersonRequest = function(id,
263 * Creates an item to request friends from the server.
264 * When processed, returns a <a href="opensocial.Collection.html">Collection</a>
265 * <<a href="opensocial.Person.html">Person</a>> object.
267 * @param {opensocial.IdSpec} idSpec An IdSpec used to specify
268 * which people to fetch. See also <a href="opensocial.IdSpec.html">IdSpec</a>.
269 * @param {Map.<opensocial.DataRequest.PeopleRequestFields, Object>}
272 * <a href="opensocial.DataRequest.PeopleRequestFields.html">params</a>
273 * to pass to the request
274 * @return {Object} A request object
276 opensocial.DataRequest.prototype.newFetchPeopleRequest = function(idSpec,
283 * @name opensocial.DataRequest.DataRequestFields
285 opensocial.DataRequest.DataRequestFields = {
287 * How to escape person data returned from the server; defaults to HTML_ESCAPE.
288 * Possible values are defined by
289 * <a href="opensocial.EscapeType.html">EscapeType</a>.
290 * This field may be used interchangeably with the string 'escapeType'.
291 * @member opensocial.DataRequest.DataRequestFields
293 ESCAPE_TYPE : 'escapeType'
298 * Creates an item to request app data for the given people.
299 * When processed, returns a Map<
300 * <a href="opensocial.DataRequest.PersonId.html">PersonId</a>,
302 * Object>> object. All of the data values returned will be valid json.
304 * @param {opensocial.IdSpec} idSpec An IdSpec used to specify
305 * which people to fetch. See also <a href="opensocial.IdSpec.html">IdSpec</a>.
306 * @param {Array.<String> | String} keys The keys you want data for; this
307 * can be an array of key names, a single key name, or "*" to mean
309 * @param {Map.<opensocial.DataRequest.DataRequestFields, Object>}
310 * opt_params Additional
311 * <a href="opensocial.DataRequest.DataRequestFields.html">params</a>
312 * to pass to the request
313 * @return {Object} A request object
315 opensocial.DataRequest.prototype.newFetchPersonAppDataRequest = function(idSpec,
316 keys, opt_params) {};
320 * Creates an item to request an update of an app field for the given person.
321 * When processed, does not return any data.
323 * @param {String} id The ID of the person to update; only the
324 * special <code>VIEWER</code> ID is currently allowed.
325 * @param {String} key The name of the key. This may only contain alphanumeric
326 * (A-Za-z0-9) characters, underscore(_), dot(.) or dash(-).
327 * @param {Object} value The value, must be valid json
328 * @return {Object} A request object
330 opensocial.DataRequest.prototype.newUpdatePersonAppDataRequest = function(id,
335 * Deletes the given keys from the datastore for the given person.
336 * When processed, does not return any data.
338 * @param {String} id The ID of the person to update; only the
339 * special <code>VIEWER</code> ID is currently allowed.
340 * @param {Array.<String> | String} keys The keys you want to delete from
341 * the datastore; this can be an array of key names, a single key name,
342 * or "*" to mean "all keys"
343 * @return {Object} A request object
345 opensocial.DataRequest.prototype.newRemovePersonAppDataRequest = function(id,
350 * Creates an item to request an activity stream from the server.
353 * When processed, returns a Collection<Activity>.
356 * @param {opensocial.IdSpec} idSpec An IdSpec used to specify
357 * which people to fetch. See also <a href="opensocial.IdSpec.html">IdSpec</a>.
358 * @param {Map.<opensocial.DataRequest.ActivityRequestFields, Object>}
360 * Additional parameters
361 * to pass to the request; not currently used
362 * @return {Object} A request object
364 opensocial.DataRequest.prototype.newFetchActivitiesRequest = function(idSpec,