google-ads-googleads 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,6 +48,7 @@ require 'google/ads/google_ads/wrapper_util'
48
48
  require 'google/ads/google_ads/logging_interceptor'
49
49
  require 'google/ads/google_ads/factories'
50
50
  require 'google/ads/google_ads/errors'
51
+ require 'google/ads/google_ads/patch_lro_headers'
51
52
 
52
53
  require 'google/gax'
53
54
 
@@ -140,13 +141,33 @@ module Google
140
141
  end
141
142
 
142
143
  if name.nil?
143
- Factories.at_version(version).services.new(
144
+ services = Factories.at_version(version).services.new(
144
145
  service_path: service_path,
145
146
  logging_interceptor: logging_interceptor,
146
147
  credentials: get_updater_proc,
147
148
  metadata: headers,
148
149
  exception_transformer: ERROR_TRANSFORMER
149
150
  )
151
+
152
+ patch_delegator = Class.new do
153
+ def initialize(services, headers, patch_callable)
154
+ @services = services
155
+ @headers = headers
156
+ @patch_callable = patch_callable
157
+ end
158
+
159
+ def respond_to_missing?(sym, include_private=false)
160
+ @services.respond_to?(sym, include_private)
161
+ end
162
+
163
+ def method_missing(name, *args)
164
+ @services.public_send(name, *args) do |cls|
165
+ @patch_callable.call(cls, @headers)
166
+ cls
167
+ end
168
+ end
169
+ end
170
+ patch_delegator.new(services, headers, method(:patch_lro_headers))
150
171
  else
151
172
  class_to_return = lookup_util.raw_service(name, version)
152
173
  class_to_return = Class.new(class_to_return) do
@@ -154,10 +175,11 @@ module Google
154
175
  const_set('SERVICE_ADDRESS', service_path.freeze)
155
176
  end
156
177
 
157
-
158
178
  const_set('GRPC_INTERCEPTORS', [logging_interceptor].compact)
159
179
  end
160
180
 
181
+ patch_lro_headers(class_to_return, headers)
182
+
161
183
  class_to_return.new(
162
184
  credentials: get_updater_proc,
163
185
  metadata: headers,
@@ -166,6 +188,10 @@ module Google
166
188
  end
167
189
  end
168
190
 
191
+ def patch_lro_headers(class_to_return, headers)
192
+ PatchLROHeaders.new(class_to_return, headers).call
193
+ end
194
+
169
195
  # Return a resource or common entity for the provided entity type. For
170
196
  # example, passing :Campaign will return an instantiated Campaign.
171
197
  #
@@ -0,0 +1,92 @@
1
+ require 'google/gax'
2
+
3
+ module Google
4
+ module Ads
5
+ module GoogleAds
6
+ class PatchLROHeaders
7
+ def initialize(class_to_return, headers)
8
+ @class_to_return = class_to_return
9
+ @headers = headers
10
+ end
11
+
12
+ def call
13
+ class_to_return = @class_to_return
14
+ headers = @headers
15
+ return unless defined?(class_to_return::OperationsClient)
16
+ opclient = class_to_return::OperationsClient
17
+
18
+ # This instance evaluates in OperationsClient class object
19
+ opclient.instance_eval do
20
+ h = headers
21
+ # This defines an instance variable on class_to_return::OperationsClient
22
+ # itself, not instances of that class
23
+ break if instance_variable_defined?(:@_patched_initialize)
24
+ @_patched_initialize = true
25
+
26
+ # This grabs the original instance method object that initializes
27
+ # this class (e.g. the autogenerated method in gax-ruby)
28
+ orig_initialize = instance_method(:initialize)
29
+
30
+ # Redefine that method to take anything (because our callers are
31
+ # autogenerated, and so we don't need to worry about these args
32
+ # being correct)
33
+ define_method(:initialize) do |*args, &blk|
34
+ h2 = h
35
+ # What we do in this next stanza is redefine construct_settings
36
+ # to merge headers in to the appopriate place, during the constructor
37
+ # execution, then invoke it, then put the implementation back.
38
+ orig_construct_settings = Google::Gax.method(:construct_settings)
39
+ begin
40
+ # Instance evaling in Google::Gax class object, not in instances
41
+ # of that object
42
+ Google::Gax.instance_eval do
43
+ # start definition
44
+ define_singleton_method(:construct_settings) do |
45
+ service_names,
46
+ client_config,
47
+ config_overrides,
48
+ retry_names,
49
+ timeout,
50
+ bundle_descriptors: {},
51
+ page_descriptors: {},
52
+ metadata: {},
53
+ kwargs: {},
54
+ errors: []|
55
+
56
+ kwargs = kwargs.merge(h2)
57
+
58
+ orig_construct_settings.call(
59
+ service_names,
60
+ client_config,
61
+ config_overrides,
62
+ retry_names,
63
+ timeout,
64
+ bundle_descriptors: bundle_descriptors,
65
+ page_descriptors: page_descriptors,
66
+ metadata: metadata,
67
+ kwargs: kwargs,
68
+ errors: errors
69
+ )
70
+ end
71
+ end
72
+
73
+ # orig_initialize was grabbed on the OperationsClient class,
74
+ # not on an OperationsClient instance, so we have to call
75
+ # bind here to scope that instance_method object to a method
76
+ # object on the instance
77
+ orig_initialize.bind(self).call(*args, &blk)
78
+ ensure
79
+ # undefine our hacked method, and put a delegator back
80
+ Google::Gax.instance_eval do
81
+ undef construct_settings
82
+
83
+ define_singleton_method(:construct_settings, &orig_construct_settings)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -19,7 +19,7 @@
19
19
  module Google
20
20
  module Ads
21
21
  module GoogleAds
22
- CLIENT_LIB_VERSION = '2.2.0'.freeze
22
+ CLIENT_LIB_VERSION = '2.2.1'.freeze
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-ads-googleads
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-23 00:00:00.000000000 Z
11
+ date: 2019-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-gax
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.4'
19
+ version: 1.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.4'
26
+ version: 1.5.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -97,6 +97,7 @@ files:
97
97
  - lib/google/ads/google_ads/logging_interceptor.rb
98
98
  - lib/google/ads/google_ads/lookup_util.rb
99
99
  - lib/google/ads/google_ads/partial_failure_error_decoder.rb
100
+ - lib/google/ads/google_ads/patch_lro_headers.rb
100
101
  - lib/google/ads/google_ads/patches.rb
101
102
  - lib/google/ads/google_ads/utils/v1/path_lookup_util.rb
102
103
  - lib/google/ads/google_ads/utils/v1/proto_lookup_util.rb