google-ads-common 0.9.2 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +3 -0
- data/README +15 -1
- data/lib/ads_common/api.rb +12 -1
- data/lib/ads_common/build/savon_registry_generator.rb +1 -1
- data/lib/ads_common/build/savon_service_generator.rb +1 -1
- data/lib/ads_common/utils.rb +24 -0
- data/lib/ads_common/version.rb +1 -1
- data/test/ads_devrel_ruby_ads_common.blueprint +36 -0
- data/test/test_utils.rb +35 -0
- metadata +3 -2
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -4,6 +4,7 @@ This gem is a dependency for the new generation of Ruby Google Ads client
|
|
4
4
|
libraries. It contains common code shared among all of these libraries, such as
|
5
5
|
authentication, SOAP stub generation, error handling, logging, etc.
|
6
6
|
|
7
|
+
|
7
8
|
= Docs for Users
|
8
9
|
|
9
10
|
== 1 - Installation:
|
@@ -18,6 +19,7 @@ The following gem libraries are required:
|
|
18
19
|
- httpi
|
19
20
|
- signet
|
20
21
|
|
22
|
+
|
21
23
|
= Docs for Developers
|
22
24
|
|
23
25
|
== 1 - Directory Structure
|
@@ -31,6 +33,7 @@ The following gem libraries are required:
|
|
31
33
|
requests.
|
32
34
|
- +test/+: Contains the unit tests for the library.
|
33
35
|
|
36
|
+
|
34
37
|
== 2 - Commands
|
35
38
|
|
36
39
|
$ gem build google-ads-common.gemspec
|
@@ -40,9 +43,20 @@ to build the gem
|
|
40
43
|
to run unit tests on the library
|
41
44
|
|
42
45
|
|
46
|
+
== 3 - Resources
|
47
|
+
|
48
|
+
Ruby client libraries code page:
|
49
|
+
|
50
|
+
http://code.google.com/p/google-api-ads-ruby/
|
51
|
+
|
52
|
+
Google Ads Developers Plus page:
|
53
|
+
|
54
|
+
https://plus.google.com/+GoogleAdsDevelopers
|
55
|
+
|
56
|
+
|
43
57
|
= Copyright/License Info
|
44
58
|
|
45
|
-
Copyright 2010-
|
59
|
+
Copyright 2010-2013, Google Inc. All Rights Reserved.
|
46
60
|
|
47
61
|
Licensed under the Apache License, Version 2.0 (the "License");
|
48
62
|
you may not use this file except in compliance with the License.
|
data/lib/ads_common/api.rb
CHANGED
@@ -140,6 +140,13 @@ module AdsCommon
|
|
140
140
|
return @auth_handler
|
141
141
|
end
|
142
142
|
|
143
|
+
# Updates default configuration file to include OAuth2 token information.
|
144
|
+
def save_oauth2_token(token)
|
145
|
+
raise AdsCommon::Errors::Error, "Can't save nil token" if token.nil?
|
146
|
+
AdsCommon::Utils.save_oauth2_token(
|
147
|
+
File.join(ENV['HOME'], api_config.default_config_filename), token)
|
148
|
+
end
|
149
|
+
|
143
150
|
private
|
144
151
|
|
145
152
|
# Auxiliary method to test parameters correctness for the service request.
|
@@ -183,9 +190,13 @@ module AdsCommon
|
|
183
190
|
# - auth handler
|
184
191
|
#
|
185
192
|
def create_auth_handler()
|
186
|
-
auth_method = @config.read('authentication.method', :
|
193
|
+
auth_method = @config.read('authentication.method', :OAUTH2)
|
187
194
|
return case auth_method
|
188
195
|
when :CLIENTLOGIN
|
196
|
+
@logger.warn("ClientLogin authentication method is now deprecated" +
|
197
|
+
" and will be removed in the future. Consider migration to" +
|
198
|
+
" OAuth2. See 'https://developers.google.com/accounts/docs/" +
|
199
|
+
"AuthForInstalledApps' for more details.")
|
189
200
|
AdsCommon::Auth::ClientLoginHandler.new(
|
190
201
|
@config,
|
191
202
|
api_config.client_login_config(:AUTH_SERVER),
|
@@ -31,7 +31,7 @@ module AdsCommon
|
|
31
31
|
#
|
32
32
|
# This is auto-generated code, changes will be overwritten.
|
33
33
|
#
|
34
|
-
# Copyright:: Copyright
|
34
|
+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
|
35
35
|
# License:: Licensed under the Apache License, Version 2.0.
|
36
36
|
#
|
37
37
|
# <%= @generator_stamp %>
|
@@ -31,7 +31,7 @@ module AdsCommon
|
|
31
31
|
#
|
32
32
|
# This is auto-generated code, changes will be overwritten.
|
33
33
|
#
|
34
|
-
# Copyright:: Copyright
|
34
|
+
# Copyright:: Copyright 2013, Google Inc. All Rights Reserved.
|
35
35
|
# License:: Licensed under the Apache License, Version 2.0.
|
36
36
|
#
|
37
37
|
# <%= @generator_stamp %>
|
data/lib/ads_common/utils.rb
CHANGED
@@ -49,6 +49,30 @@ module AdsCommon
|
|
49
49
|
result
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
# Updates file to include token details.
|
54
|
+
def self.save_oauth2_token(filename, token)
|
55
|
+
config_data = {}
|
56
|
+
if File.exist?(filename)
|
57
|
+
config_data = YAML::load_file(filename)
|
58
|
+
new_file_name = self.find_new_name(filename)
|
59
|
+
File.rename(filename, new_file_name)
|
60
|
+
end
|
61
|
+
config_data[:authentication][:oauth2_token] = token
|
62
|
+
File.open(filename, 'w') {|f| f.write(YAML::dump(config_data))}
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
# Returns an available filename for renaming a given file.
|
68
|
+
def self.find_new_name(old_name)
|
69
|
+
counter = 0
|
70
|
+
begin
|
71
|
+
filename = old_name + '.backup' + ((counter > 0) ? counter.to_s : '')
|
72
|
+
counter += 1
|
73
|
+
end while File.exist?(filename)
|
74
|
+
return filename
|
75
|
+
end
|
52
76
|
end
|
53
77
|
end
|
54
78
|
|
data/lib/ads_common/version.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
include "devtools/blueprint/ncl/blueprint_file.ncl";
|
2
|
+
|
3
|
+
blueprint_file = ::blueprint::BlueprintFile(
|
4
|
+
buildable_units = [
|
5
|
+
::blueprint::BuildableUnit(
|
6
|
+
build_patterns = [
|
7
|
+
"//third_party/ruby/ads_api/ads_common/...",
|
8
|
+
],
|
9
|
+
test_patterns = [
|
10
|
+
"//third_party/ruby/ads_api/ads_common:rake-test",
|
11
|
+
],
|
12
|
+
build_flags = ["--cpu=k8",
|
13
|
+
"--java_cpu=k8"],
|
14
|
+
test_flags = [],
|
15
|
+
name = "ads_devrel.ruby.ads_api_clients",
|
16
|
+
coverage_instrumentation_filters = [
|
17
|
+
"third_party/ruby/ads_api/ads_common/",
|
18
|
+
"-third_party/ruby/ads_api/ads_common/test",
|
19
|
+
"-test_.*$",
|
20
|
+
],
|
21
|
+
continuous_build_email = ::blueprint::ContinuousBuildEmailInfo(
|
22
|
+
build_cop_email_addrs = ["ads-client-libs+tap-ruby@google.com"],
|
23
|
+
summary_email_addrs = []),
|
24
|
+
enable_release = false,
|
25
|
+
enable_continuous_build = true,
|
26
|
+
tap_settings = tap::TapBuildableUnitSettings()
|
27
|
+
)
|
28
|
+
],
|
29
|
+
owned_code_depotpaths = [
|
30
|
+
"//depot/google3/third_party/ruby/ads_api/ads_common/...",
|
31
|
+
],
|
32
|
+
mpm_packages = [
|
33
|
+
],
|
34
|
+
project_name = "ads_devrel.ruby.ads_api_clients",
|
35
|
+
mdb_groups = ["ads-api-devrel"]
|
36
|
+
);
|
data/test/test_utils.rb
CHANGED
@@ -20,7 +20,9 @@
|
|
20
20
|
#
|
21
21
|
# Tests the utils.
|
22
22
|
|
23
|
+
require 'tempfile'
|
23
24
|
require 'test/unit'
|
25
|
+
require 'yaml'
|
24
26
|
|
25
27
|
require 'ads_common/utils'
|
26
28
|
|
@@ -75,4 +77,37 @@ class TestUtils < Test::Unit::TestCase
|
|
75
77
|
assert_equal(4, result.size)
|
76
78
|
assert_not_same(result, data)
|
77
79
|
end
|
80
|
+
|
81
|
+
def test_save_oauth2_token()
|
82
|
+
config_stub = {:authentication => {:method => 'OAuth2'}}
|
83
|
+
token = {:token_key => 'token_value', :token_number => 42}
|
84
|
+
expected_result = {
|
85
|
+
:authentication => {
|
86
|
+
:method => 'OAuth2',
|
87
|
+
:oauth2_token => token.dup
|
88
|
+
}
|
89
|
+
}
|
90
|
+
tmp_file = Tempfile.new('ruby-tests')
|
91
|
+
tmp_file.write(YAML::dump(config_stub))
|
92
|
+
filename = tmp_file.path()
|
93
|
+
tmp_file.close()
|
94
|
+
AdsCommon::Utils.save_oauth2_token(filename, token)
|
95
|
+
|
96
|
+
assert(File.exist?(filename))
|
97
|
+
result = YAML::load_file(filename)
|
98
|
+
assert_equal(expected_result, result)
|
99
|
+
assert(File.exist?(filename + '.backup'))
|
100
|
+
File.unlink(filename + '.backup')
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_find_new_name()
|
104
|
+
tmp_file = Tempfile.new('ruby-tests')
|
105
|
+
name1 = AdsCommon::Utils.find_new_name(tmp_file.path())
|
106
|
+
assert_equal(tmp_file.path() + '.backup', name1)
|
107
|
+
File.open(name1, 'w') do |file1|
|
108
|
+
name2 = AdsCommon::Utils.find_new_name(tmp_file.path())
|
109
|
+
assert_equal(tmp_file.path() + '.backup1', name2)
|
110
|
+
end
|
111
|
+
File.unlink(name1)
|
112
|
+
end
|
78
113
|
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.9.
|
4
|
+
version: 0.9.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: savon
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- test/suite_unittests.rb
|
96
96
|
- test/test_credential_handler.rb
|
97
97
|
- test/test_client_login_handler.rb
|
98
|
+
- test/ads_devrel_ruby_ads_common.blueprint
|
98
99
|
- test/test_parameters_validator.rb
|
99
100
|
- test/test_utils.rb
|
100
101
|
- test/test_config.rb
|