google-api-client 0.52.0 → 0.53.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -14
  3. data/CHANGELOG.md +6 -0
  4. data/OVERVIEW.md +36 -27
  5. data/generated/google/apis/accesscontextmanager_v1.rb +1 -1
  6. data/generated/google/apis/accesscontextmanager_v1/classes.rb +326 -0
  7. data/generated/google/apis/accesscontextmanager_v1/representations.rb +139 -0
  8. data/generated/google/apis/admin_directory_v1.rb +1 -1
  9. data/generated/google/apis/admin_directory_v1/service.rb +2 -2
  10. data/generated/google/apis/analyticsadmin_v1alpha.rb +2 -2
  11. data/generated/google/apis/analyticsadmin_v1alpha/classes.rb +8 -0
  12. data/generated/google/apis/analyticsadmin_v1alpha/representations.rb +1 -0
  13. data/generated/google/apis/analyticsadmin_v1alpha/service.rb +12 -1
  14. data/{lib/google/apis/core/logging.rb → generated/google/apis/apigateway_v1.rb} +14 -10
  15. data/generated/google/apis/apigateway_v1/classes.rb +1116 -0
  16. data/generated/google/apis/apigateway_v1/representations.rb +442 -0
  17. data/generated/google/apis/apigateway_v1/service.rb +1172 -0
  18. data/generated/google/apis/apigateway_v1beta.rb +1 -1
  19. data/generated/google/apis/apigateway_v1beta/classes.rb +19 -8
  20. data/generated/google/apis/apigateway_v1beta/representations.rb +1 -0
  21. data/generated/google/apis/apigee_v1.rb +1 -1
  22. data/generated/google/apis/apigee_v1/classes.rb +24 -22
  23. data/generated/google/apis/apigee_v1/service.rb +50 -48
  24. data/generated/google/apis/artifactregistry_v1.rb +38 -0
  25. data/generated/google/apis/artifactregistry_v1/classes.rb +242 -0
  26. data/generated/google/apis/artifactregistry_v1/representations.rb +116 -0
  27. data/generated/google/apis/artifactregistry_v1/service.rb +210 -0
  28. data/generated/google/apis/artifactregistry_v1beta1.rb +1 -1
  29. data/generated/google/apis/artifactregistry_v1beta1/classes.rb +0 -120
  30. data/generated/google/apis/artifactregistry_v1beta1/representations.rb +0 -62
  31. data/generated/google/apis/artifactregistry_v1beta2.rb +1 -1
  32. data/generated/google/apis/artifactregistry_v1beta2/classes.rb +0 -120
  33. data/generated/google/apis/artifactregistry_v1beta2/representations.rb +0 -62
  34. data/generated/google/apis/chat_v1.rb +1 -1
  35. data/generated/google/apis/chat_v1/service.rb +132 -0
  36. data/generated/google/apis/cloudasset_v1.rb +1 -1
  37. data/generated/google/apis/cloudasset_v1/classes.rb +326 -0
  38. data/generated/google/apis/cloudasset_v1/representations.rb +139 -0
  39. data/generated/google/apis/cloudasset_v1beta1.rb +1 -1
  40. data/generated/google/apis/cloudasset_v1beta1/classes.rb +326 -0
  41. data/generated/google/apis/cloudasset_v1beta1/representations.rb +139 -0
  42. data/generated/google/apis/cloudasset_v1p5beta1.rb +1 -1
  43. data/generated/google/apis/cloudasset_v1p5beta1/classes.rb +326 -0
  44. data/generated/google/apis/cloudasset_v1p5beta1/representations.rb +139 -0
  45. data/generated/google/apis/cloudbuild_v1.rb +1 -1
  46. data/generated/google/apis/cloudbuild_v1/classes.rb +3 -3
  47. data/generated/google/apis/cloudbuild_v1alpha1.rb +1 -1
  48. data/generated/google/apis/cloudbuild_v1alpha1/classes.rb +3 -3
  49. data/generated/google/apis/cloudbuild_v1alpha2.rb +1 -1
  50. data/generated/google/apis/cloudbuild_v1alpha2/classes.rb +3 -3
  51. data/generated/google/apis/cloudidentity_v1beta1.rb +1 -1
  52. data/generated/google/apis/cloudidentity_v1beta1/classes.rb +1 -1
  53. data/generated/google/apis/cloudresourcemanager_v1.rb +1 -1
  54. data/generated/google/apis/cloudresourcemanager_v1/classes.rb +0 -26
  55. data/generated/google/apis/cloudresourcemanager_v1/representations.rb +0 -24
  56. data/generated/google/apis/cloudresourcemanager_v1beta1.rb +1 -1
  57. data/generated/google/apis/cloudresourcemanager_v1beta1/classes.rb +0 -26
  58. data/generated/google/apis/cloudresourcemanager_v1beta1/representations.rb +0 -24
  59. data/generated/google/apis/cloudresourcemanager_v2.rb +1 -1
  60. data/generated/google/apis/cloudresourcemanager_v2/classes.rb +0 -26
  61. data/generated/google/apis/cloudresourcemanager_v2/representations.rb +0 -24
  62. data/generated/google/apis/cloudresourcemanager_v2beta1.rb +1 -1
  63. data/generated/google/apis/cloudresourcemanager_v2beta1/classes.rb +0 -26
  64. data/generated/google/apis/cloudresourcemanager_v2beta1/representations.rb +0 -24
  65. data/generated/google/apis/container_v1.rb +1 -1
  66. data/generated/google/apis/container_v1/classes.rb +7 -7
  67. data/generated/google/apis/container_v1beta1.rb +1 -1
  68. data/generated/google/apis/container_v1beta1/classes.rb +7 -7
  69. data/generated/google/apis/content_v2_1.rb +1 -1
  70. data/generated/google/apis/content_v2_1/classes.rb +434 -0
  71. data/generated/google/apis/content_v2_1/representations.rb +187 -0
  72. data/generated/google/apis/content_v2_1/service.rb +116 -0
  73. data/generated/google/apis/datacatalog_v1beta1.rb +1 -1
  74. data/generated/google/apis/datacatalog_v1beta1/classes.rb +6 -0
  75. data/generated/google/apis/datacatalog_v1beta1/representations.rb +1 -0
  76. data/generated/google/apis/dataflow_v1b3.rb +1 -1
  77. data/generated/google/apis/datalabeling_v1beta1.rb +1 -1
  78. data/generated/google/apis/dataproc_v1.rb +1 -1
  79. data/generated/google/apis/dataproc_v1/classes.rb +29 -1
  80. data/generated/google/apis/dataproc_v1/representations.rb +14 -0
  81. data/generated/google/apis/dataproc_v1/service.rb +42 -0
  82. data/generated/google/apis/dataproc_v1beta2.rb +1 -1
  83. data/generated/google/apis/dataproc_v1beta2/classes.rb +29 -1
  84. data/generated/google/apis/dataproc_v1beta2/representations.rb +14 -0
  85. data/generated/google/apis/dataproc_v1beta2/service.rb +42 -0
  86. data/generated/google/apis/dialogflow_v2.rb +1 -1
  87. data/generated/google/apis/dialogflow_v2/classes.rb +4041 -678
  88. data/generated/google/apis/dialogflow_v2/representations.rb +1851 -298
  89. data/generated/google/apis/dialogflow_v2beta1.rb +1 -1
  90. data/generated/google/apis/dialogflow_v2beta1/classes.rb +4047 -684
  91. data/generated/google/apis/dialogflow_v2beta1/representations.rb +1862 -309
  92. data/generated/google/apis/dialogflow_v3.rb +1 -1
  93. data/generated/google/apis/dialogflow_v3/classes.rb +3120 -311
  94. data/generated/google/apis/dialogflow_v3/representations.rb +2002 -617
  95. data/generated/google/apis/dialogflow_v3/service.rb +408 -0
  96. data/generated/google/apis/dialogflow_v3beta1.rb +1 -1
  97. data/generated/google/apis/dialogflow_v3beta1/classes.rb +5145 -2336
  98. data/generated/google/apis/dialogflow_v3beta1/representations.rb +1729 -344
  99. data/generated/google/apis/dialogflow_v3beta1/service.rb +408 -0
  100. data/generated/google/apis/dlp_v2.rb +1 -1
  101. data/generated/google/apis/dlp_v2/service.rb +3 -9
  102. data/generated/google/apis/documentai_v1beta2.rb +1 -1
  103. data/generated/google/apis/documentai_v1beta2/classes.rb +5 -92
  104. data/generated/google/apis/documentai_v1beta2/representations.rb +2 -15
  105. data/generated/google/apis/documentai_v1beta3.rb +1 -1
  106. data/generated/google/apis/documentai_v1beta3/classes.rb +5 -92
  107. data/generated/google/apis/documentai_v1beta3/representations.rb +2 -15
  108. data/generated/google/apis/gameservices_v1.rb +1 -1
  109. data/generated/google/apis/gameservices_v1/service.rb +14 -14
  110. data/generated/google/apis/gameservices_v1beta.rb +1 -1
  111. data/generated/google/apis/gameservices_v1beta/service.rb +14 -14
  112. data/generated/google/apis/localservices_v1.rb +4 -1
  113. data/generated/google/apis/manufacturers_v1.rb +1 -1
  114. data/generated/google/apis/manufacturers_v1/classes.rb +2 -2
  115. data/generated/google/apis/monitoring_v3.rb +1 -1
  116. data/generated/google/apis/monitoring_v3/classes.rb +2 -2
  117. data/generated/google/apis/notebooks_v1.rb +1 -1
  118. data/generated/google/apis/notebooks_v1/classes.rb +13 -0
  119. data/generated/google/apis/notebooks_v1/representations.rb +12 -0
  120. data/generated/google/apis/notebooks_v1/service.rb +34 -0
  121. data/generated/google/apis/prod_tt_sasportal_v1alpha1.rb +1 -1
  122. data/generated/google/apis/prod_tt_sasportal_v1alpha1/classes.rb +0 -37
  123. data/generated/google/apis/prod_tt_sasportal_v1alpha1/representations.rb +0 -18
  124. data/generated/google/apis/recommendationengine_v1beta1.rb +1 -1
  125. data/generated/google/apis/recommendationengine_v1beta1/service.rb +2 -1
  126. data/generated/google/apis/securitycenter_v1.rb +1 -1
  127. data/generated/google/apis/securitycenter_v1/classes.rb +18 -10
  128. data/generated/google/apis/securitycenter_v1/representations.rb +1 -0
  129. data/generated/google/apis/securitycenter_v1/service.rb +30 -30
  130. data/generated/google/apis/securitycenter_v1beta1.rb +1 -1
  131. data/generated/google/apis/securitycenter_v1beta1/classes.rb +7 -0
  132. data/generated/google/apis/securitycenter_v1beta1/representations.rb +1 -0
  133. data/generated/google/apis/securitycenter_v1beta2.rb +1 -1
  134. data/generated/google/apis/securitycenter_v1beta2/classes.rb +7 -0
  135. data/generated/google/apis/securitycenter_v1beta2/representations.rb +1 -0
  136. data/generated/google/apis/servicemanagement_v1.rb +1 -1
  137. data/generated/google/apis/servicemanagement_v1/classes.rb +11 -10
  138. data/generated/google/apis/sqladmin_v1beta4.rb +1 -1
  139. data/generated/google/apis/sqladmin_v1beta4/classes.rb +7 -7
  140. data/generated/google/apis/sqladmin_v1beta4/service.rb +4 -1
  141. data/generated/google/apis/storagetransfer_v1.rb +1 -1
  142. data/generated/google/apis/storagetransfer_v1/classes.rb +25 -0
  143. data/generated/google/apis/storagetransfer_v1/representations.rb +3 -0
  144. data/generated/google/apis/webmasters_v3/classes.rb +8 -0
  145. data/generated/google/apis/webmasters_v3/representations.rb +1 -0
  146. data/generated/google/apis/youtube_v3.rb +1 -1
  147. data/generated/google/apis/youtube_v3/classes.rb +18 -143
  148. data/generated/google/apis/youtube_v3/representations.rb +0 -57
  149. data/generated/google/apis/youtube_v3/service.rb +0 -43
  150. data/lib/google/apis/version.rb +1 -23
  151. metadata +27 -263
  152. data/.github/CONTRIBUTING.md +0 -31
  153. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -36
  154. data/.github/ISSUE_TEMPLATE/feature_request.md +0 -21
  155. data/.github/ISSUE_TEMPLATE/support_request.md +0 -7
  156. data/.github/workflows/autoapprove.yml +0 -49
  157. data/.github/workflows/release-please.yml +0 -57
  158. data/.gitignore +0 -23
  159. data/.kokoro/build.bat +0 -11
  160. data/.kokoro/build.sh +0 -4
  161. data/.kokoro/continuous/common.cfg +0 -25
  162. data/.kokoro/continuous/linux.cfg +0 -25
  163. data/.kokoro/continuous/osx.cfg +0 -8
  164. data/.kokoro/continuous/post.cfg +0 -30
  165. data/.kokoro/continuous/windows.cfg +0 -29
  166. data/.kokoro/osx.sh +0 -4
  167. data/.kokoro/presubmit/common.cfg +0 -24
  168. data/.kokoro/presubmit/linux.cfg +0 -24
  169. data/.kokoro/presubmit/osx.cfg +0 -8
  170. data/.kokoro/presubmit/windows.cfg +0 -29
  171. data/.kokoro/release.cfg +0 -94
  172. data/.kokoro/trampoline.bat +0 -10
  173. data/.kokoro/trampoline.sh +0 -4
  174. data/.repo-metadata.json +0 -5
  175. data/.rspec +0 -2
  176. data/.rubocop.yml +0 -12
  177. data/.rubocop_todo.yml +0 -63
  178. data/CODE_OF_CONDUCT.md +0 -43
  179. data/Gemfile +0 -55
  180. data/MIGRATING.md +0 -215
  181. data/README.md +0 -402
  182. data/Rakefile +0 -131
  183. data/api_list_config.yaml +0 -9
  184. data/api_names.yaml +0 -1082
  185. data/bin/generate-api +0 -194
  186. data/docs/api-keys.md +0 -20
  187. data/docs/auth.md +0 -53
  188. data/docs/client-secrets.md +0 -69
  189. data/docs/getting-started.md +0 -340
  190. data/docs/installation.md +0 -0
  191. data/docs/logging.md +0 -34
  192. data/docs/media-upload.md +0 -25
  193. data/docs/oauth-installed.md +0 -191
  194. data/docs/oauth-server.md +0 -133
  195. data/docs/oauth-web.md +0 -280
  196. data/docs/oauth.md +0 -268
  197. data/docs/pagination.md +0 -29
  198. data/docs/performance.md +0 -25
  199. data/google-api-client.gemspec +0 -36
  200. data/lib/google/api_client/auth/installed_app.rb +0 -143
  201. data/lib/google/api_client/auth/key_utils.rb +0 -94
  202. data/lib/google/api_client/auth/storage.rb +0 -104
  203. data/lib/google/api_client/auth/storages/file_store.rb +0 -57
  204. data/lib/google/api_client/auth/storages/redis_store.rb +0 -59
  205. data/lib/google/api_client/client_secrets.rb +0 -176
  206. data/lib/google/apis.rb +0 -58
  207. data/lib/google/apis/core/api_command.rb +0 -209
  208. data/lib/google/apis/core/base_service.rb +0 -447
  209. data/lib/google/apis/core/batch.rb +0 -236
  210. data/lib/google/apis/core/composite_io.rb +0 -97
  211. data/lib/google/apis/core/download.rb +0 -118
  212. data/lib/google/apis/core/hashable.rb +0 -44
  213. data/lib/google/apis/core/http_command.rb +0 -447
  214. data/lib/google/apis/core/json_representation.rb +0 -153
  215. data/lib/google/apis/core/multipart.rb +0 -135
  216. data/lib/google/apis/core/upload.rb +0 -273
  217. data/lib/google/apis/errors.rb +0 -89
  218. data/lib/google/apis/generator.rb +0 -71
  219. data/lib/google/apis/generator/annotator.rb +0 -339
  220. data/lib/google/apis/generator/helpers.rb +0 -76
  221. data/lib/google/apis/generator/model.rb +0 -187
  222. data/lib/google/apis/generator/template.rb +0 -124
  223. data/lib/google/apis/generator/templates/_class.tmpl +0 -43
  224. data/lib/google/apis/generator/templates/_method.tmpl +0 -92
  225. data/lib/google/apis/generator/templates/_representation.tmpl +0 -51
  226. data/lib/google/apis/generator/templates/_representation_stub.tmpl +0 -17
  227. data/lib/google/apis/generator/templates/_representation_type.tmpl +0 -10
  228. data/lib/google/apis/generator/templates/classes.rb.tmpl +0 -29
  229. data/lib/google/apis/generator/templates/module.rb.tmpl +0 -40
  230. data/lib/google/apis/generator/templates/representations.rb.tmpl +0 -32
  231. data/lib/google/apis/generator/templates/service.rb.tmpl +0 -61
  232. data/lib/google/apis/options.rb +0 -116
  233. data/rakelib/devsite/devsite_builder.rb +0 -126
  234. data/rakelib/devsite/link_checker.rb +0 -64
  235. data/rakelib/devsite/repo_metadata.rb +0 -56
  236. data/rakelib/metrics.rake +0 -22
  237. data/rakelib/rubocop.rake +0 -10
  238. data/rakelib/spec.rake +0 -11
  239. data/rakelib/yard.rake +0 -11
  240. data/samples/cli/.env +0 -4
  241. data/samples/cli/Gemfile +0 -7
  242. data/samples/cli/README.md +0 -51
  243. data/samples/cli/google-api-samples +0 -32
  244. data/samples/cli/lib/base_cli.rb +0 -95
  245. data/samples/cli/lib/samples/adsense.rb +0 -99
  246. data/samples/cli/lib/samples/analytics.rb +0 -80
  247. data/samples/cli/lib/samples/androidpublisher.rb +0 -47
  248. data/samples/cli/lib/samples/bigquery.rb +0 -101
  249. data/samples/cli/lib/samples/calendar.rb +0 -83
  250. data/samples/cli/lib/samples/drive.rb +0 -82
  251. data/samples/cli/lib/samples/gmail.rb +0 -157
  252. data/samples/cli/lib/samples/pubsub.rb +0 -114
  253. data/samples/cli/lib/samples/sheets.rb +0 -61
  254. data/samples/cli/lib/samples/translate.rb +0 -44
  255. data/samples/cli/lib/samples/vision.rb +0 -69
  256. data/samples/cli/lib/samples/you_tube.rb +0 -47
  257. data/samples/web/Gemfile +0 -9
  258. data/samples/web/README.md +0 -44
  259. data/samples/web/app.rb +0 -120
  260. data/samples/web/views/calendar.erb +0 -34
  261. data/samples/web/views/drive.erb +0 -33
  262. data/samples/web/views/home.erb +0 -34
  263. data/samples/web/views/layout.erb +0 -40
  264. data/synth.py +0 -40
