jomz-google-api-client 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/CHANGELOG.md +144 -0
  2. data/CONTRIBUTING.md +32 -0
  3. data/Gemfile +41 -0
  4. data/LICENSE +202 -0
  5. data/README.md +192 -0
  6. data/Rakefile +46 -0
  7. data/lib/cacerts.pem +2183 -0
  8. data/lib/compat/multi_json.rb +16 -0
  9. data/lib/google/api_client.rb +672 -0
  10. data/lib/google/api_client/auth/compute_service_account.rb +28 -0
  11. data/lib/google/api_client/auth/file_storage.rb +87 -0
  12. data/lib/google/api_client/auth/installed_app.rb +122 -0
  13. data/lib/google/api_client/auth/jwt_asserter.rb +126 -0
  14. data/lib/google/api_client/auth/key_utils.rb +93 -0
  15. data/lib/google/api_client/auth/pkcs12.rb +41 -0
  16. data/lib/google/api_client/batch.rb +323 -0
  17. data/lib/google/api_client/client_secrets.rb +176 -0
  18. data/lib/google/api_client/discovery.rb +19 -0
  19. data/lib/google/api_client/discovery/api.rb +300 -0
  20. data/lib/google/api_client/discovery/media.rb +77 -0
  21. data/lib/google/api_client/discovery/method.rb +363 -0
  22. data/lib/google/api_client/discovery/resource.rb +156 -0
  23. data/lib/google/api_client/discovery/schema.rb +121 -0
  24. data/lib/google/api_client/environment.rb +42 -0
  25. data/lib/google/api_client/errors.rb +60 -0
  26. data/lib/google/api_client/gzip.rb +28 -0
  27. data/lib/google/api_client/logging.rb +32 -0
  28. data/lib/google/api_client/media.rb +259 -0
  29. data/lib/google/api_client/railtie.rb +16 -0
  30. data/lib/google/api_client/reference.rb +27 -0
  31. data/lib/google/api_client/request.rb +351 -0
  32. data/lib/google/api_client/result.rb +253 -0
  33. data/lib/google/api_client/service.rb +233 -0
  34. data/lib/google/api_client/service/batch.rb +103 -0
  35. data/lib/google/api_client/service/request.rb +144 -0
  36. data/lib/google/api_client/service/resource.rb +40 -0
  37. data/lib/google/api_client/service/result.rb +162 -0
  38. data/lib/google/api_client/service/simple_file_store.rb +151 -0
  39. data/lib/google/api_client/service/stub_generator.rb +59 -0
  40. data/lib/google/api_client/service_account.rb +18 -0
  41. data/lib/google/api_client/version.rb +31 -0
  42. data/lib/google/inflection.rb +28 -0
  43. data/spec/fixtures/files/privatekey.p12 +0 -0
  44. data/spec/fixtures/files/sample.txt +33 -0
  45. data/spec/fixtures/files/secret.pem +19 -0
  46. data/spec/google/api_client/batch_spec.rb +249 -0
  47. data/spec/google/api_client/discovery_spec.rb +652 -0
  48. data/spec/google/api_client/gzip_spec.rb +86 -0
  49. data/spec/google/api_client/media_spec.rb +179 -0
  50. data/spec/google/api_client/request_spec.rb +30 -0
  51. data/spec/google/api_client/result_spec.rb +203 -0
  52. data/spec/google/api_client/service_account_spec.rb +164 -0
  53. data/spec/google/api_client/service_spec.rb +586 -0
  54. data/spec/google/api_client/simple_file_store_spec.rb +137 -0
  55. data/spec/google/api_client_spec.rb +253 -0
  56. data/spec/spec_helper.rb +56 -0
  57. data/tasks/gem.rake +97 -0
  58. data/tasks/git.rake +45 -0
  59. data/tasks/metrics.rake +22 -0
  60. data/tasks/spec.rake +57 -0
  61. data/tasks/wiki.rake +82 -0
  62. data/tasks/yard.rake +29 -0
  63. metadata +309 -0
