google-ads-common 0.14.1 → 1.0.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
  SHA1:
3
- metadata.gz: 991111457e7120b976a506c037b0fd935aa5c6f9
4
- data.tar.gz: 0a769071c1c36367d1b5f484290584f43401bf72
3
+ metadata.gz: 3323c13c66ba24618874eabc9af72432dbc1aba7
4
+ data.tar.gz: 8e7c3178e7f7dfb61a04a406e904cd7880babb5d
5
5
  SHA512:
6
- metadata.gz: 95974d42f490a7b4395089032f09afd8e570289831120fd51a95cad0fec249150e0a89a26cf4dbfe5286cd886c622ab9ba6f4ff695a74c403ee61e3cfda8a19f
7
- data.tar.gz: 3bcc749b38ab140d2b994bdd2ae01bbf13a34947574412f49498b64f5c83d488bd355503bc399c5b76e49106d048e218099d0132e49a64afc8baa32973062a2b
6
+ metadata.gz: 760fcea64ff72ae3f9e5bc7ba2af0bb73937174a6b6287753685557c20a460b5f53c7798e9e9382d5e4cebe44904220e6e6e1bc53f73a5f48c959e1749987aef
7
+ data.tar.gz: 58d901837aee9ba0a8d5c322232c88dda558567b4e1450fd2e072d783dcda421e2854af51dbe17298318b591007fad9a5d112a00ddd5b02c40ab2bdfe9cbc548
data/ChangeLog CHANGED
@@ -1,3 +1,11 @@
1
+ 1.0.0:
2
+ - Major version bump. The library has been stable and feature complete for
3
+ some time, and this is more accurately reflected by this version number.
4
+ - Throw explicit warning for disabled SSL peer verification.
5
+ - Small performance improvements for large requests.
6
+ - No longer include test files in the built gem.
7
+ - Removing support for multiple environments.
8
+
1
9
  0.14.1:
2
10
  - Scrubbing an additional sensitive field present in some AdWords requests.
3
11
 
data/README.md CHANGED
@@ -68,7 +68,7 @@ Google Ads Developers Plus page:
68
68
 
69
69
  # Copyright/License Info
70
70
 
71
- Copyright 2010-2015, Google Inc. All Rights Reserved.
71
+ Copyright 2010-2017, Google Inc. All Rights Reserved.
72
72
 
73
73
  Licensed under the Apache License, Version 2.0 (the "License");
74
74
  you may not use this file except in compliance with the License.
@@ -70,10 +70,9 @@ module AdsCommon
70
70
  def service(name, version = nil)
71
71
  name = name.to_sym
72
72
  version = (version.nil?) ? api_config.default_version : version.to_sym
73
- environment = @config.read('service.environment')
74
73
 
75
74
  # Check if the combination is available.
76
- validate_service_request(environment, version, name)
75
+ validate_service_request(version, name)
77
76
 
78
77
  # Try to re-use the service for this version if it was requested before.
79
78
  wrapper = if @wrappers.include?(version) && @wrappers[version][name]
@@ -150,12 +149,11 @@ module AdsCommon
150
149
  private
151
150
 
152
151
  # Auxiliary method to test parameters correctness for the service request.
153
- def validate_service_request(environment, version, service)
154
- # Check if the current environment supports the requested version.
155
- unless api_config.environment_has_version(environment, version)
152
+ def validate_service_request(version, service)
153
+ # Check if the current config supports the requested version.
154
+ unless api_config.has_version(version)
156
155
  raise AdsCommon::Errors::Error,
157
- "Environment '%s' does not support version '%s'" %
158
- [environment.to_s, version.to_s]
156
+ "Version '%s' not recognized" % version.to_s
159
157
  end
160
158
 
161
159
  # Check if the specified version has the requested service.
@@ -196,18 +194,14 @@ module AdsCommon
196
194
  raise AdsCommon::Errors::Error,
197
195
  'OAuth authorization method is deprecated, use OAuth2 instead.'
198
196
  when :OAUTH2
199
- environment = @config.read('service.environment',
200
- api_config.default_environment())
201
197
  AdsCommon::Auth::OAuth2Handler.new(
202
198
  @config,
203
- api_config.environment_config(environment, :oauth_scope)
199
+ api_config.config(:oauth_scope)
204
200
  )
205
201
  when :OAUTH2_SERVICE_ACCOUNT
206
- environment = @config.read('service.environment',
207
- api_config.default_environment())
208
202
  AdsCommon::Auth::OAuth2ServiceAccountHandler.new(
209
203
  @config,
210
- api_config.environment_config(environment, :oauth_scope)
204
+ api_config.config(:oauth_scope)
211
205
  )
