google-adwords-api 0.4.1 → 0.4.2
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 +5 -0
- data/README +1 -1
- data/Rakefile +2 -2
- data/examples/v201109/oauth_report_download.rb +97 -0
- data/lib/adwords_api.rb +5 -5
- data/lib/adwords_api/api_config.rb +3 -30
- data/lib/adwords_api/client_login_header_handler.rb +17 -0
- data/lib/adwords_api/errors.rb +6 -0
- data/lib/adwords_api/extensions.rb +9 -6
- data/lib/adwords_api/report_utils.rb +28 -20
- data/test/adwords_api/test_api_config.rb +55 -0
- data/test/adwords_api/test_report_utils.rb +110 -0
- metadata +10 -10
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -29,7 +29,7 @@ which is installed automatically as a dependency.
|
|
29
29
|
The following gem libraries are required:
|
30
30
|
- savon v0.9.6
|
31
31
|
- httpclient v2.1.2 or greater
|
32
|
-
- google-ads-common v0.5.
|
32
|
+
- google-ads-common v0.5.4 or later.
|
33
33
|
|
34
34
|
|
35
35
|
== 2 - Using the client library:
|
data/Rakefile
CHANGED
@@ -48,7 +48,7 @@ spec = Gem::Specification.new do |s|
|
|
48
48
|
s.test_files = tests
|
49
49
|
s.has_rdoc = true
|
50
50
|
s.extra_rdoc_files = docs
|
51
|
-
s.add_dependency('google-ads-common', '~> 0.5.
|
51
|
+
s.add_dependency('google-ads-common', '~> 0.5.4')
|
52
52
|
s.add_dependency('savon', '= 0.9.6')
|
53
53
|
end
|
54
54
|
|
@@ -71,7 +71,7 @@ task :generate do
|
|
71
71
|
api_config = AdwordsApi::ApiConfig
|
72
72
|
versions = api_config.versions()
|
73
73
|
versions.each do |version|
|
74
|
-
code_path = "lib/%s/%s" % [api_config.
|
74
|
+
code_path = "lib/%s/%s" % [api_config.api_name.to_s.snakecase, version]
|
75
75
|
wsdls = AdwordsApi::ApiConfig.get_wsdls(version)
|
76
76
|
wsdls.each do |service_name, wsdl_url|
|
77
77
|
logger.info("Processing %s at [%s]..." % [service_name, wsdl_url])
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# This example gets and downloads an Ad Hoc report from a XML report definition
|
21
|
+
# using OAuth as authorization method.
|
22
|
+
|
23
|
+
require 'rubygems'
|
24
|
+
require 'adwords_api'
|
25
|
+
|
26
|
+
API_VERSION = :v201109
|
27
|
+
MAX_RETRIES = 3
|
28
|
+
|
29
|
+
def oauth_report_download()
|
30
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
31
|
+
# when called without parameters.
|
32
|
+
adwords = AdwordsApi::Api.new
|
33
|
+
|
34
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
35
|
+
# the configuration file or provide your own logger:
|
36
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
37
|
+
|
38
|
+
# Get report utilities for the version.
|
39
|
+
report_utils = adwords.report_utils(API_VERSION)
|
40
|
+
|
41
|
+
# File name to write report to. To retrieve the report as return value, use
|
42
|
+
# "download_report" method.
|
43
|
+
file_name = 'INSERT_OUTPUT_FILE_NAME_HERE'
|
44
|
+
|
45
|
+
# Define report definition. You can also pass your own XML text as a string.
|
46
|
+
report_definition = {
|
47
|
+
:selector => {
|
48
|
+
:fields => ['CampaignId', 'Id', 'Impressions', 'Clicks', 'Cost'],
|
49
|
+
# Predicates are optional.
|
50
|
+
:predicates => {
|
51
|
+
:field => 'Status',
|
52
|
+
:operator => 'IN',
|
53
|
+
:values => ['ENABLED', 'PAUSED']
|
54
|
+
}
|
55
|
+
},
|
56
|
+
:report_name => 'Custom ADGROUP_PERFORMANCE_REPORT',
|
57
|
+
:report_type => 'ADGROUP_PERFORMANCE_REPORT',
|
58
|
+
:download_format => 'CSV',
|
59
|
+
:date_range_type => 'LAST_7_DAYS',
|
60
|
+
# Enable to get rows with zero impressions.
|
61
|
+
:include_zero_impressions => false
|
62
|
+
}
|
63
|
+
|
64
|
+
retry_count = 0
|
65
|
+
|
66
|
+
begin
|
67
|
+
# Download report, using "download_report_as_file" utility method.
|
68
|
+
report_utils.download_report_as_file(report_definition, file_name)
|
69
|
+
puts "Report was downloaded to '%s'." % file_name
|
70
|
+
rescue AdsCommon::Errors::OAuthVerificationRequired => e
|
71
|
+
if retry_count < MAX_RETRIES
|
72
|
+
puts "Hit Auth error, please navigate to URL:\n\t%s" % e.oauth_url
|
73
|
+
print 'log in and type the verification code: '
|
74
|
+
verification_code = gets.chomp
|
75
|
+
adwords.credential_handler.set_credential(
|
76
|
+
:oauth_verification_code, verification_code)
|
77
|
+
retry_count += 1
|
78
|
+
retry
|
79
|
+
else
|
80
|
+
raise AdsCommon::Errors::AuthError, 'Failed to authenticate.'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if __FILE__ == $0
|
86
|
+
begin
|
87
|
+
oauth_report_download()
|
88
|
+
|
89
|
+
# HTTP errors.
|
90
|
+
rescue AdsCommon::Errors::HttpError => e
|
91
|
+
puts "HTTP Error: %s" % e
|
92
|
+
|
93
|
+
# API errors.
|
94
|
+
rescue AdwordsApi::Errors::ReportError => e
|
95
|
+
puts "Reporting Error: %s" % e.message
|
96
|
+
end
|
97
|
+
end
|
data/lib/adwords_api.rb
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
#
|
21
21
|
# Contains the main classes for the client library.
|
22
22
|
|
23
|
-
gem 'google-ads-common', '~>0.5.
|
23
|
+
gem 'google-ads-common', '~>0.5.4'
|
24
24
|
|
25
25
|
require 'ads_common/api'
|
26
26
|
require 'ads_common/auth/oauth_handler'
|
@@ -84,7 +84,7 @@ module AdwordsApi
|
|
84
84
|
end
|
85
85
|
handlers = header_list.map do |header|
|
86
86
|
AdsCommon::SavonHeaders::SimpleHeaderHandler.new(
|
87
|
-
@credential_handler, auth_handler, header,
|
87
|
+
@credential_handler, auth_handler, header, namespace, version)
|
88
88
|
end
|
89
89
|
else
|
90
90
|
handlers = case auth_method
|
@@ -226,8 +226,6 @@ module AdwordsApi
|
|
226
226
|
return AdwordsApi::ReportUtils.new(self, version)
|
227
227
|
end
|
228
228
|
|
229
|
-
private
|
230
|
-
|
231
229
|
# Overrides AdsCommon::Api.get_auth_handler to allow version-specific
|
232
230
|
# handlers.
|
233
231
|
def get_auth_handler(environment, version = nil)
|
@@ -237,6 +235,8 @@ module AdwordsApi
|
|
237
235
|
return @auth_handler
|
238
236
|
end
|
239
237
|
|
238
|
+
private
|
239
|
+
|
240
240
|
# Creates an appropriate authentication handler for each service (reuses the
|
241
241
|
# ClientLogin one to avoid generating multiple tokens unnecessarily).
|
242
242
|
#
|
@@ -249,7 +249,7 @@ module AdwordsApi
|
|
249
249
|
#
|
250
250
|
def create_auth_handler(environment, version = nil)
|
251
251
|
return (version == :v13) ?
|
252
|
-
AdwordsApi::V13LoginHandler.new : super(environment)
|
252
|
+
AdwordsApi::V13LoginHandler.new(@config) : super(environment)
|
253
253
|
end
|
254
254
|
|
255
255
|
# Executes block with a temporary flag set to a given value. Returns block
|
@@ -41,8 +41,7 @@ module AdwordsApi
|
|
41
41
|
|
42
42
|
# Set other constants
|
43
43
|
API_NAME = 'AdwordsApi'
|
44
|
-
|
45
|
-
CLIENT_LIB_VERSION = '0.4.1'
|
44
|
+
CLIENT_LIB_VERSION = '0.4.2'
|
46
45
|
DEFAULT_CONFIG_FILENAME = 'adwords_api.yml'
|
47
46
|
|
48
47
|
# Configure the services available to each version
|
@@ -265,10 +264,6 @@ module AdwordsApi
|
|
265
264
|
API_NAME
|
266
265
|
end
|
267
266
|
|
268
|
-
def self.api_path
|
269
|
-
API_PATH
|
270
|
-
end
|
271
|
-
|
272
267
|
def self.service_config
|
273
268
|
@@service_config
|
274
269
|
end
|
@@ -293,32 +288,10 @@ module AdwordsApi
|
|
293
288
|
@@headers_config
|
294
289
|
end
|
295
290
|
|
296
|
-
# Returns the full interface class name for a given service. Overriding this
|
297
|
-
# method from ads_common to fix odd behaviour with v13 class names.
|
298
|
-
#
|
299
|
-
# Args:
|
300
|
-
# - version: the API version (as an integer)
|
301
|
-
# - service: the service name (as a string)
|
302
|
-
#
|
303
|
-
# Returns:
|
304
|
-
# The full interface class name for the given service (as a string)
|
305
|
-
#
|
306
|
-
def self.interface_name(version, service)
|
307
|
-
service_str = service.to_s
|
308
|
-
service_str = service_str.sub(/Service$/, '') if version == :v13
|
309
|
-
return module_name(version, service) + "::" + service_str
|
310
|
-
end
|
311
|
-
|
312
|
-
def self.do_require(version, service)
|
313
|
-
service_name = service.to_s.snakecase()
|
314
|
-
filename = "%s/%s/%s" % [api_path, version, service_name]
|
315
|
-
require filename
|
316
|
-
end
|
317
|
-
|
318
291
|
# Get the download URL for reports.
|
319
292
|
#
|
320
293
|
# Args:
|
321
|
-
# - environment: the service environment to be used
|
294
|
+
# - environment: the service environment to be used
|
322
295
|
# - version: the API version (as a symbol)
|
323
296
|
#
|
324
297
|
# Returns:
|
@@ -335,7 +308,7 @@ module AdwordsApi
|
|
335
308
|
# Get the download URL for Ad Hoc reports.
|
336
309
|
#
|
337
310
|
# Args:
|
338
|
-
# - environment: the service environment to be used
|
311
|
+
# - environment: the service environment to be used
|
339
312
|
# - version: the API version (as a symbol)
|
340
313
|
#
|
341
314
|
# Returns:
|
@@ -60,6 +60,23 @@ module AdwordsApi
|
|
60
60
|
end
|
61
61
|
|
62
62
|
private
|
63
|
+
# Generates SOAP request header with login credentials and namespace
|
64
|
+
# definition.
|
65
|
+
#
|
66
|
+
# Args:
|
67
|
+
# - None
|
68
|
+
#
|
69
|
+
# Returns:
|
70
|
+
# - Hash containing a header with filled in credentials
|
71
|
+
#
|
72
|
+
def generate_request_header()
|
73
|
+
headers = @auth_handler.headers(@credential_handler.credentials(@version))
|
74
|
+
return headers.inject({}) do |request_header, (header, value)|
|
75
|
+
request_header[prepend_namespace(header)] = value
|
76
|
+
request_header
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
63
80
|
# Skips namespace prefixes for all elements except top level. Use default
|
64
81
|
# (inherited) prefixing for the top level key.
|
65
82
|
#
|
data/lib/adwords_api/errors.rb
CHANGED
@@ -66,6 +66,12 @@ module AdwordsApi
|
|
66
66
|
|
67
67
|
# Error for server-side report error.
|
68
68
|
class ReportError < AdsCommon::Errors::ApiException
|
69
|
+
attr_reader :http_code
|
70
|
+
|
71
|
+
def initialize(http_code, message)
|
72
|
+
super(message)
|
73
|
+
@http_code = http_code
|
74
|
+
end
|
69
75
|
end
|
70
76
|
end
|
71
77
|
end
|
@@ -20,8 +20,10 @@
|
|
20
20
|
# Contains extensions to the API, that is, service helper methods provided in
|
21
21
|
# client-side by the client library.
|
22
22
|
|
23
|
-
require 'rexml/document'
|
24
23
|
require 'csv'
|
24
|
+
require 'httpi/request'
|
25
|
+
require 'rexml/document'
|
26
|
+
|
25
27
|
require 'ads_common/http'
|
26
28
|
|
27
29
|
module AdwordsApi
|
@@ -223,18 +225,19 @@ module AdwordsApi
|
|
223
225
|
|
224
226
|
# Gets a report response for a given parameters.
|
225
227
|
def self.get_report_response(wrapper, url)
|
226
|
-
headers = get_report_request_headers(wrapper)
|
228
|
+
headers = get_report_request_headers(wrapper, url)
|
227
229
|
report_response = AdsCommon::Http.get_response(url, wrapper.api.config,
|
228
230
|
headers)
|
229
231
|
return report_response
|
230
232
|
end
|
231
233
|
|
232
|
-
def self.get_report_request_headers(wrapper)
|
234
|
+
def self.get_report_request_headers(wrapper, url)
|
233
235
|
headers = {}
|
234
236
|
credentials = wrapper.api.credential_handler.credentials
|
235
|
-
auth_handler = wrapper.api.
|
236
|
-
|
237
|
-
|
237
|
+
auth_handler = wrapper.api.get_auth_handler(
|
238
|
+
wrapper.api.config.read('service.environment'), wrapper.version)
|
239
|
+
headers['Authorization'] = auth_handler.auth_string(credentials,
|
240
|
+
HTTPI::Request.new(url))
|
238
241
|
if credentials[:clientCustomerId]
|
239
242
|
headers['clientCustomerId'] = credentials[:clientCustomerId]
|
240
243
|
elsif credentials[:clientEmail]
|
@@ -20,6 +20,7 @@
|
|
20
20
|
# Contains utility methods specific to reporting.
|
21
21
|
|
22
22
|
require 'gyoku'
|
23
|
+
require 'httpi/request'
|
23
24
|
|
24
25
|
require 'adwords_api/errors'
|
25
26
|
|
@@ -89,10 +90,10 @@ module AdwordsApi
|
|
89
90
|
# Send POST request for a report and returns Response object.
|
90
91
|
def get_report_response(report_definition)
|
91
92
|
definition_text = get_report_definition_text(report_definition)
|
92
|
-
data = {
|
93
|
+
data = {'__rdxml' => definition_text}
|
93
94
|
url = @api.api_config.adhoc_report_download_url(
|
94
95
|
@api.config.read('service.environment'), @version)
|
95
|
-
headers = get_report_request_headers()
|
96
|
+
headers = get_report_request_headers(url)
|
96
97
|
response = AdsCommon::Http.post_response(url, data, @api.config, headers)
|
97
98
|
check_for_errors(response)
|
98
99
|
return response
|
@@ -102,8 +103,8 @@ module AdwordsApi
|
|
102
103
|
# and Hash (renders XML).
|
103
104
|
def get_report_definition_text(report_definition)
|
104
105
|
return case report_definition
|
105
|
-
when String
|
106
|
-
when Hash
|
106
|
+
when String then report_definition
|
107
|
+
when Hash then report_definition_to_xml(report_definition)
|
107
108
|
else
|
108
109
|
raise AdwordsApi::Errors::InvalidReportDefinitionError,
|
109
110
|
"Unknown object for report definition: %s" %
|
@@ -112,13 +113,17 @@ module AdwordsApi
|
|
112
113
|
end
|
113
114
|
|
114
115
|
# Prepares headers for report request.
|
115
|
-
def get_report_request_headers()
|
116
|
+
def get_report_request_headers(url)
|
116
117
|
credentials = @api.credential_handler.credentials
|
117
|
-
|
118
|
+
auth_handler = @api.get_auth_handler(
|
119
|
+
@api.config.read('service.environment'), @version)
|
120
|
+
auth_string = auth_handler.auth_string(
|
121
|
+
credentials, HTTPI::Request.new(url))
|
118
122
|
headers = {
|
119
|
-
'Authorization' =>
|
123
|
+
'Authorization' => auth_string,
|
120
124
|
'ClientCustomerId' => credentials[:clientCustomerId],
|
121
|
-
'Content-Type' => 'multipart/form-data'
|
125
|
+
'Content-Type' => 'multipart/form-data',
|
126
|
+
'developerToken' => credentials[:developerToken]
|
122
127
|
}
|
123
128
|
return headers
|
124
129
|
end
|
@@ -131,20 +136,23 @@ module AdwordsApi
|
|
131
136
|
# Checks downloaded data for error signature. Raises ReportError if it
|
132
137
|
# detects an error.
|
133
138
|
def check_for_errors(response)
|
134
|
-
# Check for error code.
|
135
|
-
unless response.code == 200
|
136
|
-
raise AdwordsApi::Errors::ReportError,
|
137
|
-
"Report download error occured, http code: %d" % response.code
|
138
|
-
end
|
139
139
|
# Check for error in body.
|
140
140
|
report_body = response.body
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
141
|
+
if report_body
|
142
|
+
error_message_regex = '^!!!(-?\d+)\|\|\|(-?\d+)\|\|\|(.*)\?\?\?'
|
143
|
+
data = report_body.slice(0, 1024)
|
144
|
+
matches = data.match(error_message_regex)
|
145
|
+
if matches
|
146
|
+
message = (matches[3].nil?) ? data : matches[3]
|
147
|
+
raise AdwordsApi::Errors::ReportError.new(response.code,
|
148
|
+
"Report download error occured: %s" % message)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
# Check for error code.
|
152
|
+
unless response.code == 200
|
153
|
+
raise AdwordsApi::Errors::ReportError.new(response.code,
|
154
|
+
"Report download error occured, http code: %d, body: %s" %
|
155
|
+
[response.code, response.body])
|
148
156
|
end
|
149
157
|
return nil
|
150
158
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# Tests the general API features.
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'test/unit'
|
24
|
+
require 'adwords_api'
|
25
|
+
|
26
|
+
class TestApiConfig < Test::Unit::TestCase
|
27
|
+
# Initialize tests.
|
28
|
+
def setup
|
29
|
+
@config = AdwordsApi::ApiConfig
|
30
|
+
end
|
31
|
+
|
32
|
+
# Test correct require path.
|
33
|
+
def test_do_require
|
34
|
+
name1 = @config.do_require(:v201109, :InfoService)
|
35
|
+
assert_equal('adwords_api/v201109/info_service', name1)
|
36
|
+
name2 = @config.do_require(:v13, :AccountService)
|
37
|
+
assert_equal('adwords_api/v13/account_service', name2)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test correct module name.
|
41
|
+
def test_module_name
|
42
|
+
name1 = @config.module_name(:v201109, :InfoService)
|
43
|
+
assert_equal('AdwordsApi::V201109::InfoService', name1)
|
44
|
+
name2 = @config.module_name(:v13, :AccountService)
|
45
|
+
assert_equal('AdwordsApi::V13::AccountService', name2)
|
46
|
+
end
|
47
|
+
|
48
|
+
# Test correct interface name.
|
49
|
+
def test_interface_name
|
50
|
+
name1 = @config.interface_name(:v201109, :InfoService)
|
51
|
+
assert_equal('AdwordsApi::V201109::InfoService::InfoService', name1)
|
52
|
+
name2 = @config.interface_name(:v13, :AccountService)
|
53
|
+
assert_equal('AdwordsApi::V13::AccountService::AccountService', name2)
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# Tests report utils.
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'test/unit'
|
24
|
+
require 'adwords_api'
|
25
|
+
|
26
|
+
API_VERSION = :v201109
|
27
|
+
|
28
|
+
# Overriding default access levels to public for tests.
|
29
|
+
module AdwordsApi
|
30
|
+
class ReportUtils
|
31
|
+
public :check_for_errors
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Stub class for HTTP response.
|
36
|
+
class ResponseStub
|
37
|
+
attr_reader :code
|
38
|
+
attr_reader :body
|
39
|
+
|
40
|
+
def initialize(code, body)
|
41
|
+
@code, @body = code, body
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Typical reply types.
|
46
|
+
REPLY_TYPES = [
|
47
|
+
{:reply => '!!!2|||-1|||Improperly formatted report request???',
|
48
|
+
:message => 'Improperly formatted report request'},
|
49
|
+
{:reply => "!!!2|||-1|||ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT @ ; trigger:'bCampaignId'???",
|
50
|
+
:message => "ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT @ ; trigger:'bCampaignId'"}
|
51
|
+
]
|
52
|
+
|
53
|
+
VALID_REPORT = '"Custom ADGROUP_PERFORMANCE_REPORT (Oct 20, 2011-Oct 26, 2011)"\nCampaign ID,Ad group ID,Impressions,Clicks,Cost\nTotal, --,0,0,0.00'
|
54
|
+
|
55
|
+
class TestReportUtils < Test::Unit::TestCase
|
56
|
+
# Initialize tests.
|
57
|
+
def setup
|
58
|
+
@api = AdwordsApi::Api.new
|
59
|
+
@report_utils = @api.report_utils(API_VERSION)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Testing HTTP code 400.
|
63
|
+
def test_check_for_errors_400
|
64
|
+
REPLY_TYPES.each do |reply_type|
|
65
|
+
begin
|
66
|
+
response = ResponseStub.new(400, reply_type[:reply])
|
67
|
+
@report_utils.check_for_errors(response)
|
68
|
+
assert(false, 'No exception thrown for code 400')
|
69
|
+
rescue AdwordsApi::Errors::ReportError => e
|
70
|
+
assert_equal(400, e.http_code)
|
71
|
+
assert(e.message.include?(reply_type[:message]))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Testing HTTP code 500.
|
77
|
+
def test_check_for_errors_500
|
78
|
+
REPLY_TYPES.each do |reply_type|
|
79
|
+
begin
|
80
|
+
response = ResponseStub.new(500, nil)
|
81
|
+
@report_utils.check_for_errors(response)
|
82
|
+
assert(false, 'No exception thrown for code 500')
|
83
|
+
rescue AdwordsApi::Errors::ReportError => e
|
84
|
+
assert_equal(500, e.http_code)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Testing HTTP code 200 with success.
|
90
|
+
def test_check_for_errors_200_success
|
91
|
+
response = ResponseStub.new(200, VALID_REPORT)
|
92
|
+
assert_nothing_raised do
|
93
|
+
@report_utils.check_for_errors(response)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Testing HTTP code 200 with failure.
|
98
|
+
def test_check_for_errors_200_success
|
99
|
+
REPLY_TYPES.each do |reply_type|
|
100
|
+
begin
|
101
|
+
response = ResponseStub.new(200, reply_type[:reply])
|
102
|
+
@report_utils.check_for_errors(response)
|
103
|
+
assert(false, 'No exception thrown for code 200')
|
104
|
+
rescue AdwordsApi::Errors::ReportError => e
|
105
|
+
assert_equal(200, e.http_code)
|
106
|
+
assert(e.message.include?(reply_type[:message]))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-adwords-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 13
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
8
|
+
- 2
|
9
|
+
version: 0.4.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Danial Klimkin
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-11-01 00:00:00 +04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +25,11 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
- 5
|
33
|
-
-
|
34
|
-
version: 0.5.
|
31
|
+
- 4
|
32
|
+
version: 0.5.4
|
35
33
|
type: :runtime
|
36
34
|
version_requirements: *id001
|
37
35
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +40,6 @@ dependencies:
|
|
42
40
|
requirements:
|
43
41
|
- - "="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 55
|
46
43
|
segments:
|
47
44
|
- 0
|
48
45
|
- 9
|
@@ -517,6 +514,7 @@ files:
|
|
517
514
|
- examples/v201109/get_geo_location_info.rb
|
518
515
|
- examples/v201109/get_all_languages.rb
|
519
516
|
- examples/v201109/delete_ad_group.rb
|
517
|
+
- examples/v201109/oauth_report_download.rb
|
520
518
|
- examples/v201109/download_report.rb
|
521
519
|
- examples/v201109/get_all_images.rb
|
522
520
|
- examples/v201109/check_campaigns.rb
|
@@ -569,6 +567,8 @@ files:
|
|
569
567
|
- examples/v201109/get_total_usage_units_per_month.rb
|
570
568
|
- Rakefile
|
571
569
|
- test/bugs/test_issue_00000031.rb
|
570
|
+
- test/adwords_api/test_api_config.rb
|
571
|
+
- test/adwords_api/test_report_utils.rb
|
572
572
|
- README
|
573
573
|
- COPYING
|
574
574
|
- ChangeLog
|
@@ -586,7 +586,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
586
586
|
requirements:
|
587
587
|
- - ">="
|
588
588
|
- !ruby/object:Gem::Version
|
589
|
-
hash: 3
|
590
589
|
segments:
|
591
590
|
- 0
|
592
591
|
version: "0"
|
@@ -595,7 +594,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
595
594
|
requirements:
|
596
595
|
- - ">="
|
597
596
|
- !ruby/object:Gem::Version
|
598
|
-
hash: 3
|
599
597
|
segments:
|
600
598
|
- 0
|
601
599
|
version: "0"
|
@@ -608,3 +606,5 @@ specification_version: 3
|
|
608
606
|
summary: Ruby Client libraries for AdWords API
|
609
607
|
test_files:
|
610
608
|
- test/bugs/test_issue_00000031.rb
|
609
|
+
- test/adwords_api/test_api_config.rb
|
610
|
+
- test/adwords_api/test_report_utils.rb
|