|
49 | 49 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpMockSequence">HttpMockSequence</a> |
50 | 50 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequest">HttpRequest</a> |
51 | 51 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#HttpRequestMock">HttpRequestMock</a> |
| 52 | +</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaDownloadProgress">MediaDownloadProgress</a> |
| 53 | +</font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaIoBaseDownload">MediaIoBaseDownload</a> |
52 | 54 | </font></dt><dt><font face="helvetica, arial"><a href="apiclient.http.html#MediaUpload">MediaUpload</a> |
53 | 55 | </font></dt><dd> |
54 | 56 | <dl> |
|
69 | 71 | <font color="#000000" face="helvetica, arial"><a name="BatchHttpRequest">class <strong>BatchHttpRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
70 | 72 |
|
71 | 73 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
72 | | -<td colspan=2><tt>Batches multiple <a href="#HttpRequest">HttpRequest</a> objects into a single HTTP request.<br> </tt></td></tr> |
| 74 | +<td colspan=2><tt>Batches multiple <a href="#HttpRequest">HttpRequest</a> objects into a single HTTP request.<br> |
| 75 | + <br> |
| 76 | +Example:<br> |
| 77 | + from apiclient.http import <a href="#BatchHttpRequest">BatchHttpRequest</a><br> |
| 78 | + <br> |
| 79 | + def list_animals(request_id, response):<br> |
| 80 | + """Do something with the animals list response."""<br> |
| 81 | + pass<br> |
| 82 | + <br> |
| 83 | + def list_farmers(request_id, response):<br> |
| 84 | + """Do something with the farmers list response."""<br> |
| 85 | + pass<br> |
| 86 | + <br> |
| 87 | + service = build('farm', 'v2')<br> |
| 88 | + <br> |
| 89 | + batch = <a href="#BatchHttpRequest">BatchHttpRequest</a>()<br> |
| 90 | + <br> |
| 91 | + batch.<a href="#BatchHttpRequest-add">add</a>(service.animals().list(), list_animals)<br> |
| 92 | + batch.<a href="#BatchHttpRequest-add">add</a>(service.farmers().list(), list_farmers)<br> |
| 93 | + batch.<a href="#BatchHttpRequest-execute">execute</a>(http)<br> </tt></td></tr> |
73 | 94 | <tr><td> </td> |
74 | 95 | <td width="100%">Methods defined here:<br> |
75 | 96 | <dl><dt><a name="BatchHttpRequest-__init__"><strong>__init__</strong></a>(self, callback<font color="#909090">=None</font>, batch_uri<font color="#909090">=None</font>)</dt><dd><tt>Constructor for a <a href="#BatchHttpRequest">BatchHttpRequest</a>.<br> |
|
102 | 123 | None<br> |
103 | 124 | <br> |
104 | 125 | Raises:<br> |
105 | | - BatchError if a resumable request is added to a batch.<br> |
| 126 | + BatchError if a media request is added to a batch.<br> |
106 | 127 | KeyError is the request_id is not unique.</tt></dd></dl> |
107 | 128 |
|
108 | 129 | <dl><dt><a name="BatchHttpRequest-execute"><strong>execute</strong></a>(self, http<font color="#909090">=None</font>)</dt><dd><tt>Execute all the requests as a single batched HTTP request.<br> |
|
239 | 260 | <br> |
240 | 261 | Example:<br> |
241 | 262 | <br> |
242 | | - media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png',<br> |
| 263 | + media = <a href="#MediaFileUpload">MediaFileUpload</a>('cow.png', mimetype='image/png',<br> |
243 | 264 | chunksize=1000, resumable=True)<br> |
244 | | - request = service.objects().insert(<br> |
245 | | - bucket=buckets['items'][0]['id'],<br> |
246 | | - name='smiley.png',<br> |
| 265 | + request = farm.animals().insert(<br> |
| 266 | + id='cow',<br> |
| 267 | + name='cow.png',<br> |
247 | 268 | media_body=media)<br> |
248 | 269 | <br> |
249 | 270 | response = None<br> |
|
300 | 321 | Same behavior as <a href="#HttpRequest">HttpRequest</a>.<a href="#HttpRequestMock-execute">execute</a>(), but the response is<br> |
301 | 322 | mocked and not really from an HTTP request/response.</tt></dd></dl> |
302 | 323 |
|
| 324 | +<hr> |
| 325 | +Data descriptors defined here:<br> |
| 326 | +<dl><dt><strong>__dict__</strong></dt> |
| 327 | +<dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 328 | +</dl> |
| 329 | +<dl><dt><strong>__weakref__</strong></dt> |
| 330 | +<dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 331 | +</dl> |
| 332 | +</td></tr></table> <p> |
| 333 | +<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 334 | +<tr bgcolor="#ffc8d8"> |
| 335 | +<td colspan=3 valign=bottom> <br> |
| 336 | +<font color="#000000" face="helvetica, arial"><a name="MediaDownloadProgress">class <strong>MediaDownloadProgress</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 337 | + |
| 338 | +<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 339 | +<td colspan=2><tt>Status of a resumable download.<br> </tt></td></tr> |
| 340 | +<tr><td> </td> |
| 341 | +<td width="100%">Methods defined here:<br> |
| 342 | +<dl><dt><a name="MediaDownloadProgress-__init__"><strong>__init__</strong></a>(self, resumable_progress, total_size)</dt><dd><tt>Constructor.<br> |
| 343 | + <br> |
| 344 | +Args:<br> |
| 345 | + resumable_progress: int, bytes received so far.<br> |
| 346 | + total_size: int, total bytes in complete download.</tt></dd></dl> |
| 347 | + |
| 348 | +<dl><dt><a name="MediaDownloadProgress-progress"><strong>progress</strong></a>(self)</dt><dd><tt>Percent of download completed, as a float.<br> |
| 349 | + <br> |
| 350 | +Returns:<br> |
| 351 | + the percentage complete as a float, returning 0.0 if the total size of<br> |
| 352 | + the download is unknown.</tt></dd></dl> |
| 353 | + |
303 | 354 | <hr> |
304 | 355 | Data descriptors defined here:<br> |
305 | 356 | <dl><dt><strong>__dict__</strong></dt> |
|
321 | 372 | method. For example, if we had a service that allowed uploading images:<br> |
322 | 373 | <br> |
323 | 374 | <br> |
324 | | - media = <a href="#MediaFileUpload">MediaFileUpload</a>('smiley.png', mimetype='image/png',<br> |
| 375 | + media = <a href="#MediaFileUpload">MediaFileUpload</a>('cow.png', mimetype='image/png',<br> |
325 | 376 | chunksize=1024*1024, resumable=True)<br> |
326 | | - service.objects().insert(<br> |
327 | | - bucket=buckets['items'][0]['id'],<br> |
328 | | - name='smiley.png',<br> |
| 377 | + farm.animals()..insert(<br> |
| 378 | + id='cow',<br> |
| 379 | + name='cow.png',<br> |
329 | 380 | media_body=media).execute()<br> </tt></td></tr> |
330 | 381 | <tr><td> </td> |
331 | 382 | <td width="100%"><dl><dt>Method resolution order:</dt> |
|
376 | 427 | Returns:<br> |
377 | 428 | Size of the body, or None of the size is unknown.</tt></dd></dl> |
378 | 429 |
|
379 | | -<dl><dt><a name="MediaFileUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Creating a JSON representation of an instance of Credentials.<br> |
| 430 | +<dl><dt><a name="MediaFileUpload-to_json"><strong>to_json</strong></a>(self)</dt><dd><tt>Creating a JSON representation of an instance of <a href="#MediaFileUpload">MediaFileUpload</a>.<br> |
380 | 431 | <br> |
381 | 432 | Returns:<br> |
382 | 433 | string, a JSON representation of this instance, suitable to pass to<br> |
|
416 | 467 | <td colspan=2><tt><a href="#MediaUpload">MediaUpload</a> for a chunk of bytes.<br> |
417 | 468 | <br> |
418 | 469 | Construct a <a href="#MediaFileUpload">MediaFileUpload</a> and pass as the media_body parameter of the<br> |
419 | | -method. For example, if we had a service that allowed plain text:<br> </tt></td></tr> |
| 470 | +method.<br> </tt></td></tr> |
420 | 471 | <tr><td> </td> |
421 | 472 | <td width="100%"><dl><dt>Method resolution order:</dt> |
422 | 473 | <dd><a href="apiclient.http.html#MediaInMemoryUpload">MediaInMemoryUpload</a></dd> |
|
500 | 551 | <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
501 | 552 | <tr bgcolor="#ffc8d8"> |
502 | 553 | <td colspan=3 valign=bottom> <br> |
| 554 | +<font color="#000000" face="helvetica, arial"><a name="MediaIoBaseDownload">class <strong>MediaIoBaseDownload</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr> |
| 555 | + |
| 556 | +<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
| 557 | +<td colspan=2><tt>"Download media resources.<br> |
| 558 | + <br> |
| 559 | +Note that the Python file <a href="__builtin__.html#object">object</a> is compatible with io.Base and can be used<br> |
| 560 | +with this class also.<br> |
| 561 | + <br> |
| 562 | + <br> |
| 563 | +Example:<br> |
| 564 | + request = farms.animals().get_media(id='cow')<br> |
| 565 | + fh = io.FileIO('cow.png', mode='wb')<br> |
| 566 | + downloader = <a href="#MediaIoBaseDownload">MediaIoBaseDownload</a>(fh, request, chunksize=1024*1024)<br> |
| 567 | + <br> |
| 568 | + done = False<br> |
| 569 | + while done is False:<br> |
| 570 | + status, done = downloader.<a href="#MediaIoBaseDownload-next_chunk">next_chunk</a>()<br> |
| 571 | + if status:<br> |
| 572 | + print "Download %d%%." % int(status.progress() * 100)<br> |
| 573 | + print "Download Complete!"<br> </tt></td></tr> |
| 574 | +<tr><td> </td> |
| 575 | +<td width="100%">Methods defined here:<br> |
| 576 | +<dl><dt><a name="MediaIoBaseDownload-__init__"><strong>__init__</strong></a>(self, fh, request, chunksize<font color="#909090">=524288</font>)</dt><dd><tt>Constructor.<br> |
| 577 | + <br> |
| 578 | +Args:<br> |
| 579 | + fh: io.Base or file <a href="__builtin__.html#object">object</a>, The stream in which to write the downloaded<br> |
| 580 | + bytes.<br> |
| 581 | + request: apiclient.http.<a href="#HttpRequest">HttpRequest</a>, the media request to perform in<br> |
| 582 | + chunks.<br> |
| 583 | + chunksize: int, File will be downloaded in chunks of this many bytes.</tt></dd></dl> |
| 584 | + |
| 585 | +<dl><dt><a name="MediaIoBaseDownload-next_chunk"><strong>next_chunk</strong></a>(self)</dt><dd><tt>Get the next chunk of the download.<br> |
| 586 | + <br> |
| 587 | +Returns:<br> |
| 588 | + (status, done): (MediaDownloadStatus, boolean)<br> |
| 589 | + The value of 'done' will be True when the media has been fully<br> |
| 590 | + downloaded.<br> |
| 591 | + <br> |
| 592 | +Raises:<br> |
| 593 | + apiclient.errors.HttpError if the response was not a 2xx.<br> |
| 594 | + httplib2.Error if a transport error has occured.</tt></dd></dl> |
| 595 | + |
| 596 | +<hr> |
| 597 | +Data descriptors defined here:<br> |
| 598 | +<dl><dt><strong>__dict__</strong></dt> |
| 599 | +<dd><tt>dictionary for instance variables (if defined)</tt></dd> |
| 600 | +</dl> |
| 601 | +<dl><dt><strong>__weakref__</strong></dt> |
| 602 | +<dd><tt>list of weak references to the object (if defined)</tt></dd> |
| 603 | +</dl> |
| 604 | +</td></tr></table> <p> |
| 605 | +<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> |
| 606 | +<tr bgcolor="#ffc8d8"> |
| 607 | +<td colspan=3 valign=bottom> <br> |
503 | 608 | <font color="#000000" face="helvetica, arial"><a name="MediaIoBaseUpload">class <strong>MediaIoBaseUpload</strong></a>(<a href="apiclient.http.html#MediaUpload">MediaUpload</a>)</font></td></tr> |
504 | 609 |
|
505 | 610 | <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> |
|
511 | 616 | fh = io.BytesIO('...Some data to upload...')<br> |
512 | 617 | media = <a href="#MediaIoBaseUpload">MediaIoBaseUpload</a>(fh, mimetype='image/png',<br> |
513 | 618 | chunksize=1024*1024, resumable=True)<br> |
514 | | - service.objects().insert(<br> |
515 | | - bucket='a_bucket_id',<br> |
516 | | - name='smiley.png',<br> |
| 619 | + farm.animals().insert(<br> |
| 620 | + id='cow',<br> |
| 621 | + name='cow.png',<br> |
517 | 622 | media_body=media).execute()<br> </tt></td></tr> |
518 | 623 | <tr><td> </td> |
519 | 624 | <td width="100%"><dl><dt>Method resolution order:</dt> |
|
0 commit comments