212
206
  else
213
207
  raise AdsCommon::Errors::Error,
@@ -226,15 +220,13 @@ module AdsCommon
226
220
  # - a simplified wrapper generated for the service
227
221
  #
228
222
  def prepare_wrapper(version, service)
229
- environment = config.read('service.environment')
230
223
  api_config.do_require(version, service)
231
- endpoint = api_config.endpoint(environment, version, service)
224
+ endpoint = api_config.endpoint(version, service)
232
225
  interface_class_name = api_config.interface_name(version, service)
233
226
 
234
227
  wrapper = class_for_path(interface_class_name).new(@config, endpoint)
235
228
  auth_handler = get_auth_handler()
236
- header_ns =
237
- api_config.environment_config(environment, :header_ns) + version.to_s
229
+ header_ns = api_config.config(:header_ns) + version.to_s
238
230
  soap_handler = soap_header_handler(auth_handler, version, header_ns,
239
231
  wrapper.namespace)
240
232
  wrapper.header_handler = soap_handler
@@ -270,10 +262,8 @@ module AdsCommon
270
262
  provided_adapter = @config.read('connection.adapter')
271
263
  @config.set('connection.adapter', :httpclient) if provided_adapter.nil?
272
264
 
273
- # Validating most important parameters.
274
- ['service.environment', 'authentication.method'].each do |parameter|
275
- symbolize_config_value(parameter)
276
- end
265
+ # Make sure Auth param is a symbol.
266
+ symbolize_config_value('authentication.method')
277
267
  end
278
268
 
279
269
  # Converts value of a config key to uppercase symbol.
@@ -42,14 +42,13 @@ module AdsCommon
42
42
  service_config.keys.select { |service| service.is_a? Integer }.max
43
43
  end
44
44
 
45
- # Does the given environment exist and contain the given version?
45
+ # Does the current config contain the given version?
46
46
  #
47
47
  # Returns:
48
- # Boolean indicating whether the given environment exists and contains the
49
- # given version
48
+ # Boolean indicating whether the current config contains the given version
50
49
  #
51
- def environment_has_version(environment, version)
52
- return !environment_config(environment, version).nil?
50
+ def has_version(version)
51
+ return !config(version).nil?
53
52
  end
54
53
 
55
54
  # Does the given version exist and contain the given service?
@@ -94,32 +93,22 @@ module AdsCommon
94
93
  return api_name.to_s.snakecase
95
94
  end
96
95
 
97
- # Get the default environment.
98
- #
99
- # Returns:
100
- # Default environment
101
- #
102
- def default_environment
103
- raise NotImplementedError, 'default_environment not overriden.'
104
- end
105
-
106
96
  # Get the default filename for the config file.
107
97
  def default_config_filename
108
98
  raise NotImplementedError, 'default_config_filename not overriden.'
109
99
  end
110
100
 
111
- # Get the endpoint for a service on a given environment and API version.
101
+ # Get the endpoint for a service on a given API version.
112
102
  #
113
103
  # Args:
114
- # - environment: the service environment to be used
115
104
  # - version: the API version
116
105
  # - service: the name of the API service
117
106
  #
118
107
  # Returns:
119
108
  # The endpoint URL
120
109
  #
121
- def endpoint(environment, version, service)
122
- base = get_wsdl_base(environment, version)
110
+ def endpoint(version, service)
111
+ base = get_wsdl_base(version)
123
112
  # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.9.0.
124
113
  if !subdir_config().nil?
125
114
  base = base.to_s + subdir_config()[[version, service]].to_s
@@ -142,19 +131,6 @@ module AdsCommon
142
131
  subdir_config()[[version, service]]
143
132
  end
144
133
 
145
- # Get the authentication server details for an environment. Allows to
146
- # override the auth URL via environmental variable.
147
- #
148
- # Args:
149
- # - environment: the service environment to be used
150
- #
151
- # Returns:
152
- # The full URL for the auth server
153
- #
154
- def auth_server(environment)
155
- return ENV['ADSAPI_AUTH_URL'] || auth_server_config[environment]
156
- end
157
-
158
134
  # Perform the loading of the necessary source files for a version.
159
135
  #
160
136
  # Args:
@@ -208,7 +184,7 @@ module AdsCommon
208
184
  #
209
185
  def get_wsdls(version)
210
186
  res = {}
211
- wsdl_base = get_wsdl_base(default_environment(), version)
187
+ wsdl_base = get_wsdl_base(version)
212
188
  postfix = wsdl_base.start_with?('http') ? '?wsdl' : '.wsdl'
