gapic-common 0.4.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 407061663f535d2c1d6e4d156b63dc27d7e550a4e965574861d27bfb88abe51b
4
- data.tar.gz: c009e26d53339c5be07d223a61db173fb2897dafe5fcd63ac1e9a72e9f89fa93
3
+ metadata.gz: 60a01e31b774ce16ba39c630c8a9e8271c18ae8a89de1bd6feddeff2c5027983
4
+ data.tar.gz: c173c35d2eeb3cbd1c7cf47769cba71deb464a95766a1939858027c22d766ed8
5
5
  SHA512:
6
- metadata.gz: 305e7cdee55f87e69c966019e62b973247de377503ff6b45a42be1dcd9ac55e1a68c54da35e718c58938d5a490b5ce5bcaf8485b9ad980ae46dbdc5f83c65987
7
- data.tar.gz: bc81ef2c7515b2630dd7e06b1ddc37e160ecc08b733a0670e8d42a3a48e41fadbcddf5d8facf3411cdc129935dd10a845edae7c38de38d7e28b0545bdd7a4b06
6
+ metadata.gz: ee846671cdebbd8d02bd0679f8e789005ea138d9cfcf10cbfac4c5e98b90e47e41a5abfbf165c0002276b8dfb6a5fe97924761eac02c8d3aa36c077a28f581da
7
+ data.tar.gz: a77e8a6feddae4cdb13859739d29901184cba2aa8431132cd4f3ebf5289434cd3b53289aaccca3f5eeaa648e4d988cb65f15a6c3cf7ba463e63e5a94649d5aaa
data/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Release History
2
2
 
3
+ ### 0.5.0 / 2021-06-15
4
+
5
+ * Provide a way to create `x-goog-api-client` headers with rest library version and/or without grpc library version
6
+
7
+ ### 0.4.3 / 2021-06-10
8
+
9
+ * Fix file permissions.
10
+
11
+ ### 0.4.2 / 2021-06-07
12
+
13
+ * Expand googleauth dependency to include 1.x
14
+ * Add a REST PUT method helper to Gapic::Rest.
15
+
3
16
  ### 0.4.1 / 2021-04-15
17
+
4
18
  * Provide a default value for the 'body' in the REST POST method in Gapic::Rest.
5
19
 
6
20
  ### 0.4.0 / 2021-02-23
data/CONTRIBUTING.md CHANGED
@@ -8,7 +8,7 @@ just a few small guidelines you need to follow.
8
8
  Contributions to this project must be accompanied by a Contributor License
9
9
  Agreement. You (or your employer) retain the copyright to your contribution;
10
10
  this simply gives us permission to use and redistribute your contributions as
11
- part of the project. Head over to <https://cla.developers.google.com/> to see
11
+ part of the project. Head over to https://cla.developers.google.com/ to see
12
12
  your current agreements on file or to sign a new one.
13
13
 
14
14
  You generally only need to submit a CLA once, so if you've already submitted one
@@ -14,6 +14,6 @@
14
14
 
15
15
  module Gapic
16
16
  module Common
17
- VERSION = "0.4.1".freeze
17
+ VERSION = "0.6.0".freeze
18
18
  end
19
19
  end
data/lib/gapic/headers.rb CHANGED
@@ -26,17 +26,27 @@ module Gapic
26
26
  # @param gax_version [String] The Gapic version. Defaults to `Gapic::Common::VERSION`.
27
27
  # @param gapic_version [String] The Gapic version.
28
28
  # @param grpc_version [String] The GRPC version. Defaults to `GRPC::VERSION`.
29
- def self.x_goog_api_client ruby_version: nil, lib_name: nil, lib_version: nil,
30
- gax_version: nil, gapic_version: nil, grpc_version: nil
29
+ # @param rest_version [String] The Rest Library (Faraday) version. Defaults to `Faraday::VERSION`.
30
+ # @param transports_version_send [Array] Which transports to send versions for.
31
+ # Allowed values to contain are:
32
+ # `:grpc` to send the GRPC library version (if defined)
33
+ # `:rest` to send the REST library version (if defined)
34
+ # Defaults to `[:grpc]`
35
+ def self.x_goog_api_client ruby_version: nil, lib_name: nil, lib_version: nil, gax_version: nil,
36
+ gapic_version: nil, grpc_version: nil, rest_version: nil,
37
+ transports_version_send: [:grpc]
38
+
31
39
  ruby_version ||= ::RUBY_VERSION
32
40
  gax_version ||= ::Gapic::Common::VERSION
33
41
  grpc_version ||= ::GRPC::VERSION if defined? ::GRPC
