google-ads-common 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +4 -0
- data/lib/ads_common/api_config.rb +26 -13
- data/lib/ads_common/auth/base_handler.rb +7 -2
- data/lib/ads_common/auth/client_login_handler.rb +5 -0
- data/lib/ads_common/auth/oauth_handler.rb +25 -0
- data/lib/ads_common/savon_headers/base_header_handler.rb +3 -3
- data/lib/ads_common/savon_headers/oauth_header_handler.rb +5 -22
- data/lib/ads_common/savon_headers/simple_header_handler.rb +3 -5
- data/lib/ads_common/savon_service.rb +1 -1
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -26,7 +26,7 @@ module AdsCommon
|
|
26
26
|
# Contains helper methods for loading and managing the available services.
|
27
27
|
# This module is meant to be imported into API-specific modules.
|
28
28
|
module ApiConfig
|
29
|
-
ADS_COMMON_VERSION = '0.5.
|
29
|
+
ADS_COMMON_VERSION = '0.5.4'
|
30
30
|
|
31
31
|
# Get the available API versions.
|
32
32
|
#
|
@@ -98,13 +98,18 @@ module AdsCommon
|
|
98
98
|
environment_config.keys
|
99
99
|
end
|
100
100
|
|
101
|
+
# Get the API name.
|
102
|
+
def api_name
|
103
|
+
raise NotImplementedError, 'api_name not overriden.'
|
104
|
+
end
|
105
|
+
|
101
106
|
# Get the default environment.
|
102
107
|
#
|
103
108
|
# Returns:
|
104
109
|
# Default environment (as a string)
|
105
110
|
#
|
106
111
|
def default_environment
|
107
|
-
|
112
|
+
raise NotImplementedError, 'default_environment not overriden.'
|
108
113
|
end
|
109
114
|
|
110
115
|
# Get the default filename for the config file.
|
@@ -160,29 +165,37 @@ module AdsCommon
|
|
160
165
|
return auth_server_url
|
161
166
|
end
|
162
167
|
|
163
|
-
# Perform the loading of the necessary source files for a version
|
168
|
+
# Perform the loading of the necessary source files for a version.
|
164
169
|
#
|
165
170
|
# Args:
|
166
|
-
# - version: the API version (as
|
171
|
+
# - version: the API version (as a symbol)
|
172
|
+
# - service: service name (as a symbol)
|
173
|
+
#
|
174
|
+
# Returns:
|
175
|
+
# The filename that was loaded.
|
167
176
|
#
|
168
177
|
def do_require(version, service)
|
169
|
-
|
178
|
+
filename = "%s/%s/%s" %
|
179
|
+
[api_name.to_s.snakecase, version.to_s, service.to_s.snakecase]
|
180
|
+
require filename
|
181
|
+
return filename
|
170
182
|
end
|
171
183
|
|
172
|
-
# Returns the full module name for a given service
|
184
|
+
# Returns the full module name for a given service.
|
173
185
|
#
|
174
186
|
# Args:
|
175
|
-
# - version: the API version (as
|
176
|
-
# - service: the service name (as a
|
187
|
+
# - version: the API version (as a symbol)
|
188
|
+
# - service: the service name (as a symbol)
|
177
189
|
#
|
178
190
|
# Returns:
|
179
|
-
# The full module name for the given service (as a string)
|
191
|
+
# The full module name for the given service (as a string).
|
180
192
|
#
|
181
193
|
def module_name(version, service)
|
182
|
-
return "
|
194
|
+
return "%s::%s::%s" %
|
195
|
+
[api_name, version.to_s.upcase, service.to_s]
|
183
196
|
end
|
184
197
|
|
185
|
-
# Returns the full interface class name for a given service
|
198
|
+
# Returns the full interface class name for a given service.
|
186
199
|
#
|
187
200
|
# Args:
|
188
201
|
# - version: the API version (as an integer)
|
@@ -192,7 +205,7 @@ module AdsCommon
|
|
192
205
|
# The full interface class name for the given service (as a string)
|
193
206
|
#
|
194
207
|
def interface_name(version, service)
|
195
|
-
return module_name(version, service) + "
|
208
|
+
return module_name(version, service) + "::" + service.to_s
|
196
209
|
end
|
197
210
|
|
198
211
|
# Returns the full wrapper class name for a given service
|
@@ -237,7 +250,7 @@ module AdsCommon
|
|
237
250
|
# the base URL via environmental variable.
|
238
251
|
#
|
239
252
|
# Args:
|
240
|
-
# - environment: environment to use like SANDBOX or PRODUCTION
|
253
|
+
# - environment: environment to use like :SANDBOX or :PRODUCTION
|
241
254
|
# - version: the API version.
|
242
255
|
#
|
243
256
|
# Returns:
|
@@ -63,9 +63,14 @@ module AdsCommon
|
|
63
63
|
return @token
|
64
64
|
end
|
65
65
|
|
66
|
-
# Creates authorization token. Needs to be
|
66
|
+
# Creates authorization token. Needs to be overridden.
|
67
67
|
def create_token(credentials)
|
68
|
-
raise NotImplementedError, 'create_token not
|
68
|
+
raise NotImplementedError, 'create_token not overridden.'
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns authorization string. Needs to be overridden.
|
72
|
+
def auth_string(credentials, request)
|
73
|
+
raise NotImplementedError, 'auth_string not overridden.'
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
@@ -76,6 +76,11 @@ module AdsCommon
|
|
76
76
|
return result
|
77
77
|
end
|
78
78
|
|
79
|
+
# Returns authorization string.
|
80
|
+
def auth_string(credentials, request)
|
81
|
+
return ("GoogleLogin auth=%s" % get_token(credentials))
|
82
|
+
end
|
83
|
+
|
79
84
|
private
|
80
85
|
|
81
86
|
# Auxiliary method to validate the credentials for token generation.
|
@@ -98,6 +98,31 @@ module AdsCommon
|
|
98
98
|
return @consumer
|
99
99
|
end
|
100
100
|
|
101
|
+
# Returns authorization string.
|
102
|
+
def auth_string(credentials, request)
|
103
|
+
if request.nil?
|
104
|
+
raise AdsCommon::Errors::AuthError,
|
105
|
+
'Request is required for OAuth generator.'
|
106
|
+
end
|
107
|
+
return generate_oauth_parameters_string(credentials, request)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Generates auth string for OAuth method of authentication.
|
111
|
+
#
|
112
|
+
# Args:
|
113
|
+
# - credentials: credentials set for authorization
|
114
|
+
# - request: a HTTPI Request to generate headers for
|
115
|
+
#
|
116
|
+
# Returns:
|
117
|
+
# - Authentication string
|
118
|
+
#
|
119
|
+
def generate_oauth_parameters_string(credentials, request)
|
120
|
+
oauth_params = {:consumer => @consumer,
|
121
|
+
:token => get_token(credentials)}
|
122
|
+
oauth_helper = OAuth::Client::Helper.new(request, oauth_params)
|
123
|
+
return oauth_helper.header
|
124
|
+
end
|
125
|
+
|
101
126
|
private
|
102
127
|
|
103
128
|
# Auxiliary method to validate the credentials for token generation.
|
@@ -84,11 +84,11 @@ module AdsCommon
|
|
84
84
|
|
85
85
|
# Generates User-Agent text for HTTP request.
|
86
86
|
def generate_user_agent_string()
|
87
|
-
credentials = @credential_handler.credentials
|
88
|
-
app_name = credentials[:
|
87
|
+
credentials = @credential_handler.credentials(@version)
|
88
|
+
app_name = credentials[:userAgent] || credentials[:useragent]
|
89
89
|
# We don't know the library version here. A breaking change needs to be
|
90
90
|
# introduced. This is scheduled for 0.6.0, using Common version for now.
|
91
|
-
lib_version = '0.5.
|
91
|
+
lib_version = '0.5.4'
|
92
92
|
soap_user_agent = "Common-Ruby-%s; %s" % [lib_version, app_name]
|
93
93
|
return "Savon/%s (%s)" % [Savon::Version, soap_user_agent]
|
94
94
|
end
|
@@ -19,8 +19,6 @@
|
|
19
19
|
#
|
20
20
|
# Handles SOAP headers and namespaces definition for OAuth type header.
|
21
21
|
|
22
|
-
require 'oauth'
|
23
|
-
|
24
22
|
require 'ads_common/savon_headers/base_header_handler'
|
25
23
|
require 'ads_common/savon_headers/httpi_request_proxy'
|
26
24
|
|
@@ -57,11 +55,14 @@ module AdsCommon
|
|
57
55
|
# - Hash containing a header with filled in credentials
|
58
56
|
#
|
59
57
|
def generate_headers(request, soap)
|
60
|
-
|
58
|
+
credentials = @credential_handler.credentials
|
59
|
+
headers = @auth_handler.headers(credentials)
|
61
60
|
request_header = headers.inject({}) do |request_header, (header, value)|
|
62
61
|
if header == :access_token
|
62
|
+
request.url = soap.endpoint
|
63
63
|
request.headers['Authorization'] =
|
64
|
-
generate_oauth_parameters_string(
|
64
|
+
@auth_handler.generate_oauth_parameters_string(credentials,
|
65
|
+
request)
|
65
66
|
else
|
66
67
|
request_header[prepend_namespace(header)] = value
|
67
68
|
end
|
@@ -69,24 +70,6 @@ module AdsCommon
|
|
69
70
|
end
|
70
71
|
soap.header[prepend_namespace(@element_name)] = request_header
|
71
72
|
end
|
72
|
-
|
73
|
-
# Generates auth string for OAuth method of authentication.
|
74
|
-
#
|
75
|
-
# Args:
|
76
|
-
# - request: a HTTPI::Request to sign
|
77
|
-
# - access_token: an initialized OAuth AccessToken
|
78
|
-
# - url: request URL to generate auth string for
|
79
|
-
#
|
80
|
-
# Returns:
|
81
|
-
# - Authentication string
|
82
|
-
#
|
83
|
-
def generate_oauth_parameters_string(request, access_token, url)
|
84
|
-
request.url = url
|
85
|
-
oauth_params = {:consumer => @auth_handler.get_oauth_consumer(),
|
86
|
-
:token => access_token}
|
87
|
-
oauth_helper = OAuth::Client::Helper.new(request, oauth_params)
|
88
|
-
return oauth_helper.header
|
89
|
-
end
|
90
73
|
end
|
91
74
|
end
|
92
75
|
end
|
@@ -54,11 +54,9 @@ module AdsCommon
|
|
54
54
|
# - Hash containing a header with filled in credentials
|
55
55
|
#
|
56
56
|
def generate_request_header()
|
57
|
-
headers = @auth_handler.headers(
|
58
|
-
|
59
|
-
|
60
|
-
request_header
|
61
|
-
end
|
57
|
+
headers = @auth_handler.headers(
|
58
|
+
@credential_handler.credentials(@version))
|
59
|
+
return headers[@element_name]
|
62
60
|
end
|
63
61
|
end
|
64
62
|
end
|
@@ -319,7 +319,7 @@ module AdsCommon
|
|
319
319
|
def normalize_output(output_data, method_definition)
|
320
320
|
fields_list = method_definition[:output][:fields]
|
321
321
|
result = normalize_output_field(output_data, fields_list, :rval)
|
322
|
-
return result[:rval]
|
322
|
+
return result[:rval] || result
|
323
323
|
end
|
324
324
|
|
325
325
|
# Normalizes one field of a given data recursively.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-ads-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sergio Gomes
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-11-01 00:00:00 +04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|