213
189
  services(version).each do |service|
214
190
  path = wsdl_base
@@ -226,15 +202,13 @@ module AdsCommon
226
202
  # the base URL via environmental variable.
227
203
  #
228
204
  # Args:
229
- # - environment: environment to use like :SANDBOX or :PRODUCTION
230
205
  # - version: the API version
231
206
  #
232
207
  # Returns:
233
208
  # String containing base URL
234
209
  #
235
- def get_wsdl_base(environment, version)
236
- return ENV['ADSAPI_BASE_URL'] ||
237
- environment_config(environment, version)
210
+ def get_wsdl_base(version)
211
+ return ENV['ADSAPI_BASE_URL'] || config(version)
238
212
  end
239
213
  end
240
214
  end
@@ -120,6 +120,10 @@ module AdsCommon
120
120
  strict_ssl =
121
121
  config.read('connection.strict_ssl_verification', true)
122
122
  httpi.auth.ssl.verify_mode = strict_ssl ? :peer : :none
123
+ if logger && !strict_ssl
124
+ logger.warn('HTTPS peer validation is disabled. This is NOT ' +
125
+ 'secure and NOT recommended.')
126
+ end
123
127
  end
124
128
  end
125
129
  end
@@ -33,6 +33,7 @@ module AdsCommon
33
33
 
34
34
  FALLBACK_API_ERROR_EXCEPTION = "ApiException"
35
35
  MAX_FAULT_LOG_LENGTH = 16000
36
+ REDACTED_STR = 'REDACTED'
36
37
 
37
38
  # Creates a new service.
38
39
  def initialize(config, endpoint, namespace, version)
@@ -201,38 +202,35 @@ module AdsCommon
201
202
  summary_message += ', Fault message: %s' % format_fault(
202
203
  response_hash[:envelope][:body][:fault][:faultstring])
203
204
  logger.warn(summary_message)
204
- logger.info(request_message) if request_message
205
- logger.info(response_message) if response_message
205
+ logger.info(request_message) unless request_message.nil?
206
+ logger.info(response_message) unless response_message.nil?
206
207
  else
207
208
  logger.info(summary_message)
208
- logger.debug(request_message) if request_message
209
- logger.debug(response_message) if response_message
209
+ logger.debug(request_message) unless request_message.nil?
210
+ logger.debug(response_message) unless response_message.nil?
210
211
  end
211
212
  end
212
213
 
213
214
  # Format headers, redacting sensitive information.
214
215
  def format_headers(headers)
215
216
  return headers.map do |k, v|
216
- v = 'REDACTED' if k == 'Authorization'
217
+ v = REDACTED_STR if k == 'Authorization'
217
218
  [k, v].join(': ')
218
219
  end.join(', ')
219
220
  end
220
221
 
221
222
  # Sanitize the request body, redacting sensitive information.
222
223
  def sanitize_request(body)
223
- body = body.gsub(/developerToken>[^<]+<\//,
224
- 'developerToken>REDACTED</')
225
- body = body.gsub(/httpAuthorizationHeader>[^<]+<\//,
226
- 'httpAuthorizationHeader>REDACTED</')
227
- return body
224
+ return body.gsub(/(developerToken>|httpAuthorizationHeader>)[^<]+(<\/)/,
225
+ '\1' + REDACTED_STR + '\2')
228
226
  end
229
227
 
230
228
  # Format the fault message by capping length and removing newlines.
231
229
  def format_fault(message)
232
- message = message[0...MAX_FAULT_LOG_LENGTH] if
233
- message.length > MAX_FAULT_LOG_LENGTH
234
- message = message.gsub("\n", " ")
235
- return message
230
+ if message.length > MAX_FAULT_LOG_LENGTH
231
+ message = message[0, MAX_FAULT_LOG_LENGTH]
232
+ end
233
+ return message.gsub("\n", ' ')
236
234
  end
237
235
 
238
236
  # Check whether or not to log request summaries based on log level.
@@ -23,8 +23,7 @@ module AdsCommon
23
23
 
24
24
  # Returns the String in lowerCamelCase.
25
25
  def lower_camelcase()
26
- result = dup()
27
- result.gsub!(/^([A-Z])/) {$1.downcase()}
26
+ result = gsub(/^([A-Z])/) {$1.downcase()}
28
27
  result.gsub!(/(?:_)([a-zA-Z\d])/) {$1.upcase()}
29
28
  return result
30
29
  end
@@ -19,6 +19,6 @@
19
19
 
20
20
  module AdsCommon
21
21
  module ApiConfig