@@ -0,0 +1,144 @@
1
+ # jomz-
2
+
3
+ * Modified lib/compat/multi_json.rb to not use MultiJson.method(:load).owner as that does not exist in ruby 1.8.6
4
+
5
+ # 0.7.1
6
+
7
+ * ?
8
+
9
+ # 0.7.0
10
+ * Remove CLI
11
+ * SUpport for automatic retires & backoff. Off by default, enable by setting `retries` on `APIClient`
12
+ * Experimental new interface (see `Google::APIClient::Service`)
13
+ * Fix warnings when using Faraday separately
14
+ * Support Google Compute Engine service accounts
15
+ * Enable gzip compression for responses
16
+ * Upgrade to Faraday 0.9.0. Resolves multiple issues with query parameter encodings.
17
+ * Use bundled root certificates for verifying SSL certificates
18
+ * Rewind media when retrying uploads
19
+
20
+ # 0.6.4
21
+ * Pin signet version to 0.4.x
22
+
23
+ # 0.6.3
24
+
25
+ * Update autoparse to 0.3.3 to fix cases where results aren't correctly parsed.
26
+ * Fix railtie loading for compatibility with rails < 3.0
27
+ * Fix refresh of access token when passing credentials as parameter to execute
28
+ * Fix URI processing in batch requests to allow query parameters
29
+
30
+ # 0.6.2
31
+
32
+ * Update signet to 0.4.6 to support server side continuation of postmessage
33
+ auth flows.
34
+
35
+ # 0.6.1
36
+
37
+ * Fix impersonation with service accounts
38
+
39
+ # 0.6
40
+
41
+ * Apps strongly encouraged to set :application_name & :application_version when
42
+ initializing a client
43
+ * JWT/service accounts moved to signet
44
+ * Added helper class for installed app OAuth flows, updated samples & CLI
45
+ * Initial logging support for client
46
+ * Fix PKCS12 loading on windows
47
+ * Allow disabling auto-refresh of OAuth 2 access tokens
48
+ * Compatibility with MultiJson >= 1.0.0 & Rails 3.2.8
49
+ * Fix for body serialization when body doesn't respond to to_json
50
+ * Remove OAuth 1.0 logins from CLI
51
+
52
+
53
+ # 0.5.0
54
+
55
+ * Beta candidate, potential incompatible changes with how requests are processed.
56
+ * All requests should be made using execute() or execute!()
57
+ * :api_method in request can no longer be a string
58
+ * Deprecated ResumableUpload.send_* methods.
59
+ * Reduce memory utilization when uploading large files
60
+ * Automatic refresh of OAuth 2 credentials & retry of request when 401 errors
61
+ are returned
62
+ * Simplify internal request processing.
63
+
64
+ # 0.4.7
65
+
66
+ * Added the ability to convert client secrets to an authorization object
67
+
68
+ # 0.4.6
69
+
70
+ * Backwards compatibility for MultiJson
71
+
72
+ # 0.4.5
73
+
74
+ * Updated Launchy dependency
75
+ * Updated Faraday dependency
76
+ * Updated Addressable dependency
77
+ * Updated Autoparse dependency
78
+ * Removed Sinatra development dependency
79
+
80
+ # 0.4.4
81
+
82
+ * Added batch execution
83
+ * Added service accounts
84
+ * Can now supply authorization on a per-request basis.
85
+
86
+ # 0.4.3
87
+
88
+ * Added media upload capabilities
89
+ * Support serializing OAuth credentials to client_secrets.json
90
+ * Fixed OS name/version string on JRuby
91
+
92
+ # 0.4.2
93
+
94
+ * Fixed incompatibility with Ruby 1.8.7
95
+
96
+ # 0.4.1
97
+
98
+ * Fixed ancestor checking issue when assigning Autoparse identifiers
99
+ * Renamed discovery methods to avoid collisions with some APIs
100
+ * Updated autoparse dependency to avoid JSON bug
101
+
102
+ # 0.4.0
103
+
104
+ * Replaced httpadapter gem dependency with faraday
105
+ * Replaced json gem dependency with multi_json
106
+ * Fixed /dev/null issues on Windows
107
+ * Repeated parameters now work
108
+
109
+ # 0.3.0
110
+
111
+ * Updated to use v1 of the discovery API
112
+ * Updated to use httpadapter 1.0.0
113
+ * Added OAuth 2 support to the command line tool
114
+ * Renamed some switches in the command line tool
115
+ * Added additional configuration capabilities
116
+ * Fixed a few deprecation warnings from dependencies
117
+ * Added gemspec to source control
118
+
119
+ # 0.2.0
120
+
121
+ * Updated to use v1 of the discovery API
122
+ * Updated to use httpadapter 1.0.0
123
+ * Added OAuth 2 support to the command line tool
124
+ * Renamed some switches in the command line tool
125
+ * Added additional configuration capabilities
126
+
127
+ # 0.1.3
128
+
129
+ * Added support for manual overrides of the discovery URI
130
+ * Added support for manual overrides of the API base
131
+ * Added support for xoauth_requestor_id
132
+
133
+ # 0.1.2
134
+
135
+ * Added support for two-legged OAuth
136
+ * Moved some development dependencies into runtime
137
+
138
+ # 0.1.1
139
+
140
+ * Substantial improvements to the command line interface
141
+
142
+ # 0.1.0
143
+
144
+ * Initial release
@@ -0,0 +1,32 @@
1
+ # How to become a contributor and submit your own code
2
+
3
+ ## Contributor License Agreements
4
+
5
+ We'd love to accept your sample apps and patches! Before we can take them, we
6
+ have to jump a couple of legal hurdles.
7
+
8
+ Please fill out either the individual or corporate Contributor License Agreement
9
+ (CLA).
10
+
11
+ * If you are an individual writing original source code and you're sure you
12
+ own the intellectual property, then you'll need to sign an [individual CLA]
13
+ (http://code.google.com/legal/individual-cla-v1.0.html).
14
+ * If you work for a company that wants to allow you to contribute your work,
15
+ then you'll need to sign a [corporate CLA]
16
+ (http://code.google.com/legal/corporate-cla-v1.0.html).
17
+
18
+ Follow either of the two links above to access the appropriate CLA and
19
+ instructions for how to sign and return it. Once we receive it, we'll be able to
20
+ accept your pull requests.
21
+
22
+ ## Contributing A Patch
23
+
24
+ 1. Submit an issue describing your proposed change to the repo in question.
25
+ 1. The repo owner will respond to your issue promptly.
26
+ 1. If your proposed change is accepted, and you haven't already done so, sign a
27
+ Contributor License Agreement (see details above).
28
+ 1. Fork the desired repo, develop and test your code changes.
29
+ 1. Ensure that your code is clear and comprehensible.
30
+ 1. Ensure that your code has an appropriate set of unit tests which all pass.
31
+ 1. Submit a pull request.
32
+
data/Gemfile ADDED
@@ -0,0 +1,41 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'signet', '>= 0.5.0'
6
+ gem 'addressable', '>= 2.3.2'
7
+ gem 'uuidtools', '>= 2.1.0'
8
+ gem 'autoparse', '>= 0.3.3'
9
+ gem 'faraday', '>= 0.9.0'
10
+ gem 'multi_json', '>= 1.0.0'
11
+ gem 'extlib', '>= 0.9.15'
12
+ gem 'jwt', '~> 0.1.5'
13
+ gem 'retriable', '>= 1.4'
14
+ gem 'jruby-openssl', :platforms => :jruby
15
+
16
+ group :development do
17
+ gem 'launchy', '>= 2.1.1'
18
+ gem 'yard'
19
+ gem 'kramdown'
20
+ end
21
+
22
+
23
+ platforms :rbx do
24
+ gem 'rubysl', '~> 2.0'
25
+ gem 'psych'
26
+ end
27
+
28
+
29
+ group :examples do
30
+ gem 'sinatra'
31
+ end
32
+
33
+ group :test, :development do
34
+ gem 'json', '~> 1.7.7'
35
+ gem 'rake', '>= 0.9.0'
36
+ gem 'rspec', '>= 2.11.0'
37
+ gem 'rcov', '>= 0.9.9', :platform => :mri_18
38
+ end
39
+
40
+
41
+ gem 'idn', :platform => :mri_18
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,192 @@
1
+ # Google API Client
2
+
3
+ <dl>
4
+ <dt>Homepage</dt><dd><a href="http://www.github.com/google/google-api-ruby-client">http://www.github.com/google/google-api-ruby-client</a></dd>
5
+ <dt>Authors</dt><dd>Bob Aman, <a href="mailto:sbazyl@google.com">Steven Bazyl</a></dd>
6
+ <dt>Copyright</dt><dd>Copyright © 2011 Google, Inc.</dd>
7
+ <dt>License</dt><dd>Apache 2.0</dd>
8
+ </dl>
9
+
10
+ [![Build Status](https://secure.travis-ci.org/google/google-api-ruby-client.png)](http://travis-ci.org/google/google-api-ruby-client)
11
+ [![Dependency Status](https://gemnasium.com/google/google-api-ruby-client.png)](https://gemnasium.com/google/google-api-ruby-client)
12
+
13
+ ## Description
14
+
15
+ The Google API Ruby Client makes it trivial to discover and access supported
16
+ APIs.
17
+
18
+ ## Install
19
+
20
+ Be sure `https://rubygems.org/` is in your gem sources.
21
+
22
+ For normal client usage, this is sufficient:
23
+
24
+ ```bash
25
+ $ gem install google-api-client
26
+ ```
27
+
28
+ ## Example Usage
29
+
30
+ ```ruby
31
+ require 'google/api_client'
32
+ require 'google/api_client/client_secrets'
33
+ require 'google/api_client/auth/installed_app'
34
+
35
+ # Initialize the client.
36
+ client = Google::APIClient.new(
37
+ :application_name => 'Example Ruby application',
38
+ :application_version => '1.0.0'
39
+ )
40
+
41
+ # Initialize Google+ API. Note this will make a request to the
42
+ # discovery service every time, so be sure to use serialization
43
+ # in your production code. Check the samples for more details.
44
+ plus = client.discovered_api('plus')
45
+
46
+ # Load client secrets from your client_secrets.json.
47
+ client_secrets = Google::APIClient::ClientSecrets.load
48
+
49
+ # Run installed application flow. Check the samples for a more
50
+ # complete example that saves the credentials between runs.
51
+ flow = Google::APIClient::InstalledAppFlow.new(
52
+ :client_id => client_secrets.client_id,
53
+ :client_secret => client_secrets.client_secret,
54
+ :scope => ['https://www.googleapis.com/auth/plus.me']
55
+ )
56
+ client.authorization = flow.authorize
57
+
58
+ # Make an API call.
59
+ result = client.execute(
60
+ :api_method => plus.activities.list,
61
+ :parameters => {'collection' => 'public', 'userId' => 'me'}
62
+ )
63
+
64
+ puts result.data
65
+ ```
66
+
67
+ ## API Features
68
+
69
+ ### API Discovery
70
+
71
+ To take full advantage of the client, load API definitions prior to use. To load an API:
72
+
73
+ ```ruby
74
+ urlshortener = client.discovered_api('urlshortener')
75
+ ```
76
+
77
+ Specific versions of the API can be loaded as well:
78
+
79
+ ```ruby
80
+ drive = client.discovered_api('drive', 'v2')
81
+ ```
82
+
83
+ Locally cached discovery documents may be used as well. To load an API from a local file:
84
+
85
+ ```ruby
86
+ doc = File.read('my-api.json')
87
+ my_api = client.register_discovery_document('myapi', 'v1', doc)
88
+ ```
89
+
90
+ ### Authorization
91
+
92
+ Most interactions with Google APIs require users to authorize applications via OAuth 2.0. The client library uses [Signet](https://github.com/google/signet) to handle most aspects of authorization. For additional details about Google's OAuth support, see [Google Developers](https://developers.google.com/accounts/docs/OAuth2).
93
+
94
+ Credentials can be managed at the connection level, as shown, or supplied on a per-request basis when calling `execute`.
95
+
96
+ For server-to-server interactions, like those between a web application and Google Cloud Storage, Prediction, or BigQuery APIs, use service accounts.
97
+
98
+ ```ruby
99
+ key = Google::APIClient::KeyUtils.load_from_pkcs12('client.p12', 'notasecret')
100
+ client.authorization = Signet::OAuth2::Client.new(
101
+ :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
102
+ :audience => 'https://accounts.google.com/o/oauth2/token',
103
+ :scope => 'https://www.googleapis.com/auth/prediction',
104
+ :issuer => '123456-abcdef@developer.gserviceaccount.com',
105
+ :signing_key => key)
106
+ client.authorization.fetch_access_token!
107
+ client.execute(...)
108
+ ```
109
+
110
+ Service accounts are also used for delegation in Google Apps domains. The target user for impersonation is specified by setting the `:person` parameter to the user's email address
111
+ in the credentials. Detailed instructions on how to enable delegation for your domain can be found at [developers.google.com](https://developers.google.com/drive/delegation).
112
+
113
+ ### Automatic Retries & Backoff
114
+
115
+ The API client can automatically retry requests for recoverable errors. To enable retries, set the `client.retries` property to
116
+ the number of additional attempts. To avoid flooding servers, retries invovle a 1 second delay that increases on each subsequent retry.
117
+
118
+ The default value for retries is 0, but will be enabled by default in future releases.
119
+
120
+ ### Batching Requests
121
+
122
+ Some Google APIs support batching requests into a single HTTP request. Use `Google::APIClient::BatchRequest`
123
+ to bundle multiple requests together.
124
+
125
+ Example:
126
+
127
+ ```ruby
128
+ client = Google::APIClient.new
129
+ urlshortener = client.discovered_api('urlshortner')
130
+
131
+ batch = Google::APIClient::BatchRequest.new do |result|
132
+ puts result.data
133
+ end
134
+
135
+ batch.add(:api_method => urlshortener.url.insert,
136
+ :body_object => { 'longUrl' => 'http://example.com/foo' })
137
+ batch.add(:api_method => urlshortener.url.insert,
138
+ :body_object => { 'longUrl' => 'http://example.com/bar' })
139
+ client.execute(batch)
140
+ ```
141
+
142
+ Blocks for handling responses can be specified either at the batch level or when adding an individual API call. For example:
143
+
144
+ ```ruby
145
+ batch.add(:api_method=>urlshortener.url.insert, :body_object => { 'longUrl' => 'http://example.com/bar' }) do |result|
146
+ puts result.data
147
+ end
148
+ ```
149
+
150
+ ### Media Upload
151
+
152
+ For APIs that support file uploads, use `Google::APIClient::UploadIO` to load the stream. Both multipart and resumable
153
+ uploads can be used. For example, to upload a file to Google Drive using multipart
154
+
155
+ ```ruby
156
+ drive = client.discovered_api('drive', 'v2')
157
+
158
+ media = Google::APIClient::UploadIO.new('mymovie.m4v', 'video/mp4')
159
+ metadata = {
160
+ 'title' => 'My movie',
161
+ 'description' => 'The best home movie ever made'
162
+ }
163
+ client.execute(:api_method => drive.files.insert,
164
+ :parameters => { 'uploadType' => 'multipart' },
165
+ :body_object => metadata,
166
+ :media => media )
167
+ ```
168
+
169
+ To use resumable uploads, change the `uploadType` parameter to `resumable`. To check the status of the upload
170
+ and continue if necessary, check `result.resumable_upload`.
171
+
172
+ ```ruby
173
+ client.execute(:api_method => drive.files.insert,
174
+ :parameters => { 'uploadType' => 'resumable' },
175
+ :body_object => metadata,
176
+ :media => media )
177
+ upload = result.resumable_upload
178
+
179
+ # Resume if needed
180
+ if upload.resumable?
181
+ client.execute(upload)
182
+ end
183
+ ```
184
+
185
+ ## Samples
186
+
187
+ See the full list of [samples on Github](https://github.com/google/google-api-ruby-client-samples).
188
+
189
+
190
+ ## Support
191
+
192
+ Please [report bugs at the project on Github](https://github.com/google/google-api-ruby-client/issues). Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-api-ruby-client) about the client or APIs on [StackOverflow](http://stackoverflow.com).