42
+ rest_version ||= ::Faraday::VERSION if defined? ::Faraday
34
43
 
35
44
  x_goog_api_client_header = ["gl-ruby/#{ruby_version}"]
36
45
  x_goog_api_client_header << "#{lib_name}/#{lib_version}" if lib_name
37
46
  x_goog_api_client_header << "gax/#{gax_version}"
38
47
  x_goog_api_client_header << "gapic/#{gapic_version}" if gapic_version
39
- x_goog_api_client_header << "grpc/#{grpc_version}" if grpc_version
48
+ x_goog_api_client_header << "grpc/#{grpc_version}" if grpc_version && transports_version_send.include?(:grpc)
49
+ x_goog_api_client_header << "rest/#{rest_version}" if rest_version && transports_version_send.include?(:rest)
40
50
  x_goog_api_client_header.join " ".freeze
41
51
  end
42
52
  end
data/lib/gapic/rest.rb CHANGED
@@ -24,4 +24,6 @@ require "gapic/protobuf"
24
24
  require "gapic/rest/client_stub"
25
25
  require "gapic/rest/error"
26
26
  require "gapic/rest/faraday_middleware"
27
+ require "gapic/rest/operation"
28
+ require "gapic/rest/paged_enumerable"
27
29
  require "json"
@@ -76,6 +76,19 @@ module Gapic
76
76
  make_http_request :delete, uri: uri, body: nil, params: params, options: options
77
77
  end
78
78
 
79
+ ##
80
+ # Makes a PATCH request
81
+ #
82
+ # @param uri [String] uri to send this request to
83
+ # @param body [String] a body to send with the request, nil for requests without a body
84
+ # @param params [Hash] query string parameters for the request
85
+ # @param options [::Gapic::CallOptions] gapic options to be applied to the REST call.
86
+ # Currently only timeout and headers are supported.
87
+ # @return [Faraday::Response]
88
+ def make_patch_request uri:, body:, params: {}, options: {}
89
+ make_http_request :patch, uri: uri, body: body, params: params, options: options
90
+ end
91
+
79
92
  ##
80
93
  # Makes a POST request
81
94
  #
@@ -90,7 +103,7 @@ module Gapic
90
103
  end
91
104
 
92
105
  ##
93
- # Makes a PATCH request
106
+ # Makes a PUT request
94
107
  #
95
108
  # @param uri [String] uri to send this request to
96
109
  # @param body [String] a body to send with the request, nil for requests without a body
@@ -98,8 +111,8 @@ module Gapic
98
111
  # @param options [::Gapic::CallOptions] gapic options to be applied to the REST call.
99
112
  # Currently only timeout and headers are supported.
100
113
  # @return [Faraday::Response]
101
- def make_patch_request uri:, body:, params: {}, options: {}
102
- make_http_request :patch, uri: uri, body: body, params: params, options: options
114
+ def make_put_request uri:, body: nil, params: {}, options: {}
115
+ make_http_request :put, uri: uri, body: body, params: params, options: options
103
116
  end
104
117
 
105
118
  protected