22
- CLIENT_LIB_VERSION = '0.14.1'
22
+ CLIENT_LIB_VERSION = '1.0.0'
23
23
  end
24
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-ads-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Gomes
@@ -10,13 +10,16 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-06-21 00:00:00.000000000 Z
13
+ date: 2017-09-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: google-ads-savon
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ - - ">="
20
23
  - !ruby/object:Gem::Version
21
24
  version: 1.0.2
22
25
  type: :runtime
@@ -24,6 +27,9 @@ dependencies:
24
27
  version_requirements: !ruby/object:Gem::Requirement
25
28
  requirements:
26
29
  - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '1.0'
32
+ - - ">="
27
33
  - !ruby/object:Gem::Version
28
34
  version: 1.0.2
29
35
  - !ruby/object:Gem::Dependency
@@ -60,18 +66,21 @@ dependencies:
60
66
  requirements:
61
67
  - - "~>"
62
68
  - !ruby/object:Gem::Version
63
- version: 0.7.0
69
+ version: '0.7'
64
70
  type: :runtime
65
71
  prerelease: false
66
72
  version_requirements: !ruby/object:Gem::Requirement
67
73
  requirements:
68
74
  - - "~>"
69
75
  - !ruby/object:Gem::Version
70
- version: 0.7.0
76
+ version: '0.7'
71
77
  - !ruby/object:Gem::Dependency
72
78
  name: rake
73
79
  requirement: !ruby/object:Gem::Requirement
74
80
  requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.4'
75
84
  - - ">="
76
85
  - !ruby/object:Gem::Version
77
86
  version: 10.4.2
@@ -79,6 +88,9 @@ dependencies:
79
88
  prerelease: false
80
89
  version_requirements: !ruby/object:Gem::Requirement
81
90
  requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: '10.4'
82
94
  - - ">="
83
95
  - !ruby/object:Gem::Version
84
96
  version: 10.4.2
@@ -114,18 +126,6 @@ files:
114
126
  - lib/ads_common/savon_service.rb
115
127
  - lib/ads_common/utils.rb
116
128
  - lib/ads_common/version.rb
117
- - test/coverage.rb
118
- - test/suite_unittests.rb
119
- - test/test_config.rb
120
- - test/test_config.yml
121
- - test/test_credential_handler.rb
122
- - test/test_env.rb
123
- - test/test_oauth2_handler.rb
124
- - test/test_oauth2_service_account_handler.rb
125
- - test/test_parameters_validator.rb
126
- - test/test_results_extractor.rb
127
- - test/test_savon_service.rb
128
- - test/test_utils.rb
129
129
  homepage: https://github.com/googleads/google-api-ads-ruby
130
130
  licenses:
131
131
  - Apache-2.0
@@ -146,17 +146,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  version: 1.3.6
147
147
  requirements: []
148
148
  rubyforge_project: google-ads-common
149
- rubygems_version: 2.4.8
149
+ rubygems_version: 2.6.8
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Common code for Google Ads APIs
153
- test_files:
154
- - test/test_savon_service.rb
155
- - test/test_config.rb
156
- - test/test_oauth2_service_account_handler.rb
157
- - test/test_credential_handler.rb
158
- - test/test_utils.rb
159
- - test/test_parameters_validator.rb
160
- - test/test_oauth2_handler.rb
161
- - test/test_env.rb
162
- - test/test_results_extractor.rb
153
+ test_files: []
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
5
- #
6
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- # Runs test with coverage tool.
20
-
21
- require 'simplecov'
22
-
23
- SimpleCov.start
24
-
25
- $:.unshift File.expand_path('../../', __FILE__)
26
- require File.join(File.dirname(__FILE__), 'suite_unittests.rb')
27
-
28
- # Now loading all files in the library to make sure we hit all untested files.
29
- lib_base_path = File.expand_path('../../lib', __FILE__)
30
- $:.unshift lib_base_path
31
-
32
- code_files_mask = File.join(lib_base_path, '**/*.rb')
33
- Dir.glob(code_files_mask).each {|file| require file}
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
5
- #
6
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15
- # implied.
16
- # See the License for the specific language governing permissions and
17
- # limitations under the License.
18
- #
19
- # Test suite for unit tests.
20
-
21
- require 'test/unit'
22
-
23
- $:.unshift File.expand_path('../../lib/', __FILE__)
24
- $:.unshift File.expand_path('../../', __FILE__)
25
-
26
- # Ads Common units tests.
27
- test_files_mask = File.join(File.dirname(__FILE__), 'test_*.rb')
28
- Dir.glob(test_files_mask).each {|file| require file}