google-ads-googleads 2.0.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ require "google/ads/google_ads/factories/v1/resources"
2
+ require "google/ads/google_ads/factories/v1/services"
3
+ require "google/ads/google_ads/factories/v1/enums"
4
+ require "google/ads/google_ads/factories/v1/operations"
5
+
6
+ module Google
7
+ module Ads
8
+ module GoogleAds
9
+ module Factories
10
+ Factory = Struct.new(:resources, :services, :enums, :operations)
11
+
12
+ FACTORY_V1 = Factory.new(
13
+ V1::Resources,
14
+ V1::Services,
15
+ V1::Enums,
16
+ V1::Operations,
17
+ ).freeze
18
+
19
+ def self.at_version(version)
20
+ case version
21
+
22
+ when :V1
23
+ FACTORY_V1
24
+
25
+ else
26
+ raise ArgumentError.new("Got unkown version: #{version}")
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -47,7 +47,7 @@ module Google
47
47
  def self.with(obj)
48
48
  raise 'nil cannot be compared' if obj.nil?
49
49
  original = obj.class.decode(obj.class.encode(obj))
50
- yield
50
+ yield obj
51
51
  compare original, obj
52
52
  end
53
53
 
@@ -46,7 +46,7 @@ require 'google/ads/google_ads/field_mask_util'
46
46
  require 'google/ads/google_ads/lookup_util'
47
47
  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
51
 
52
52
  require 'google/gax'
@@ -108,26 +108,13 @@ module Google
108
108
  # :Campaign will return an instantiated CampaignServiceClient.
109
109
  #
110
110
  # Raises ArgumentError if no service can be found for the provided type.
111
- def service(name, version = default_api_version)
111
+ def service(name=nil, version = default_api_version)
112
112
  service_path = ENV['GOOGLEADS_SERVICE_PATH']
113
113
 
114
114
  # We need a local reference to refer to from within the class block
115
115
  # below.
116
116
  logger = @logger
117
117
 
118
- class_to_return = lookup_util.raw_service(name, version)
119
- class_to_return = Class.new(class_to_return) do
120
- unless service_path.nil? || service_path.empty?
121
- const_set('SERVICE_ADDRESS', service_path.freeze)
122
- end
123
-
124
- if logger
125
- logging_interceptor =
126
- Google::Ads::GoogleAds::LoggingInterceptor.new(logger)
127
- const_set('GRPC_INTERCEPTORS', [logging_interceptor])
128
- end
129
- end
130
-
131
118
  headers = {
132
119
  :"developer-token" => @config.developer_token
133
120
  }
@@ -140,27 +127,60 @@ module Google
140
127
  end
141
128
  headers[:"login-customer-id"] = login_customer_id.to_s # header values must be strings
142
129
  end
143
- return class_to_return.new(
144
- credentials: get_updater_proc(),
145
- metadata: headers,
146
- exception_transformer: ERROR_TRANSFORMER
147
- )
130
+
131
+ if logger
132
+ logging_interceptor = Google::Ads::GoogleAds::LoggingInterceptor.new(logger)
133
+ end
134
+
135
+ if name.nil?
136
+ Factories.at_version(version).services.new(
137
+ service_path: service_path,
138
+ logging_interceptor: logging_interceptor,
139
+ credentials: get_updater_proc,
140
+ metadata: headers,
141
+ exception_transformer: ERROR_TRANSFORMER
142
+ )
143
+ else
144
+ class_to_return = lookup_util.raw_service(name, version)
145
+ class_to_return = Class.new(class_to_return) do
146
+ unless service_path.nil? || service_path.empty?
147
+ const_set('SERVICE_ADDRESS', service_path.freeze)
148
+ end
149
+
150
+
151
+ const_set('GRPC_INTERCEPTORS', [logging_interceptor].compact)
152
+ end
153
+
154
+ class_to_return.new(
155
+ credentials: get_updater_proc,
156
+ metadata: headers,
157
+ exception_transformer: ERROR_TRANSFORMER
158
+ )
159
+ end
148
160
  end
149
161
 
150
162
  # Return a resource or common entity for the provided entity type. For
151
163
  # example, passing :Campaign will return an instantiated Campaign.
152
164
  #
153
165
  # Raises ArgumentError if no entity can be found for the provided type.
154
- def resource(name, version = default_api_version)
155
- lookup_util.resource(name, version)
166
+ def resource(name=nil, version=default_api_version)
167
+ if name.nil?
168
+ Factories.at_version(version).resources
169
+ else
170
+ lookup_util.resource(name, version)
171
+ end
156
172
  end
157
173
 
158
174
  # Return an operation for the provided entity type. For example, passing
159
175
  # :Campaign will return an instantiated CampaignOperation.
160
176
  #
161
177
  # Raises ArgumentError if no entity can be found for the provided type.
162
- def operation(name, version = default_api_version)
163
- lookup_util.operation(name, version)
178
+ def operation(name=nil, version = default_api_version)
179
+ if name.nil?
180
+ Factories.at_version(version).operations
181
+ else
182
+ lookup_util.operation(name, version)
183
+ end
164
184
  end
165
185
 
166
186
  # Return a reference to the enum class for the provided enum type. For
@@ -168,8 +188,12 @@ module Google
168
188
  # CampaignStatusEnum.
169
189
  #
170
190
  # Raises ArgumentError if no enum can be found for the provided type.
171
- def enum(name, version = default_api_version)
172
- lookup_util.enum(name, version)
191
+ def enum(name=nil, version = default_api_version)
192
+ if name.nil?
193
+ Factories.at_version(version).enums
194
+ else
195
+ lookup_util.enum(name, version)
196
+ end
173
197
  end
174
198
 
175
199
  # Returns a reference to the FieldMaskUtil class for ease of access.
@@ -231,6 +255,14 @@ module Google
231
255
  raise gax_error
232
256
  end
233
257
 
258
+ def get_credentials()
259
+ if @config.authentication
260
+ @config.authentication
261
+ else
262
+ get_updater_proc
263
+ end
264
+ end
265
+
234
266
  # Provides the service a method by which to obtain an access token to
235
267
  # authenticate API requests.
236
268
  def get_updater_proc()
@@ -19,7 +19,7 @@
19
19
  module Google
20
20
  module Ads
21
21
  module GoogleAds
22
- CLIENT_LIB_VERSION = '2.0.0'.freeze
22
+ CLIENT_LIB_VERSION = '2.1.1'.freeze
23
23
  end
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-ads-googleads
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.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-01 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-gax
@@ -87,6 +87,11 @@ files:
87
87
  - lib/google/ads/google_ads/api_versions.rb
88
88
  - lib/google/ads/google_ads/config.rb
89
89
  - lib/google/ads/google_ads/errors.rb
90
+ - lib/google/ads/google_ads/factories.rb
91
+ - lib/google/ads/google_ads/factories/v1/enums.rb
92
+ - lib/google/ads/google_ads/factories/v1/operations.rb
93
+ - lib/google/ads/google_ads/factories/v1/resources.rb
94
+ - lib/google/ads/google_ads/factories/v1/services.rb
90
95
  - lib/google/ads/google_ads/field_mask_util.rb
91
96
  - lib/google/ads/google_ads/google_ads_client.rb
92
97
  - lib/google/ads/google_ads/logging_interceptor.rb