@@ -1,268 +0,0 @@
1
- # OAuth 2.0
2
-
3
- This document describes OAuth 2.0, when to use it, how to acquire client IDs and client secrets, and generally how to use OAuth 2.0 with the Google API Client Library for Ruby.
4
-
5
- ## About OAuth 2.0
6
-
7
- OAuth 2.0 is the authorization protocol used by Google APIs. It is summarized on the Authentication page of this library's documentation, and there are other good references as well:
8
-
9
- - [The OAuth 2.0 Authorization Protocol](https://tools.ietf.org/html/rfc6749)
10
- - [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/OAuth2)
11
-
12
- ## Acquiring client IDs and secrets
13
-
14
- To find your project's client ID and client secret, do the following:
15
-
16
- Select an existing OAuth 2.0 credential or open the Credentials page.
17
- If you haven't done so already, create your project's OAuth 2.0 credentials by clicking Create credentials > OAuth client ID, and providing the information needed to create the credentials.
18
- Look for the Client ID in the OAuth 2.0 client IDs section. For details, click the client ID.
19
- There are different types of client IDs, so be sure to get the correct type for your application:
20
-
21
- * Web application client IDs
22
- * Installed application client IDs
23
- * [Service Account](https://developers.google.com/accounts/docs/OAuth2ServiceAccount) client IDs
24
-
25
- **Warning**: Keep your client secret private. If someone obtains your client secret, they could use it to consume your quota, incur charges against your Google APIs Console project, and request access to user data.
26
-
27
- ## The Signet library
28
-
29
- The [Signet](https://github.com/googleapis/signet) library is included with the Google API Client Library for Ruby. It handles all steps of the OAuth 2.0 protocol required for making API calls. It is available as a separate gem if you only need an OAuth 2.0 library.
30
-
31
- ## Flows
32
-
33
- There are three main OAuth 2.0 flows in the Google API Client Library for Ruby: web server, installed application and service account.
34
-
35
- ## Web server
36
-
37
- We start by retrieving the client ID and client secret from a preconfigured client_secrets.json file:
38
-
39
- ```rb
40
- client_secrets = Google::APIClient::ClientSecrets.load
41
- ```
42
- For web-based applications, we then redirect the user to an authorization page:
43
-
44
- ```rb
45
- # Request authorization
46
- redirect user_credentials.authorization_uri.to_s, 303
47
- ```
48
-
49
- The user completes the steps on her browser, and control gets returned to the application via the callback URL:
50
-
51
- ```rb
52
- get '/oauth2callback' do
53
- # Exchange token
54
- user_credentials.code = params[:code] if params[:code]
55
- user_credentials.fetch_access_token!
56
- redirect to('/')
57
- end
58
- ```
59
-
60
- user_credentials now has everything needed to make authenticated requests:
61
-
62
- ```rb
63
- events = calendar.list_events('primary', options: { authorization: user_credentials })
64
- ```
65
-
66
- Below is the full sample we've been looking at.
67
-
68
- ```rb
69
- require 'google/apis/calendar_v3'
70
- require 'google/api_client/client_secrets'
71
- require 'sinatra'
72
- require 'logger'
73
-
74
- enable :sessions
75
-
76
- def logger; settings.logger end
77
-
78
- def calendar; settings.calendar; end
79
-
80
- def user_credentials
81
- # Build a per-request oauth credential based on token stored in session
82
- # which allows us to use a shared API client.
83
- @authorization ||= (
84
- auth = settings.authorization.dup
85
- auth.redirect_uri = to('/oauth2callback')
86
- auth.update_token!(session)
87
- auth
88
- )
89
- end
90
-
91
- configure do
92
- log_file = File.open('calendar.log', 'a+')
93
- log_file.sync = true
94
- logger = Logger.new(log_file)
95
- logger.level = Logger::DEBUG
96
-
97
- Google::Apis::ClientOptions.default.application_name = 'Ruby Calendar sample'
98
- Google::Apis::ClientOptions.default.application_version = '1.0.0'
99
- calendar_api = Google::Apis::CalendarV3::CalendarService.new
100
-
101
- client_secrets = Google::APIClient::ClientSecrets.load
102
- authorization = client_secrets.to_authorization
103
- authorization.scope = 'https://www.googleapis.com/auth/calendar'
104
-
105
- set :authorization, authorization
106
- set :logger, logger
107
- set :calendar, calendar_api
108
- end
109
-
110
- before do
111
- # Ensure user has authorized the app
112
- unless user_credentials.access_token || request.path_info =~ /^\/oauth2/
113
- redirect to('/oauth2authorize')
114
- end
115
- end
116
-
117
- after do
118
- # Serialize the access/refresh token to the session and credential store.
119
- session[:access_token] = user_credentials.access_token
120
- session[:refresh_token] = user_credentials.refresh_token
121
- session[:expires_in] = user_credentials.expires_in
122
- session[:issued_at] = user_credentials.issued_at
123
- end
124
-
125
- get '/oauth2authorize' do
126
- # Request authorization
127
- redirect user_credentials.authorization_uri.to_s, 303
128
- end
129
-
130
- get '/oauth2callback' do
131
- # Exchange token
132
- user_credentials.code = params[:code] if params[:code]
133
- user_credentials.fetch_access_token!
134
- redirect to('/')
135
- end
136
-
137
- get '/' do
138
- # Fetch list of events on the user's default calandar
139
- events = calendar.list_events('primary', options: { authorization: user_credentials })
140
- [200, {'Content-Type' => 'application/json'}, events.to_h.to_json]
141
- end
142
- ```
143
-
144
- ### Installed application
145
-
146
- We start by retrieving the client ID and client secret from a preconfigured client_secrets.json file:
147
-
148
- ```rb
149
- client_secrets = Google::APIClient::ClientSecrets.load
150
- ```
151
-
152
- For installed applications, we can use the Google::APIClient::InstalledAppFlow helper class to handle most of the setup:
153
-
154
- ```rb
155
- flow = Google::APIClient::InstalledAppFlow.new(
156
- :client_id => client_secrets.client_id,
157
- :client_secret => client_secrets.client_secret,
158
- :scope => ['https://www.googleapis.com/auth/adsense.readonly']
159
- )
160
- ```
161
-
162
- The user completes the steps on her browser, which is opened automatically, and the authorization code is fed into the application automatically, so all it takes is:
163
-
164
- ```rb
165
- adsense.authorization = flow.authorize(storage)
166
- ```
167
-
168
- The client now has everything needed to make an authenticated request:
169
-
170
- ```rb
171
- report = adsense.generate_report(start_date: '2011-01-01', end_date: '2011-08-31',
172
- metric: %w(PAGE_VIEWS AD_REQUESTS AD_REQUESTS_COVERAGE
173
- CLICKS AD_REQUESTS_CTR COST_PER_CLICK
174
- AD_REQUESTS_RPM EARNINGS),
175
- dimension: %w(DATE),
176
- sort: %w(+DATE))
177
- ```
178
-
179
- Below is the full sample we've been looking at.
180
-
181
- ```rb
182
- # AdSense Management API command-line sample.
183
- require 'google/apis/adsense_v1_4'
184
- require 'google/api_client/client_secrets'
185
- require 'google/api_client/auth/installed_app'
186
- require 'google/api_client/auth/storage'
187
- require 'google/api_client/auth/storages/file_store'
188
- require 'logger'
189
- require 'json'
190
-
191
- CREDENTIAL_STORE_FILE = "#{$0}-oauth2.json"
192
-
193
- # Handles authentication and loading of the API.
194
- def setup
195
- log_file = File.open('adsense.log', 'a+')
196
- log_file.sync = true
197
- logger = Logger.new(log_file)
198
- logger.level = Logger::DEBUG
199
-
200
- adsense = Google::Apis::AdsenseV1_4::AdSenseService.new
201
-
202
- # Stores auth credentials in a file, so they survive multiple runs
203
- # of the application. This avoids prompting the user for authorization every
204
- # time the access token expires, by remembering the refresh token.
205
- # Note: FileStorage is not suitable for multi-user applications.
206
- storage = Google::APIClient::Storage.new(
207
- Google::APIClient::FileStore.new(CREDENTIAL_STORE_FILE))
208
- adsense.authorization = storage.authorize
209
- if storage.authorization.nil?
210
- client_secrets = Google::APIClient::ClientSecrets.load
211
- # The InstalledAppFlow is a helper class to handle the OAuth 2.0 installed
212
- # application flow, which ties in with Stroage to store credentials
213
- # between runs.
214
- flow = Google::APIClient::InstalledAppFlow.new(
215
- :client_id => client_secrets.client_id,
216
- :client_secret => client_secrets.client_secret,
217
- :scope => ['https://www.googleapis.com/auth/adsense.readonly']
218
- )
219
- adsense.authorization = flow.authorize(storage)
220
- end
221
- return adsense
222
- end
223
-
224
- # Generates a report for the default account.
225
- def generate_report(adsense)
226
- report = adsense.generate_report(start_date: '2011-01-01', end_date: '2011-08-31',
227
- metric: %w(PAGE_VIEWS AD_REQUESTS AD_REQUESTS_COVERAGE
228
- CLICKS AD_REQUESTS_CTR COST_PER_CLICK
229
- AD_REQUESTS_RPM EARNINGS),
230
- dimension: %w(DATE),
231
- sort: %w(+DATE))
232
-
233
- # Display headers.
234
- report.headers.each do |header|
235
- print '%25s' % header.name
236
- end
237
- puts
238
-
239
- # Display results.
240
- report.rows.each do |row|
241
- row.each do |column|
242
- print '%25s' % column
243
- end
244
- puts
245
- end
246
- end
247
-
248
-
249
- if __FILE__ == $0
250
- adsense = setup()
251
- generate_report(adsense)
252
- end
253
- ```
254
-
255
- ## Service accounts
256
-
257
- For server-to-server interactions, like those between a web application and Google Cloud Storage, Prediction, or BigQuery APIs, you can use service accounts.
258
-
259
- ```rb
260
- require 'googleauth'
261
- require 'google/apis/compute_v1'
262
-
263
- compute = Google::Apis::ComputeV1::ComputeService.new
264
-
265
- # Get the environment configured authorization
266
- scopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/compute']
267
- compute.authorization = Google::Auth.get_application_default(scopes)
268
- ```
@@ -1,29 +0,0 @@
1
- # Pagination
2
-
3
- Some API methods may return very large lists of data. To reduce the response size, many of these API methods support pagination. With paginated results, your application can iteratively request and process large lists one page at a time. When using API methods that support pagination, responses will come back with a next_page property, which builds a request for the next page for you.
4
-
5
- To process the first page of results, construct a request as you normally would. There's usually an API-level parameter you can provide to specify the maximum size of each page, so be sure to check the API's documentation.
6
-
7
- `stamps = service.list_stamps(cents: 5, max_results: 20)`
8
-
9
- For further pages, repeat the request including the next page token from the previous result.
10
-
11
- `stamps = service.list_stamps(cents:5, max_results: 20, page_token: stamps.next_page_token)`
12
-
13
- Here is a full example which loops through the paginated results of a user's public Google Plus activities feed:
14
-
15
- ```rb
16
- require 'google/apis/plus_v1'
17
-
18
- plus = Google::Apis::PlusV1::PlusService.new
19
- plus.key = '...' # API Key from the Google Developers Console
20
- next_page = nil
21
- begin
22
- puts "Fetching page of activities"
23
- activities = plus.list_activities('103354693083460731603', 'public', page_token: next_page)
24
- activities.items.each do |activity|
25
- puts "#{activity.published} #{activity.title}"
26
- end
27
- next_page = activities.next_page_token
28
- end while next_page
29
- ```
@@ -1,25 +0,0 @@
1
- # Performance Tips
2
-
3
- This document covers techniques you can use to improve the performance of your application. The documentation for the specific API you are using should have a similar page with more detail on some of these topics. For example, see the Performance Tips page for the Google Drive API.
4
-
5
- ## Partial response (fields parameter)
6
-
7
- By default, the server sends back the full representation of a resource after processing requests. For better performance, you can ask the server to send only the fields you really need and get a partial response instead.
8
-
9
- To request a partial response, add the standard fields parameter to any API method. The value of this parameter specifies the fields you want returned. You can use this parameter with any request that returns response data.
10
-
11
- In the following code snippet, the list_stamps method of a fictitious Stamps API is called. The cents parameter is defined by the API to only return stamps with the given value. The value of the fields parameter is set to 'count,items/name'code>. The response will only contain stamps whose value is 5 cents, and the data returned will only include the number of stamps found along with the stamp names:
12
-
13
- `response = service.list_stamps(cents: 5, fields: 'count,items/name')`
14
-
15
- Note how commas are used to delimit the desired fields, and slashes are used to indicate fields that are contained in parent fields. There are other formatting options for the fields parameter, and you should see the "Performance Tips" page in the documentation for the API you are using.
16
-
17
- ## Partial update (patch)
18
-
19
- If the API you are calling supports patch, you can avoid sending unnecessary data when modifying resources. For these APIs, you can call the patch() method and supply the arguments you wish to modify for the resource. If supported, the API's reference will have documentation for the patch() method.
20
-
21
- For more information about patch semantics, see the "Performance Tips" page in the documentation for the API you are using.
22
-
23
- ## Batch
24
-
25
- If you are sending many small requests you may benefit from batching, which allows those requests to be bundled into a single HTTP request.
@@ -1,36 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'google/apis/version'
4
-
5
- Gem::Specification.new do |gem|
6
- gem.name = 'google-api-client'
7
- gem.version = Google::Apis::VERSION
8
- gem.authors = ['Steven Bazyl', 'Tim Emiola', 'Sergio Gomes', 'Bob Aman']
9
- gem.email = ['sbazyl@google.com']
10
- gem.summary = 'Client for accessing Google APIs'
11
- gem.homepage = 'https://github.com/google/google-api-ruby-client'
12
- gem.license = 'Apache-2.0'
13
- gem.metadata = {
14
- "documentation_uri" => "https://googleapis.dev/ruby/google-api-client/v#{Google::Apis::VERSION}"
15
- }
16
-
17
- gem.files = `git ls-files -z`
18
- .split("\x0")
19
- .reject { |f| f.match(%r{^(spec|script)/|^api_names_out|synth\.metadata}) }
20
-
21
- gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
- gem.require_paths = %w[lib generated]
23
-
24
- gem.required_ruby_version = '>= 2.4'
25
-
26
- gem.add_runtime_dependency 'representable', '~> 3.0'
27
- gem.add_runtime_dependency 'retriable', '>= 2.0', '< 4.0'
28
- gem.add_runtime_dependency 'addressable', '~> 2.5', '>= 2.5.1'
29
- gem.add_runtime_dependency 'mini_mime', '~> 1.0'
30
- gem.add_runtime_dependency 'signet', '~> 0.12'
31
- gem.add_runtime_dependency 'googleauth', '~> 0.9'
32
- gem.add_runtime_dependency 'httpclient', '>= 2.8.1', '< 3.0'
33
- gem.add_runtime_dependency 'rexml'
34
- gem.add_development_dependency 'thor', '~> 0.19'
35
- gem.add_development_dependency 'activesupport', '>= 4.2', '< 5.1'
36
- end
@@ -1,143 +0,0 @@
1
- # Copyright 2010 Google Inc.
2
- #
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
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
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.
14
-
15
- require 'webrick'
16
-
17
- launchy_available =
18
- begin
19
- require 'launchy'
20
- true
21
- rescue LoadError
22
- warn "Attempted to require google/api_client/auth/installed_app.rb when" \
23
- " launchy is not available. The InstalledAppFlow class is disabled."
24
- false
25
- end
26
-
27
- module Google
28
- class APIClient
29
-
30
- # Small helper for the sample apps for performing OAuth 2.0 flows from the command
31
- # line or in any other installed app environment.
32
- #
33
- # This class is used in some sample apps and tests but is not really part
34
- # of the client libraries, and probably does not belong here. As such, it
35
- # is deprecated. If you do choose to use it, note that you must include the
36
- # `launchy` gem in your bundle, as it is required by this class but not
37
- # listed in the google-api-client gem's requirements.
38
- #
39
- # @example
40
- #
41
- # flow = Google::APIClient::InstalledAppFlow.new(
42
- # :client_id => '691380668085.apps.googleusercontent.com',
43
- # :client_secret => '...',
44
- # :scope => 'https://www.googleapis.com/auth/drive'
45
- # )
46
- # authorization = flow.authorize
47
- # Drive = Google::Apis::DriveV2
48
- # drive = Drive::DriveService.new
49
- # drive.authorization = authorization
50
- #
51
- # @deprecated Use google-auth-library-ruby instead
52
- class InstalledAppFlow
53
-
54
- RESPONSE_BODY = <<-HTML
55
- <html>
56
- <head>
57
- <script>
58
- function closeWindow() {
59
- window.open('', '_self', '');
60
- window.close();
61
- }
62
- setTimeout(closeWindow, 10);
63
- </script>
64
- </head>
65
- <body>You may close this window.</body>
66
- </html>
67
- HTML
68
-
69
- ##
70
- # Configure the flow
71
- #
72
- # @param [Hash] options The configuration parameters for the client.
73
- # @option options [Fixnum] :port
74
- # Port to run the embedded server on. Defaults to 9292
75
- # @option options [String] :client_id
76
- # A unique identifier issued to the client to identify itself to the
77
- # authorization server.
78
- # @option options [String] :client_secret
79
- # A shared symmetric secret issued by the authorization server,
80
- # which is used to authenticate the client.
81
- # @option options [String] :scope
82
- # The scope of the access request, expressed either as an Array
83
- # or as a space-delimited String.
84
- #
85
- # @see Signet::OAuth2::Client
86
- def initialize(options)
87
- @port = options[:port] || 9292
88
- @authorization = Signet::OAuth2::Client.new({
89
- :authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
90
- :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
91
- :redirect_uri => "http://localhost:#{@port}/"}.update(options)
92
- )
93
- end
94
-
95
- ##
96
- # Request authorization. Opens a browser and waits for response.
97
- #
98
- # @param [Google::APIClient::Storage] storage
99
- # Optional object that responds to :write_credentials, used to serialize
100
- # the OAuth 2 credentials after completing the flow.
101
- #
102
- # @return [Signet::OAuth2::Client]
103
- # Authorization instance, nil if user cancelled.
104
- def authorize(storage=nil, options={})
105
- auth = @authorization
106
-
107
- server = WEBrick::HTTPServer.new(
108
- :Port => @port,
109
- :BindAddress =>"localhost",
110
- :Logger => WEBrick::Log.new(STDOUT, 0),
111
- :AccessLog => []
112
- )
113
- begin
114
- trap("INT") { server.shutdown }
115
-
116
- server.mount_proc '/' do |req, res|
117
- auth.code = req.query['code']
118
- if auth.code
119
- auth.fetch_access_token!
120
- end
121
- res.status = WEBrick::HTTPStatus::RC_ACCEPTED
122
- res.body = RESPONSE_BODY
123
- server.stop
124
- end
125
-
126
- Launchy.open(auth.authorization_uri(options).to_s)
127
- server.start
128
- ensure
129
- server.shutdown
130
- end
131
- if @authorization.access_token
132
- if storage.respond_to?(:write_credentials)
133
- storage.write_credentials(@authorization)
134
- end
135
- return @authorization
136
- else
137
- return nil
138
- end
139
- end
140
- end
141
-
142
- end
143
- end if launchy_available