Side by Side Diff

Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Keyboard Shortcuts

File
u :up to issue
m :publish + mail comments
M :edit review message
j / k :jump to file after / before current file
J / K :jump to next file with a comment after / before current file
Side-by-side diff
i :toggle intra-line diffs
e :expand all comments
c :collapse all comments
s :toggle showing all comments
n / p :next / previous diff chunk or comment
N / P :next / previous comment
<Up> / <Down> :next / previous line
<Enter> :respond to / edit current comment
d :mark current comment as done
Issue
u :up to list of issues
m :publish + mail comments
j / k :jump to patch after / before current patch
o / <Enter> :open current patch in side-by-side view
i :open current patch in unified diff view
Issue List
j / k :jump to issue after / before current issue
o / <Enter> :open current issue
# : close issue
Comment/message editing
<Ctrl> + s or <Ctrl> + Enter :save comment
<Esc> :cancel edit
Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(179)
Issues Repositories Search
Open Issues | Closed Issues | All Issues | Sign in with your Google Account to create issues and add comments

Side by Side Diff: javascript-client-library-example/index.html

Issue 6810062: JavaScript Sample Application for Google Cloud Storage
Patch Set: Addressing comments from code review for Patch Set 1 Created 13 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
('i') | ('e') | ('c') | ('s')
OLDNEW
1 <!-- 1 <!--
2 Copyright (c) 2012 Google Inc. 2 Copyright (c) 2012 Google Inc.
3 3
4 Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 use this file except in compliance with the License. You may obtain a copy of 5 use this file except in compliance with the License. You may obtain a copy of
6 the License at 6 the License at
7 7
8 http://www.apache.org/licenses/LICENSE-2.0 8 http://www.apache.org/licenses/LICENSE-2.0
9 9
10 Unless required by applicable law or agreed to in writing, software 10 Unless required by applicable law or agreed to in writing, software
(...skipping 39 matching lines...) | | Loading...
50 * To enter one or more authentication scopes, refer to the documentation 50 * To enter one or more authentication scopes, refer to the documentation
51 * for the API. 51 * for the API.
52 */ 52 */
53 var scopes = 'https://www.googleapis.com/auth/devstorage.full_control'; 53 var scopes = 'https://www.googleapis.com/auth/devstorage.full_control';
54 54
55 /** 55 /**
56 * Constants for request parameters. Fill these values in with your custom 56 * Constants for request parameters. Fill these values in with your custom
57 * information. 57 * information.
58 */ 58 */
59 var API_VERSION = 'v1beta1'; 59 var API_VERSION = 'v1beta1';
60 var DEFAULT_PROJECT = projectId; 60 var PROJECT = projectId;
61 var DEFAULT_BUCKET = 'YOUR_DEFAULT_BUCKET_NAME'; 61
62 var DEFAULT_OBJECT = 'YOUR_DEFAULT_OBJECT_NAME'; 62 /**
63 var DEFAULT_GROUP = 'YOUR_DEFAULT_GROUP_NAME'; 63 * The name of the new bucket to create.
64 var DEFAULT_CONTENT_TYPE = 'YOUR_DEFAULT_CONTENT_TYPE'; 64 */
65 var DEFAULT_DATA = 'YOUR_DEFAULT_DATA'; 65 var BUCKET = 'code-sample-bucket';
66 var DEFAULT_ENTITY = 'YOUR_DEFAULT_ENTITY'; 66
67 var DEFAULT_ROLE = 'YOUR_DEFAULT_ROLE'; 67 /**
68 var DEFAULT_ROLE_OBJECT = 'YOUR_DEFAULT_ROLE_OBJECT'; 68 * The name of the new object to create.
69 */
70 var OBJECT = 'test.htm';
71
72 /**
73 * Get this value from the API console.
74 */
75 var GROUP = 'group-000000000000000000000000000000000000000000000000000000000 0000000';
76
77 /**
78 * Valid values are user-userId, user-email, group-groupId, group-email,
79 * allUsers, allAuthenticatedUsers
80 */
81 var ENTITY = 'allUsers';
82
83 /**
84 * Valid values are READER, OWNER
85 */
86 var ROLE = 'READER';
87
88 /**
89 * Valid values are READER, OWNER
90 */
91 var ROLE_OBJECT = 'READER';
69 92
70 /** 93 /**
71 * A list of example calls to the Google Cloud Storage JavaScript client 94 * A list of example calls to the Google Cloud Storage JavaScript client
72 * library, as well as associated explanations of each call. 95 * library, as well as associated explanations of each call.
73 */ 96 */
74 var listApiRequestExplanations = { 97 var listApiRequestExplanations = {
75 'listBuckets': 'This API call queries the Google Cloud Storage API ' + 98 'listBuckets': 'This API call queries the Google Cloud Storage API ' +
76 'for a list of buckets in your project, and returns the result as ' + 99 'for a list of buckets in your project, and returns the result as ' +
77 'a list of Google Cloud Storage buckets.', 100 'a list of Google Cloud Storage buckets.',
78 101
79 'listObjects': 'This API call queries the Google Cloud Storage API ' + 102 'listObjects': 'This API call queries the Google Cloud Storage API ' +
80 'for a list of objects in your bucket, and returns the result as ' + 103 'for a list of objects in your bucket, and returns the result as ' +
81 'a list of Google Cloud Storage objects.', 104 'a list of Google Cloud Storage objects.',
82 105
83 'listBucketsAccessControls': 'This API call queries the Google Cloud ' + 106 'listBucketsAccessControls': 'This API call queries the Google Cloud ' +
84 'Storage API for the list of access control lists on buckets in your ' + 107 'Storage API for the list of access control lists on buckets in your ' +
85 'project and returns the result as a list of Google Cloud Storage ' + 108 'project and returns the result as a list of Google Cloud Storage ' +
86 'Access Control Lists.', 109 'Access Control Lists.',
87 110
88 'listObjectsAccessControls': 'This API call queries the Google Cloud ' + 111 'listObjectsAccessControls': 'This API call queries the Google Cloud ' +
89 'Storage API for the list of access control lists on objects in your ' + 112 'Storage API for the list of access control lists on objects in your ' +
90 'bucket and returns the result as a list of Google Cloud Storage ' + 113 'bucket and returns the result as a list of Google Cloud Storage ' +
91 'Access Control Lists.', 114 'Access Control Lists.',
92 115
93 'getBucket': 'This API call queries the Google Cloud Storage API ' + 116 'getBucket': 'This API call queries the Google Cloud Storage API ' +
94 'for a bucket in your project, and returns the result as a ' + 117 'for a bucket in your project, and returns the result as a ' +
95 'Google Cloud Storage bucket.', 118 'Google Cloud Storage bucket.',
96 119
97 'getObject': 'This API call queries the Google Cloud Storage API ' +
98 'for an object in your project, and returns the result as a ' +
99 'Google Cloud Storage object.',
100
101 'getBucketAccessControls': 'This API call queries the Google Cloud ' + 120 'getBucketAccessControls': 'This API call queries the Google Cloud ' +
102 'Storage API for the access control list on a specific bucket ' + 121 'Storage API for the access control list on a specific bucket ' +
103 'and returns the result as a Google Cloud Storage Access Control List.', 122 'and returns the result as a Google Cloud Storage Access Control List.',
104 123
105 'getObjectAccessControls': 'This API call queries the Google Cloud ' + 124 'getObjectAccessControls': 'This API call queries the Google Cloud ' +
106 'Storage API for the access control list on a specific object ' + 125 'Storage API for the access control list on a specific object ' +
107 'and returns the result as a Google Cloud Storage Access Control List.', 126 'and returns the result as a Google Cloud Storage Access Control List.',
108 127
109 'insertBucket': 'This API call uses the Google Cloud Storage API ' + 128 'insertBucket': 'This API call uses the Google Cloud Storage API ' +
110 'to insert a bucket into your project.', 129 'to insert a bucket into your project.',
111 130
112 'insertObject': 'This API call uses the Google Cloud Storage API ' +
113 'to insert an object into your project.',
114
115 'insertBucketAccessControls': 'This API uses the Google Cloud ' + 131 'insertBucketAccessControls': 'This API uses the Google Cloud ' +
116 'Storage API to insert an access control list on a specific bucket ' + 132 'Storage API to insert an access control list on a specific bucket ' +
117 'and returns the result as a Google Cloud Storage Access Control List.', 133 'and returns the result as a Google Cloud Storage Access Control List.',
118 134
119 'insertObjectAccessControls': 'This API uses the Google Cloud ' + 135 'insertObjectAccessControls': 'This API uses the Google Cloud ' +
120 'Storage API to insert an access control list on a specific object ' + 136 'Storage API to insert an access control list on a specific object ' +
121 'and returns the result as a Google Cloud Storage Access Control List.', 137 'and returns the result as a Google Cloud Storage Access Control List.',
122 138
123 'deleteBucket': 'This API uses the Google Cloud Storage API to delete ' + 139 'deleteBucket': 'This API uses the Google Cloud Storage API to delete ' +
124 'an empty bucket and returns an empty response to indicate success.', 140 'an empty bucket and returns an empty response to indicate success.',
125 141
126 'deleteObject': 'This API uses the Google Cloud Storage API to delete ' + 142 'deleteObject': 'This API uses the Google Cloud Storage API to delete ' +
127 'an object and returns an empty response to indicate success.' 143 'an object and returns an empty response to indicate success.'
128 }; 144 };
129 145
130 /** 146 /**
131 * Removes the current API result entry in the main-content div, adds the
132 * results of the entry for your function.
133 * @param {string} apiRequestName The name of the example API request.
134 */
135 function updateApiResultEntry(apiRequestName) {
136 listChildren = document.getElementById('main-content')
137 .childNodes;
138 if (listChildren.length > 1) {
139 listChildren[1].parentNode.removeChild(listChildren[1]);
140 }
141 if (apiRequestName != 'null') {
142 window[apiRequestName].apply(this);
143 }
144 }
145
146 /**
147 * Determines which API request has been selected, and makes a call to add
148 * its result entry.
149 */
150 function runSelectedApiRequest() {
151 var curElement = document.getElementById('api-selection-options');
152 var apiRequestName = curElement.options[curElement.selectedIndex].value;
153 updateApiResultEntry(apiRequestName);
154 }
155
156 /**
157 * Binds event listeners to handle a newly selected API request.
158 */
159 function addSelectionSwitchingListeners() {
160 document.getElementById('api-selection-options')
161 .addEventListener('change',
162 runSelectedApiRequest, false);
163 }
164
165 /**
166 * Template for getting JavaScript sample code snippets.
167 * @param {string} method The name of the Google Cloud Storage request
168 * @param {string} params The parameters passed to method
169 */
170 function getCodeSnippet(method, params) {
171 var objConstruction = "// Declare your parameter object\n";
172 objConstruction += "var params = {};";
173 objConstruction += "\n\n";
174
175 var param = "// Initialize your parameters \n";
176 for (i in params) {
177 param += "params['" + i + "'] = ";
178 param += JSON.stringify(params[i], null, '\t');
179 param += ";";
180 param += "\n";
181 }
182 param += "\n";
183
184 var methodCall = "// Make a request to the Google Cloud Storage API \n";
185 methodCall += "var request = gapi.client." + method + "(params);";
186 return objConstruction + param + methodCall;
187 }
188
189 /**
190 * Executes your Google Cloud Storage request object and, subsequently,
191 * inserts the response into the page.
192 * @param {string} request A Google Cloud Storage request object issued
193 * from the Google Cloud Storage JavaScript client library.
194 * @param {string} apiRequestName The name of the example API request.
195 */
196 function executeRequest(request, apiRequestName) {
197 request.execute(function(resp) {
198 console.log(resp);
199 var apiRequestNode = document.createElement('div');
200 apiRequestNode.id = apiRequestName;
201
202 var apiRequestNodeHeader = document.createElement('h2');
203 apiRequestNodeHeader.innerHTML = apiRequestName;
204
205 var apiRequestExplanationNode = document.createElement('div');
206 apiRequestExplanationNode.id = apiRequestName + 'RequestExplanation';
207
208 var apiRequestExplanationNodeHeader = document.createElement('h3');
209 apiRequestExplanationNodeHeader.innerHTML = 'API Request Explanation';
210 apiRequestExplanationNode.appendChild(apiRequestExplanationNodeHeader);
211
212 var apiRequestExplanationEntry = document.createElement('p');
213 apiRequestExplanationEntry.innerHTML =·
214 listApiRequestExplanations[apiRequestName];
215 apiRequestExplanationNode.appendChild(apiRequestExplanationEntry);
216
217 apiRequestNode.appendChild(apiRequestNodeHeader);
218 apiRequestNode.appendChild(apiRequestExplanationNode);
219
220 var apiRequestCodeSnippetNode = document.createElement('div');
221 apiRequestCodeSnippetNode.id = apiRequestName + 'CodeSnippet';
222
223 var apiRequestCodeSnippetHeader = document.createElement('h3');
224 apiRequestCodeSnippetHeader.innerHTML = 'API Request Code Snippet';
225 apiRequestCodeSnippetNode.appendChild(apiRequestCodeSnippetHeader);
226
227 var apiRequestCodeSnippetEntry = document.createElement('pre');
228 apiRequestCodeSnippetEntry.innerHTML = getCodeSnippet(request.b.method,
229 request.b.rpcParams);
230
231 apiRequestCodeSnippetNode.appendChild(apiRequestCodeSnippetEntry);
232 apiRequestNode.appendChild(apiRequestCodeSnippetNode);
233
234 var apiResponseEntry = document.createElement('pre');
235 apiResponseEntry.innerHTML = JSON.stringify(resp.result, null, ' ');
236
237 var apiResponseNode = document.createElement('div');
238 apiResponseNode.id = apiRequestName + 'Response';
239
240 var apiResponseHeader = document.createElement('h3');
241 apiResponseHeader.innerHTML = 'API Response';
242 apiResponseNode.appendChild(apiResponseHeader);
243
244 var apiResponseEntry = document.createElement('pre');
245 apiResponseEntry.innerHTML = JSON.stringify(resp.result, null, ' ');
246
247 apiResponseNode.appendChild(apiResponseEntry);
248 apiRequestNode.appendChild(apiResponseNode);
249
250 var content = document.getElementById('main-content');
251 content.appendChild(apiRequestNode);
252 });
253 }
254
255 /**
256 * Google Cloud Storage API request to retrieve the list of buckets in 147 * Google Cloud Storage API request to retrieve the list of buckets in
257 * your Google Cloud Storage project. 148 * your Google Cloud Storage project.
258 */ 149 */
259 function listBuckets() { 150 function listBuckets() {
260 var request = gapi.client.storage.buckets.list({ 151 var request = gapi.client.storage.buckets.list({
261 'projectId': DEFAULT_PROJECT 152 'projectId': PROJECT
262 }); 153 });
263 executeRequest(request, 'listBuckets'); 154 executeRequest(request, 'listBuckets');
264 } 155 }
265 156
266 /** 157 /**
267 * Google Cloud Storage API request to retrieve the list of buckets in 158 * Google Cloud Storage API request to retrieve the list of objects in
268 * your Google Cloud Storage project. 159 * your Google Cloud Storage project.
269 */ 160 */
270 function listObjects() { 161 function listObjects() {
271 var request = gapi.client.storage.objects.list({ 162 var request = gapi.client.storage.objects.list({
272 'bucket': DEFAULT_BUCKET 163 'bucket': BUCKET
273 }); 164 });
274 executeRequest(request, 'listObjects'); 165 executeRequest(request, 'listObjects');
275 } 166 }
276 167
277 /** 168 /**
278 * Google Cloud Storage API request to retrieve the access control list on 169 * Google Cloud Storage API request to retrieve the access control list on
279 * a bucket in your Google Cloud Storage project. 170 * a bucket in your Google Cloud Storage project.
280 */ 171 */
281 function listBucketsAccessControls() { 172 function listBucketsAccessControls() {
282 var request = gapi.client.storage.bucketAccessControls.list({ 173 var request = gapi.client.storage.bucketAccessControls.list({
283 'bucket': DEFAULT_BUCKET 174 'bucket': BUCKET
284 }); 175 });
285 executeRequest(request, 'listBucketsAccessControls'); 176 executeRequest(request, 'listBucketsAccessControls');
286 } 177 }
287 178
288 /** 179 /**
289 * Google Cloud Storage API request to retrieve the access control list on 180 * Google Cloud Storage API request to retrieve the access control list on
290 * an object in your Google Cloud Storage project. 181 * an object in your Google Cloud Storage project.
291 */ 182 */
292 function listObjectsAccessControls() { 183 function listObjectsAccessControls() {
293 var request = gapi.client.storage.objectAccessControls.list({ 184 var request = gapi.client.storage.objectAccessControls.list({
294 'bucket': DEFAULT_BUCKET, 185 'bucket': BUCKET,
295 'object': DEFAULT_OBJECT 186 'object': OBJECT
296 }); 187 });
297 executeRequest(request, 'listObjectsAccessControls'); 188 executeRequest(request, 'listObjectsAccessControls');
298 } 189 }
299 190
300 /** 191 /**
301 * Google Cloud Storage API request to retrieve a bucket in 192 * Google Cloud Storage API request to retrieve a bucket in
302 * your Google Cloud Storage project. 193 * your Google Cloud Storage project.
303 */ 194 */
304 function getBucket() { 195 function getBucket() {
305 var request = gapi.client.storage.buckets.get({ 196 var request = gapi.client.storage.buckets.get({
306 'bucket': DEFAULT_BUCKET 197 'bucket': BUCKET
307 }); 198 });
308 executeRequest(request, 'getBucket'); 199 executeRequest(request, 'getBucket');
309 } 200 }
310 201
311 /** 202 /**
312 * Google Cloud Storage API request to retrieve an object in
313 * your Google Cloud Storage project.
314 */
315 function getObject() {
316 var request = gapi.client.storage.objects.get({
317 'bucket': DEFAULT_BUCKET,
318 'object': DEFAULT_OBJECT
319 });
320 executeRequest(request, 'getObject');
321 }
322
323 /**
324 * Google Cloud Storage API request to retrieve a bucket's Access Control 203 * Google Cloud Storage API request to retrieve a bucket's Access Control
325 * List in your Google Cloud Storage project. 204 * List in your Google Cloud Storage project.
326 */ 205 */
327 function getBucketAccessControls() { 206 function getBucketAccessControls() {
328 var request = gapi.client.storage.bucketAccessControls.get({ 207 var request = gapi.client.storage.bucketAccessControls.get({
329 'bucket': DEFAULT_BUCKET, 208 'bucket': BUCKET,
330 'entity': DEFAULT_GROUP 209 'entity': GROUP
331 }); 210 });
332 executeRequest(request, 'getBucketAccessControls'); 211 executeRequest(request, 'getBucketAccessControls');
333 } 212 }
334 213
335 /** 214 /**
336 * Google Cloud Storage API request to retrieve an object's Access Control 215 * Google Cloud Storage API request to retrieve an object's Access Control
337 * List in your Google Cloud Storage project. 216 * List in your Google Cloud Storage project.
338 */ 217 */
339 function getObjectAccessControls() { 218 function getObjectAccessControls() {
340 var request = gapi.client.storage.objectAccessControls.get({ 219 var request = gapi.client.storage.objectAccessControls.get({
341 'bucket': DEFAULT_BUCKET, 220 'bucket': BUCKET,
342 'object': DEFAULT_OBJECT, 221 'object': OBJECT,
343 'entity': DEFAULT_GROUP 222 'entity': GROUP
344 }); 223 });
345 executeRequest(request, 'getBucketAccessControls'); 224 executeRequest(request, 'getBucketAccessControls');
346 } 225 }
347 226
348 /** 227 /**
349 * Google Cloud Storage API request to insert a bucket into 228 * Google Cloud Storage API request to insert a bucket into
350 * your Google Cloud Storage project. 229 * your Google Cloud Storage project.
351 */ 230 */
352 function insertBucket() { 231 function insertBucket() {
353 resource = { 232 resource = {
354 'id': DEFAULT_BUCKET, 233 'id': BUCKET,
355 'projectId': DEFAULT_PROJECT 234 'projectId': PROJECT
356 }; 235 };
357 236
358 var request = gapi.client.storage.buckets.insert({ 237 var request = gapi.client.storage.buckets.insert({
359 'resource': resource 238 'resource': resource
360 }); 239 });
361 executeRequest(request, 'insertBucket'); 240 executeRequest(request, 'insertBucket');
362 } 241 }
363 242
364 /** 243 /**
365 * Google Cloud Storage API request to insert a bucket into
366 * your Google Cloud Storage project.
367 */
368 function insertObject() {
369 resource = {
370 "media": {
371 'contentType': DEFAULT_CONTENT_TYPE,
372 'data': DEFAULT_DATA
373 }
374 };
375
376 var request = gapi.client.storage.objects.insert({
377 'bucket': DEFAULT_BUCKET,
378 'name': DEFAULT_OBJECT,
379 'resource': resource
380 });
381 executeRequest(request, 'insertObject');
382 }
383
384 /**
385 * Google Cloud Storage API request to insert an Access Control List into 244 * Google Cloud Storage API request to insert an Access Control List into
386 * your Google Cloud Storage bucket. 245 * your Google Cloud Storage bucket.
387 */ 246 */
388 function insertBucketAccessControls() { 247 function insertBucketAccessControls() {
389 resource = { 248 resource = {
390 'entity': DEFAULT_ENTITY, 249 'entity': ENTITY,
391 'role': DEFAULT_ROLE 250 'role': ROLE
392 }; 251 };
393 252
394 var request = gapi.client.storage.bucketAccessControls.insert({ 253 var request = gapi.client.storage.bucketAccessControls.insert({
395 'bucket': DEFAULT_BUCKET, 254 'bucket': BUCKET,
396 'resource': resource 255 'resource': resource
397 }); 256 });
398 executeRequest(request, 'insertBucketAccessControls'); 257 executeRequest(request, 'insertBucketAccessControls');
399 } 258 }
400 259
401 /** 260 /**
402 * Google Cloud Storage API request to insert an Access Control List into 261 * Google Cloud Storage API request to insert an Access Control List into
403 * your Google Cloud Storage object. 262 * your Google Cloud Storage object.
404 */ 263 */
405 function insertObjectAccessControls() { 264 function insertObjectAccessControls() {
406 resource = { 265 resource = {
407 'entity': DEFAULT_ENTITY, 266 'entity': ENTITY,
408 'role': DEFAULT_ROLE_OBJECT 267 'role': ROLE_OBJECT
409 }; 268 };
410 269
411 var request = gapi.client.storage.objectAccessControls.insert({ 270 var request = gapi.client.storage.objectAccessControls.insert({
412 'bucket': DEFAULT_BUCKET, 271 'bucket': BUCKET,
413 'object': DEFAULT_OBJECT, 272 'object': OBJECT,
414 'resource': resource 273 'resource': resource
415 }); 274 });
416 executeRequest(request, 'insertObjectAccessControls'); 275 executeRequest(request, 'insertObjectAccessControls');
417 } 276 }
418 277
419 /** 278 /**
420 * Google Cloud Storage API request to delete a Google Cloud Storage bucket. 279 * Google Cloud Storage API request to delete a Google Cloud Storage bucket.
421 */ 280 */
422 function deleteBucket() { 281 function deleteBucket() {
423 var request = gapi.client.storage.buckets.delete({ 282 var request = gapi.client.storage.buckets.delete({
424 'bucket': DEFAULT_BUCKET 283 'bucket': BUCKET
425 }); 284 });
426 executeRequest(request, 'deleteBucket'); 285 executeRequest(request, 'deleteBucket');
427 } 286 }
428 287
429 /** 288 /**
430 * Google Cloud Storage API request to delete a Google Cloud Storage object. 289 * Google Cloud Storage API request to delete a Google Cloud Storage object.
431 */ 290 */
432 function deleteObject() { 291 function deleteObject() {
433 var request = gapi.client.storage.objects.delete({ 292 var request = gapi.client.storage.objects.delete({
434 'bucket': DEFAULT_BUCKET, 293 'bucket': BUCKET,
435 'object': DEFAULT_OBJECT 294 'object': OBJECT
436 }); 295 });
437 executeRequest(request, 'deleteObject'); 296 executeRequest(request, 'deleteObject');
438 } 297 }
439 298
440 /** 299 /**
300 * Removes the current API result entry in the main-content div, adds the
301 * results of the entry for your function.
302 * @param {string} apiRequestName The name of the example API request.
303 */
304 function updateApiResultEntry(apiRequestName) {
305 listChildren = document.getElementById('main-content')
306 .childNodes;
307 if (listChildren.length > 1) {
308 listChildren[1].parentNode.removeChild(listChildren[1]);
309 }
310 if (apiRequestName != 'null') {
311 window[apiRequestName].apply(this);
312 }
313 }
314
315 /**
316 * Determines which API request has been selected, and makes a call to add
317 * its result entry.
318 */
319 function runSelectedApiRequest() {
320 var curElement = document.getElementById('api-selection-options');
321 var apiRequestName = curElement.options[curElement.selectedIndex].value;
322 updateApiResultEntry(apiRequestName);
323 }
324
325 /**
326 * Binds event listeners to handle a newly selected API request.
327 */
328 function addSelectionSwitchingListeners() {
329 document.getElementById('api-selection-options')
330 .addEventListener('change',
331 runSelectedApiRequest, false);
332 }
333
334 /**
335 * Template for getting JavaScript sample code snippets.
336 * @param {string} method The name of the Google Cloud Storage request
337 * @param {string} params The parameters passed to method
338 */
339 function getCodeSnippet(method, params) {
340 var objConstruction = "// Declare your parameter object\n";
341 objConstruction += "var params = {};";
342 objConstruction += "\n\n";
343
344 var param = "// Initialize your parameters \n";
345 for (i in params) {
346 param += "params['" + i + "'] = ";
347 param += JSON.stringify(params[i], null, '\t');
348 param += ";";
349 param += "\n";
350 }
351 param += "\n";
352
353 var methodCall = "// Make a request to the Google Cloud Storage API \n";
354 methodCall += "var request = gapi.client." + method + "(params);";
355 return objConstruction + param + methodCall;
356 }
357
358 /**
359 * Executes your Google Cloud Storage request object and, subsequently,
360 * inserts the response into the page.
361 * @param {string} request A Google Cloud Storage request object issued
362 * from the Google Cloud Storage JavaScript client library.
363 * @param {string} apiRequestName The name of the example API request.
364 */
365 function executeRequest(request, apiRequestName) {
366 request.execute(function(resp) {
367 console.log(resp);
368 var apiRequestNode = document.createElement('div');
369 apiRequestNode.id = apiRequestName;
370
371 var apiRequestNodeHeader = document.createElement('h2');
372 apiRequestNodeHeader.innerHTML = apiRequestName;
373
374 var apiRequestExplanationNode = document.createElement('div');
375 apiRequestExplanationNode.id = apiRequestName + 'RequestExplanation';
376
377 var apiRequestExplanationNodeHeader = document.createElement('h3');
378 apiRequestExplanationNodeHeader.innerHTML = 'API Request Explanation';
379 apiRequestExplanationNode.appendChild(apiRequestExplanationNodeHeader);
380
381 var apiRequestExplanationEntry = document.createElement('p');
382 apiRequestExplanationEntry.innerHTML =·
383 listApiRequestExplanations[apiRequestName];
384 apiRequestExplanationNode.appendChild(apiRequestExplanationEntry);
385
386 apiRequestNode.appendChild(apiRequestNodeHeader);
387 apiRequestNode.appendChild(apiRequestExplanationNode);
388
389 var apiRequestCodeSnippetNode = document.createElement('div');
390 apiRequestCodeSnippetNode.id = apiRequestName + 'CodeSnippet';
391
392 var apiRequestCodeSnippetHeader = document.createElement('h3');
393 apiRequestCodeSnippetHeader.innerHTML = 'API Request Code Snippet';
394 apiRequestCodeSnippetNode.appendChild(apiRequestCodeSnippetHeader);
395
396 var apiRequestCodeSnippetEntry = document.createElement('pre');
397 apiRequestCodeSnippetEntry.innerHTML = getCodeSnippet(request.b.method,
398 request.b.rpcParams);
399
400 apiRequestCodeSnippetNode.appendChild(apiRequestCodeSnippetEntry);
401 apiRequestNode.appendChild(apiRequestCodeSnippetNode);
402
403 var apiResponseEntry = document.createElement('pre');
404 apiResponseEntry.innerHTML = JSON.stringify(resp.result, null, ' ');
405
406 var apiResponseNode = document.createElement('div');
407 apiResponseNode.id = apiRequestName + 'Response';
408
409 var apiResponseHeader = document.createElement('h3');
410 apiResponseHeader.innerHTML = 'API Response';
411 apiResponseNode.appendChild(apiResponseHeader);
412
413 var apiResponseEntry = document.createElement('pre');
414 apiResponseEntry.innerHTML = JSON.stringify(resp.result, null, ' ');
415
416 apiResponseNode.appendChild(apiResponseEntry);
417 apiRequestNode.appendChild(apiResponseNode);
418
419 var content = document.getElementById('main-content');
420 content.appendChild(apiRequestNode);
421 });
422 }
423
424 /**
441 * Set required API keys and check authentication status. 425 * Set required API keys and check authentication status.
442 */ 426 */
443 function handleClientLoad() { 427 function handleClientLoad() {
444 gapi.client.setApiKey(apiKey); 428 gapi.client.setApiKey(apiKey);
445 window.setTimeout(checkAuth, 1); 429 window.setTimeout(checkAuth, 1);
446 } 430 }
447 431
448 /** 432 /**
449 * Authorize Google Cloud Storage API. 433 * Authorize Google Cloud Storage API.
450 */ 434 */
(...skipping 67 matching lines...) | | Loading...
518 </option> 502 </option>
519 <option value="listBucketsAccessControls"> 503 <option value="listBucketsAccessControls">
520 List Buckets Access Control List 504 List Buckets Access Control List
521 </option> 505 </option>
522 <option value="listObjectsAccessControls"> 506 <option value="listObjectsAccessControls">
523 List Objects Access Control List 507 List Objects Access Control List
524 </option> 508 </option>
525 <option value="getBucket"> 509 <option value="getBucket">
526 Get Bucket 510 Get Bucket
527 </option> 511 </option>
528 <option value="getObject">
529 Get Object
530 </option>
531 <option value="getBucketAccessControls"> 512 <option value="getBucketAccessControls">
532 Get Bucket Access Controls 513 Get Bucket Access Controls
533 </option> 514 </option>
534 <option value="getObjectAccessControls"> 515 <option value="getObjectAccessControls">
535 Get Object Access Controls 516 Get Object Access Controls
536 </option> 517 </option>
537 <option value="insertBucket"> 518 <option value="insertBucket">
538 Insert Bucket 519 Insert Bucket
539 </option> 520 </option>
540 <option value="insertObject">
541 Insert Object
542 </option>
543 <option value="insertBucketAccessControls"> 521 <option value="insertBucketAccessControls">
544 Insert Bucket Access Controls 522 Insert Bucket Access Controls
545 </option> 523 </option>
546 <option value="insertObjectAccessControls"> 524 <option value="insertObjectAccessControls">
547 Insert Object Access Controls 525 Insert Object Access Controls
548 </option> 526 </option>
549 <option value="deleteBucket"> 527 <option value="deleteBucket">
550 Delete Bucket 528 Delete Bucket
551 </option> 529 </option>
552 <option value="deleteObject"> 530 <option value="deleteObject">
553 Delete Object 531 Delete Object
554 </option> 532 </option>
555 </select> 533 </select>
556 <div id="main-content"> 534 <div id="main-content">
557 </div> 535 </div>
558 </body> 536 </body>
559 </html> 537 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b

AltStyle によって変換されたページ (->オリジナル) /