@@ -0,0 +1,33 @@
1
+ # Copyright 2021 Google LLC
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
+ # https://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
+ module Gapic
16
+ module Rest
17
+ ##
18
+ # A base class for the wrappers over the long-running operations to the response of a REST LRO method.
19
+ #
20
+ # @attribute [r] operation
21
+ # @return [Object] The wrapped operation object.
22
+ class BaseOperation
23
+ attr_reader :operation
24
+
25
+ ##
26
+ # @private
27
+ # @param operation [Object] The wrapped operation object.
28
+ def initialize operation
29
+ @operation = operation
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,225 @@
1
+ # Copyright 2021 Google LLC
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
+ # https://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
+ module Gapic
16
+ module Rest
17
+ ##
18
+ # A class to provide the Enumerable interface to the response of a REST paginated method.
19
+ # PagedEnumerable assumes response message holds a list of resources and the token to the next page.
20
+ #
21
+ # PagedEnumerable provides the enumerations over the resource data, and also provides the enumerations over the
22
+ # pages themselves.
23
+ #
24
+ # @example normal iteration over resources.
25
+ # paged_enumerable.each { |resource| puts resource }
26
+ #
27
+ # @example per-page iteration.
28
+ # paged_enumerable.each_page { |page| puts page }
29
+ #
30
+ # @example Enumerable over pages.
31
+ # paged_enumerable.each_page do |page|
32
+ # page.each { |resource| puts resource }
33
+ # end
34
+ #
35
+ # @example more exact operations over pages.
36
+ # while some_condition()
37
+ # page = paged_enumerable.page
38
+ # do_something(page)
39
+ # break if paged_enumerable.next_page?
40
+ # paged_enumerable.next_page
41
+ # end
42
+ #
43
+ # @attribute [r] page
44
+ # @return [Page] The current page object.
45
+ #
46
+ class PagedEnumerable
47
+ include Enumerable
48
+
49
+ attr_reader :page
50
+
51
+ ##
52
+ # @private
53
+ # @param service_stub [Object] The REST service_stub with the baseline implementation for the wrapped method.
54
+ # @param method_name [Symbol] The REST method name that is being wrapped.
55
+ # @param request [Object] The request object.
56
+ # @param response [Object] The response object.
57
+ # @param options [Gapic::CallOptions] The options for making the RPC call.
58
+ # @param format_resource [Proc] A Proc object to format the resource object. The Proc should accept response as an
59
+ # argument, and return a formatted resource object. Optional.
60
+ #
61
+ def initialize service_stub, method_name, resource_field_name, request, response, options, format_resource: nil
62
+ @service_stub = service_stub
63
+ @method_name = method_name
64
+ @resource_field_name = resource_field_name
65
+ @request = request
66
+ @response = response
67
+ @options = options
68
+ @format_resource = format_resource
69
+
70
+ @page = Page.new response, resource_field_name, format_resource: @format_resource
71
+ end
72
+
73
+ ##
74
+ # Iterate over the individual resources, automatically requesting new pages as needed.
75
+ #
76
+ # @yield [Object] Gives the resource objects in the stream.
77
+ #
78
+ # @return [Enumerator] if no block is provided
79
+ #
80
+ def each &block
81
+ return enum_for :each unless block_given?
82
+
83
+ each_page do |page|
84
+ page.each(&block)
85
+ end
86
+ end
87
+
88
+ ##
89
+ # Iterate over the pages.
90
+ #
91
+ # @yield [Page] Gives the pages in the stream.
92
+ #
93
+ # @return [Enumerator] if no block is provided
94
+ #
95
+ def each_page
96
+ return enum_for :each_page unless block_given?
97
+
98
+ loop do
99
+ break if @page.nil?
100
+ yield @page
101
+ next_page!
102
+ end
103
+ end
104
+
105
+ ##
106
+ # True if there is at least one more page of results.
107
+ #
108
+ # @return [Boolean]
109
+ #
110
+ def next_page?
111
+ !next_page_token.nil? && !next_page_token.empty?
112
+ end
113
+
114
+ ##
115
+ # Load the next page and set it as the current page.
116
+ # If there is no next page, sets nil as a current page.
117
+ #
118
+ # @return [Page, nil] the new page object.
119
+ #
120
+ def next_page!
121
+ unless next_page?
122
+ @page = nil
123
+ return @page
124
+ end
125
+
126
+ next_request = @request.dup
127
+ next_request.page_token = @page.next_page_token
128
+
129
+ @response = @service_stub.send @method_name, next_request, @options
130
+ @page = Page.new @response, @resource_field_name, format_resource: @format_resource
131
+ end
132
+ alias next_page next_page!
133
+
134
+ ##
135
+ # The page token to be used for the next RPC call, or the empty string if there is no next page.
136
+ # nil if the iteration is complete.
137
+ #
138
+ # @return [String, nil]
139
+ #
140
+ def next_page_token
141
+ @page&.next_page_token
142
+ end
143
+
144
+ ##
145
+ # The current response object, for the current page.
146
+ # nil if the iteration is complete.
147
+ #
148
+ # @return [Object, nil]
149
+ #
150
+ def response
151
+ @page&.response
152
+ end
153
+
154
+ ##
155
+ # A class to represent a page in a PagedEnumerable. This also implements Enumerable, so it can iterate over the
156
+ # resource elements.
157
+ #
158
+ # @attribute [r] response
159
+ # @return [Object] the response object for the page.
160
+ class Page
161
+ include Enumerable
162
+ attr_reader :response
163
+
164
+ ##
165
+ # @private
166
+ # @param response [Object] The response object for the page.
167
+ # @param resource_field [String] The name of the field in response which holds the resources.
168
+ # @param format_resource [Proc, nil] A Proc object to format the resource object. Default nil (no formatting).
169
+ # The Proc should accept response as an argument, and return a formatted resource object. Optional.
170
+ #
171
+ def initialize response, resource_field, format_resource: nil
172
+ @response = response
173
+ @resource_field = resource_field
174
+ @format_resource = format_resource
175
+ end
176
+
177
+ ##
178
+ # Iterate over the resources.
179
+ #
180
+ # @yield [Object] Gives the resource objects in the page.
181
+ #
182
+ # @return [Enumerator] if no block is provided
183
+ #
184
+ def each
185
+ return enum_for :each unless block_given?
186
+
187
+ # We trust that the field exists and is an Enumerable
188
+ resources.each do |resource|
189
+ resource = @format_resource.call resource if @format_resource
190
+ yield resource
191
+ end
192
+ end
193
+
194
+ ##
195
+ # The page token to be used for the next RPC call, or the empty string if there is no next page.
196
+ #
197
+ # @return [String]
198
+ #
199
+ def next_page_token
200
+ @response.next_page_token
201
+ end
202
+
203
+ ##
204
+ # Whether the next_page_token exists and is not empty
205
+ #
206
+ # @return [Boolean]
207
+ #
208
+ def next_page_token?
209
+ !next_page_token.empty?
210
+ end
211
+
212
+ ##
213
+ # Resources in this page presented as an array.
214
+ # When the iterable is a protobuf map, the `.each |item|` gives just the keys
215
+ # to iterate like a normal hash it should be converted to an array first
216
+ #
217
+ # @return [Array]
218
+ #
219
+ def resources
220
+ @resources ||= @response[@resource_field].to_a
221
+ end
222
+ end
223
+ end
224
+ end
225
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gapic-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google API Authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-16 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 1.3.11
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '2.0'
36
+ version: 2.a
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 1.3.11
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '2.0'
46
+ version: 2.a
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: googleapis-common-protos-types
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -53,7 +53,7 @@ dependencies:
53
53
  version: 1.0.6
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: '2.0'
56
+ version: 2.a
57
57
  type: :runtime
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
@@ -63,47 +63,41 @@ dependencies:
63
63
  version: 1.0.6
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: '2.0'
66
+ version: 2.a
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: googleauth
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '0.15'
74
71
  - - ">="
75
72
  - !ruby/object:Gem::Version
76
- version: 0.15.1
73
+ version: 0.16.2
74
+ - - "<"
75
+ - !ruby/object:Gem::Version
76
+ version: 2.a
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
82
- - !ruby/object:Gem::Version
83
- version: '0.15'
84
81
  - - ">="
85
82
  - !ruby/object:Gem::Version
86
- version: 0.15.1
83
+ version: 0.16.2
84
+ - - "<"
85
+ - !ruby/object:Gem::Version
86
+ version: 2.a
87
87
  - !ruby/object:Gem::Dependency
88
88
  name: google-protobuf
89
89
  requirement: !ruby/object:Gem::Requirement
90
90
  requirements:
91
91
  - - "~>"
92
92
  - !ruby/object:Gem::Version
93
- version: '3.15'
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 3.15.2
93
+ version: '3.14'
97
94
  type: :runtime
98
95
  prerelease: false
99
96
  version_requirements: !ruby/object:Gem::Requirement
100
97
  requirements:
101
98
  - - "~>"
102
99
  - !ruby/object:Gem::Version
103
- version: '3.15'
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: 3.15.2
100
+ version: '3.14'
107
101
  - !ruby/object:Gem::Dependency
108
102
  name: grpc
109
103
  requirement: !ruby/object:Gem::Requirement
@@ -152,14 +146,14 @@ dependencies:
152
146
  requirements:
153
147
  - - "~>"
154
148
  - !ruby/object:Gem::Version
155
- version: '5.10'
149
+ version: '5.14'
156
150
  type: :development
157
151
  prerelease: false
158
152
  version_requirements: !ruby/object:Gem::Requirement
159
153
  requirements:
160
154
  - - "~>"
161
155
  - !ruby/object:Gem::Version
162
- version: '5.10'
156
+ version: '5.14'
163
157
  - !ruby/object:Gem::Dependency
164
158
  name: minitest-autotest
165
159
  requirement: !ruby/object:Gem::Requirement
@@ -278,6 +272,8 @@ files:
278
272
  - lib/gapic/rest/client_stub.rb
279
273
  - lib/gapic/rest/error.rb
280
274
  - lib/gapic/rest/faraday_middleware.rb
275
+ - lib/gapic/rest/operation.rb
276
+ - lib/gapic/rest/paged_enumerable.rb
281
277
  - lib/gapic/stream_input.rb
282
278
  homepage: https://github.com/googleapis/gapic-generator-ruby
283
279
  licenses:
@@ -298,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
294
  - !ruby/object:Gem::Version
299
295
  version: '0'
300
296
  requirements: []
301
- rubygems_version: 3.0.3
297
+ rubygems_version: 3.1.6
302
298
  signing_key:
303
299
  specification_version: 4
304
300
  summary: Common code for GAPIC-generated API clients