google-adwords-api 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -0
- data/README +4 -4
- data/examples/v201109_1/account_management/create_account.rb +80 -0
- data/examples/v201109_1/account_management/get_account_alerts.rb +111 -0
- data/examples/v201109_1/account_management/get_account_changes.rb +137 -0
- data/examples/v201109_1/account_management/get_account_hierarchy.rb +93 -0
- data/examples/v201109_1/account_management/get_client_customer_id.rb +85 -0
- data/examples/v201109_1/account_management/get_client_unit_usage.rb +87 -0
- data/examples/v201109_1/basic_operations/add_ad_groups.rb +111 -0
- data/examples/v201109_1/basic_operations/add_campaigns.rb +140 -0
- data/examples/v201109_1/basic_operations/add_keywords.rb +108 -0
- data/examples/v201109_1/basic_operations/add_text_ads.rb +105 -0
- data/examples/v201109_1/basic_operations/delete_ad.rb +85 -0
- data/examples/v201109_1/basic_operations/delete_ad_group.rb +102 -0
- data/examples/v201109_1/basic_operations/delete_campaign.rb +103 -0
- data/examples/v201109_1/basic_operations/delete_keyword.rb +90 -0
- data/examples/v201109_1/basic_operations/get_ad_groups.rb +98 -0
- data/examples/v201109_1/basic_operations/get_campaigns.rb +93 -0
- data/examples/v201109_1/basic_operations/get_keywords.rb +104 -0
- data/examples/v201109_1/basic_operations/get_text_ads.rb +106 -0
- data/examples/v201109_1/basic_operations/pause_ad.rb +84 -0
- data/examples/v201109_1/basic_operations/update_ad_group.rb +81 -0
- data/examples/v201109_1/basic_operations/update_campaign.rb +84 -0
- data/examples/v201109_1/basic_operations/update_keyword.rb +99 -0
- data/examples/v201109_1/campaign_management/add_experiment.rb +158 -0
- data/examples/v201109_1/campaign_management/add_keywords_in_bulk.rb +150 -0
- data/examples/v201109_1/campaign_management/add_location_extension.rb +117 -0
- data/examples/v201109_1/campaign_management/add_location_extension_override.rb +83 -0
- data/examples/v201109_1/campaign_management/get_all_disapproved_ads.rb +93 -0
- data/examples/v201109_1/campaign_management/promote_experiment.rb +77 -0
- data/examples/v201109_1/campaign_management/set_ad_parameters.rb +114 -0
- data/examples/v201109_1/campaign_management/validate_text_ad.rb +106 -0
- data/examples/v201109_1/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201109_1/error_handling/handle_partial_failures.rb +126 -0
- data/examples/v201109_1/error_handling/handle_policy_violation_error.rb +137 -0
- data/examples/v201109_1/error_handling/handle_two_factor_authorization_error.rb +87 -0
- data/examples/v201109_1/misc/get_all_images_and_videos.rb +101 -0
- data/examples/v201109_1/misc/upload_image.rb +90 -0
- data/examples/v201109_1/misc/use_oauth.rb +97 -0
- data/examples/v201109_1/optimization/estimate_keyword_traffic.rb +129 -0
- data/examples/v201109_1/optimization/get_keyword_bid_simulations.rb +92 -0
- data/examples/v201109_1/optimization/get_keyword_ideas.rb +113 -0
- data/examples/v201109_1/optimization/get_placement_ideas.rb +106 -0
- data/examples/v201109_1/remarketing/add_audience.rb +115 -0
- data/examples/v201109_1/remarketing/add_conversion_tracker.rb +97 -0
- data/examples/v201109_1/reporting/download_criteria_report.rb +79 -0
- data/examples/v201109_1/reporting/get_campaign_stats.rb +105 -0
- data/examples/v201109_1/reporting/get_defined_reports.rb +75 -0
- data/examples/{v201109/reporting/download_defined_report.rb → v201109_1/reporting/get_report_fields.rb} +15 -11
- data/examples/v201109_1/reporting/parallel_report_download.rb +159 -0
- data/examples/v201109_1/targeting/add_campaign_targeting_criteria.rb +118 -0
- data/examples/v201109_1/targeting/get_campaign_targeting_criteria.rb +102 -0
- data/examples/v201109_1/targeting/get_targetable_languages_and_carriers.rb +86 -0
- data/examples/v201109_1/targeting/lookup_location.rb +103 -0
- data/lib/adwords_api.rb +15 -88
- data/lib/adwords_api/api_config.rb +75 -33
- data/lib/adwords_api/client_login_header_handler.rb +17 -26
- data/lib/adwords_api/credential_handler.rb +29 -65
- data/lib/adwords_api/report_header_handler.rb +65 -0
- data/lib/adwords_api/report_utils.rb +12 -36
- data/lib/adwords_api/v201109/ad_extension_override_service.rb +3 -3
- data/lib/adwords_api/v201109/ad_extension_override_service_registry.rb +2 -2
- data/lib/adwords_api/v201109/ad_group_ad_service.rb +3 -3
- data/lib/adwords_api/v201109/ad_group_ad_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/ad_group_criterion_service.rb +3 -3
- data/lib/adwords_api/v201109/ad_group_criterion_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/ad_group_service.rb +3 -3
- data/lib/adwords_api/v201109/ad_group_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/ad_param_service.rb +3 -3
- data/lib/adwords_api/v201109/ad_param_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/alert_service.rb +3 -3
- data/lib/adwords_api/v201109/alert_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/budget_order_service.rb +42 -0
- data/lib/adwords_api/v201109/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201109/bulk_mutate_job_service.rb +3 -3
- data/lib/adwords_api/v201109/bulk_mutate_job_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/campaign_ad_extension_service.rb +3 -3
- data/lib/adwords_api/v201109/campaign_ad_extension_service_registry.rb +2 -2
- data/lib/adwords_api/v201109/campaign_criterion_service.rb +3 -3
- data/lib/adwords_api/v201109/campaign_criterion_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/campaign_service.rb +3 -3
- data/lib/adwords_api/v201109/campaign_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/campaign_target_service.rb +3 -3
- data/lib/adwords_api/v201109/campaign_target_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/constant_data_service.rb +3 -3
- data/lib/adwords_api/v201109/constant_data_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/conversion_tracker_service.rb +3 -3
- data/lib/adwords_api/v201109/conversion_tracker_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/create_account_service.rb +3 -3
- data/lib/adwords_api/v201109/create_account_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/customer_sync_service.rb +3 -3
- data/lib/adwords_api/v201109/customer_sync_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/data_service.rb +3 -3
- data/lib/adwords_api/v201109/data_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/experiment_service.rb +3 -3
- data/lib/adwords_api/v201109/experiment_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/geo_location_service.rb +3 -3
- data/lib/adwords_api/v201109/geo_location_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/info_service.rb +3 -3
- data/lib/adwords_api/v201109/info_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/location_criterion_service.rb +3 -3
- data/lib/adwords_api/v201109/location_criterion_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/media_service.rb +3 -3
- data/lib/adwords_api/v201109/media_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/mutate_job_service.rb +3 -3
- data/lib/adwords_api/v201109/mutate_job_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/report_definition_service.rb +3 -12
- data/lib/adwords_api/v201109/report_definition_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/serviced_account_service.rb +3 -3
- data/lib/adwords_api/v201109/serviced_account_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/targeting_idea_service.rb +3 -3
- data/lib/adwords_api/v201109/targeting_idea_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/traffic_estimator_service.rb +3 -3
- data/lib/adwords_api/v201109/traffic_estimator_service_registry.rb +1 -1
- data/lib/adwords_api/v201109/user_list_service.rb +3 -3
- data/lib/adwords_api/v201109/user_list_service_registry.rb +1 -1
- data/lib/adwords_api/v201109_1/ad_extension_override_service.rb +38 -0
- data/lib/adwords_api/v201109_1/ad_extension_override_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/ad_group_ad_service.rb +38 -0
- data/lib/adwords_api/v201109_1/ad_group_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/ad_group_criterion_service.rb +38 -0
- data/lib/adwords_api/v201109_1/ad_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/ad_group_service.rb +38 -0
- data/lib/adwords_api/v201109_1/ad_group_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/ad_param_service.rb +38 -0
- data/lib/adwords_api/v201109_1/ad_param_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/alert_service.rb +34 -0
- data/lib/adwords_api/v201109_1/alert_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/budget_order_service.rb +42 -0
- data/lib/adwords_api/v201109_1/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/bulk_mutate_job_service.rb +38 -0
- data/lib/adwords_api/v201109_1/bulk_mutate_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/campaign_ad_extension_service.rb +38 -0
- data/lib/adwords_api/v201109_1/campaign_ad_extension_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/campaign_criterion_service.rb +38 -0
- data/lib/adwords_api/v201109_1/campaign_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/campaign_service.rb +38 -0
- data/lib/adwords_api/v201109_1/campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/campaign_target_service.rb +38 -0
- data/lib/adwords_api/v201109_1/campaign_target_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/constant_data_service.rb +38 -0
- data/lib/adwords_api/v201109_1/constant_data_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/conversion_tracker_service.rb +38 -0
- data/lib/adwords_api/v201109_1/conversion_tracker_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/create_account_service.rb +34 -0
- data/lib/adwords_api/v201109_1/create_account_service_registry.rb +47 -0
- data/lib/adwords_api/v201109_1/customer_sync_service.rb +34 -0
- data/lib/adwords_api/v201109_1/customer_sync_service_registry.rb +47 -0
- data/lib/adwords_api/v201109_1/data_service.rb +38 -0
- data/lib/adwords_api/v201109_1/data_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/experiment_service.rb +38 -0
- data/lib/adwords_api/v201109_1/experiment_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/geo_location_service.rb +34 -0
- data/lib/adwords_api/v201109_1/geo_location_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/info_service.rb +34 -0
- data/lib/adwords_api/v201109_1/info_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/location_criterion_service.rb +34 -0
- data/lib/adwords_api/v201109_1/location_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/media_service.rb +38 -0
- data/lib/adwords_api/v201109_1/media_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/mutate_job_service.rb +42 -0
- data/lib/adwords_api/v201109_1/mutate_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/report_definition_service.rb +38 -0
- data/lib/adwords_api/v201109_1/report_definition_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/serviced_account_service.rb +34 -0
- data/lib/adwords_api/v201109_1/serviced_account_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/targeting_idea_service.rb +38 -0
- data/lib/adwords_api/v201109_1/targeting_idea_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/traffic_estimator_service.rb +34 -0
- data/lib/adwords_api/v201109_1/traffic_estimator_service_registry.rb +46 -0
- data/lib/adwords_api/v201109_1/user_list_service.rb +38 -0
- data/lib/adwords_api/v201109_1/user_list_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_api_config.rb +24 -8
- data/test/adwords_api/test_credential_handler.rb +32 -52
- data/test/coverage.rb +38 -0
- data/test/examples/v201109/test_reporting.rb +0 -12
- data/test/examples/v201109_1/test_account_management.rb +60 -0
- data/test/examples/v201109_1/test_basic_operations.rb +172 -0
- data/test/examples/v201109_1/test_campaign_management.rb +116 -0
- data/test/examples/v201109_1/test_error_handling.rb +63 -0
- data/{lib/adwords_api/v13_login_handler.rb → test/examples/v201109_1/test_misc.rb} +24 -10
- data/test/examples/v201109_1/test_optimization.rb +63 -0
- data/test/{suite_exampletests.rb → examples/v201109_1/test_remarketing.rb} +16 -8
- data/test/examples/v201109_1/test_reporting.rb +77 -0
- data/test/examples/v201109_1/test_targeting.rb +60 -0
- data/test/examples/v201109_1/utils.rb +239 -0
- data/test/suite_exampletests_v201109.rb +37 -0
- data/test/suite_exampletests_v201109_1.rb +37 -0
- data/test/suite_unittests.rb +7 -5
- metadata +136 -11
- data/lib/adwords_api/extensions.rb +0 -269
@@ -1,269 +0,0 @@
|
|
1
|
-
# Encoding: utf-8
|
2
|
-
#
|
3
|
-
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
4
|
-
#
|
5
|
-
# Copyright:: Copyright 2010, 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
|
-
# Contains extensions to the API, that is, service helper methods provided in
|
21
|
-
# client-side by the client library.
|
22
|
-
|
23
|
-
require 'csv'
|
24
|
-
require 'httpi/request'
|
25
|
-
require 'rexml/document'
|
26
|
-
|
27
|
-
require 'ads_common/http'
|
28
|
-
|
29
|
-
module AdwordsApi
|
30
|
-
|
31
|
-
module Extensions
|
32
|
-
|
33
|
-
# Maintains a list of all extension methods, indexed by version and service.
|
34
|
-
# Using camelCase to match API method names.
|
35
|
-
@@extensions = {
|
36
|
-
[:v13, :ReportService] => [:download_xml_report, :download_csv_report],
|
37
|
-
[:v201003, :ReportDefinitionService] => [:download_report,
|
38
|
-
:download_report_as_file],
|
39
|
-
[:v201008, :ReportDefinitionService] => [:download_report,
|
40
|
-
:download_report_as_file],
|
41
|
-
[:v201101, :ReportDefinitionService] => [:download_report,
|
42
|
-
:download_report_as_file],
|
43
|
-
[:v201109, :ReportDefinitionService] => [:download_report,
|
44
|
-
:download_report_as_file]
|
45
|
-
}
|
46
|
-
|
47
|
-
# Defines the parameter list for every extension method.
|
48
|
-
@@methods = {
|
49
|
-
:download_xml_report => [:job_id],
|
50
|
-
:download_csv_report => [:job_id],
|
51
|
-
:download_report => [:report_definition_id],
|
52
|
-
:download_report_as_file => [:report_definition_id, :path]
|
53
|
-
}
|
54
|
-
|
55
|
-
# Return list of all extension methods, indexed by version and service.
|
56
|
-
def self.extensions
|
57
|
-
return @@extensions
|
58
|
-
end
|
59
|
-
|
60
|
-
# Return the parameter list for every extension method.
|
61
|
-
def self.methods
|
62
|
-
return @@methods
|
63
|
-
end
|
64
|
-
|
65
|
-
#########################################################################
|
66
|
-
# NOTE: The following extension methods shouldn't be used directly; they
|
67
|
-
# should instead be used from the services wrappers they get mapped to.
|
68
|
-
# For example, you should use ReportServiceWrapper::downloadXmlReport
|
69
|
-
# instead of Extensions::downloadXmlReport.
|
70
|
-
#########################################################################
|
71
|
-
|
72
|
-
# <i>Extension method</i> -- Download and return report data in XML format.
|
73
|
-
#
|
74
|
-
# *Warning*: this method is blocking for the calling thread.
|
75
|
-
#
|
76
|
-
# Args:
|
77
|
-
# - wrapper: the service wrapper object for any API methods that need to be
|
78
|
-
# called
|
79
|
-
# - job_id: the job id for the report to be downloaded
|
80
|
-
#
|
81
|
-
# Returns:
|
82
|
-
# The xml for the report (as a string)
|
83
|
-
#
|
84
|
-
def self.download_xml_report(wrapper, args)
|
85
|
-
job_id = args.first
|
86
|
-
sleep_interval = 30
|
87
|
-
|
88
|
-
status_field = :get_report_job_status_return
|
89
|
-
download_field = :get_report_download_url_return
|
90
|
-
|
91
|
-
# Repeatedly check the report status until it is finished.
|
92
|
-
# 'Pending' and 'InProgress' statuses indicate the job is still being run.
|
93
|
-
status = wrapper.get_report_job_status(job_id)[status_field]
|
94
|
-
while status != 'Completed' && status != 'Failed'
|
95
|
-
sleep(sleep_interval)
|
96
|
-
status = wrapper.get_report_job_status(job_id)[status_field]
|
97
|
-
end
|
98
|
-
|
99
|
-
if status == 'Completed'
|
100
|
-
report_url = wrapper.get_report_download_url(job_id)[download_field]
|
101
|
-
|
102
|
-
# Download the report and return its contents. The report is an XML
|
103
|
-
# document; the actual element names vary depending on the type of
|
104
|
-
# report run and columns requested.
|
105
|
-
begin
|
106
|
-
return AdsCommon::Http.get(report_url, wrapper.api.config)
|
107
|
-
rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
|
108
|
-
# This exception indicates a connection-level error.
|
109
|
-
# In general, it is likely to be transitory.
|
110
|
-
raise AdsCommon::Errors::HttpError, e.message, e.backtrace
|
111
|
-
end
|
112
|
-
else
|
113
|
-
# Reports that pass validation will normally not fail, but if there is
|
114
|
-
# an error in the report generation service it can sometimes happen.
|
115
|
-
raise AdwordsApi::Errors::ApiException, 'Report generation failed.'
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
# <i>Extension method</i> -- Download and return report data in CSV format.
|
120
|
-
#
|
121
|
-
# *Warning*: this method is blocking for the calling thread.
|
122
|
-
#
|
123
|
-
# Args:
|
124
|
-
# - wrapper: the service wrapper object for any API methods that need to be
|
125
|
-
# called
|
126
|
-
# - job_id: the job id for the report to be downloaded
|
127
|
-
# - xml: optional parameter used for testing and debugging
|
128
|
-
#
|
129
|
-
# Returns:
|
130
|
-
# The CSV data for the report (as a string)
|
131
|
-
#
|
132
|
-
def self.download_csv_report(wrapper, args)
|
133
|
-
(job_id, report_xml) = args
|
134
|
-
# Get XML report data.
|
135
|
-
report_xml = download_xml_report(wrapper, job_id) if report_xml.nil?
|
136
|
-
|
137
|
-
begin
|
138
|
-
# Construct DOM object.
|
139
|
-
doc = REXML::Document.new(report_xml)
|
140
|
-
|
141
|
-
# Get data columns.
|
142
|
-
columns = []
|
143
|
-
doc.elements.each('report/table/columns/column') do |column_elem|
|
144
|
-
name = column_elem.attributes['name']
|
145
|
-
columns << name unless name.nil?
|
146
|
-
end
|
147
|
-
|
148
|
-
# Get data rows.
|
149
|
-
rows = []
|
150
|
-
doc.elements.each('report/table/rows/row') do |row_elem|
|
151
|
-
rows << row_elem.attributes unless row_elem.attributes.nil?
|
152
|
-
end
|
153
|
-
|
154
|
-
# Build CSV
|
155
|
-
csv = ''
|
156
|
-
CSV::Writer.generate(csv) do |writer|
|
157
|
-
writer << columns
|
158
|
-
rows.each do |row|
|
159
|
-
row_values = []
|
160
|
-
columns.each { |column| row_values << row[column] }
|
161
|
-
writer << row_values
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
return csv
|
166
|
-
rescue REXML::ParseException => e
|
167
|
-
# Error parsing XML
|
168
|
-
raise AdwordsApi::Errors::ApiException,
|
169
|
-
"Error parsing report XML: %s\nSource: %s" % [e, e.backtrace.first]
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
# <i>Extension method</i> -- Download and return a v20xx report into a file.
|
174
|
-
#
|
175
|
-
# *Warning*: this method is blocking for the calling thread.
|
176
|
-
#
|
177
|
-
# Args:
|
178
|
-
# - wrapper: the service wrapper object for any API methods that need to be
|
179
|
-
# called
|
180
|
-
# - report_definition_id: the id for the report definition
|
181
|
-
# - path: the file where the data should be saved
|
182
|
-
#
|
183
|
-
# Returns:
|
184
|
-
# nil
|
185
|
-
#
|
186
|
-
def self.download_report_as_file(wrapper, args)
|
187
|
-
(report_definition_id, path) = args
|
188
|
-
report_data = download_report(wrapper, [report_definition_id])
|
189
|
-
save_to_file(report_data, path)
|
190
|
-
return nil
|
191
|
-
end
|
192
|
-
|
193
|
-
# <i>Extension method</i> -- Download and return a v20xx report.
|
194
|
-
#
|
195
|
-
# *Warning*: this method is blocking for the calling thread.
|
196
|
-
#
|
197
|
-
# Args:
|
198
|
-
# - wrapper: the service wrapper object for any API methods that need to be
|
199
|
-
# called
|
200
|
-
# - report_definition_id: the id for the report definition
|
201
|
-
#
|
202
|
-
# Returns:
|
203
|
-
# The data for the report (as a string)
|
204
|
-
#
|
205
|
-
def self.download_report(wrapper, args)
|
206
|
-
report_definition_id = args.first
|
207
|
-
url = get_report_url(wrapper, "?__rd=%s" % report_definition_id)
|
208
|
-
report_response = get_report_response(wrapper, url)
|
209
|
-
return report_response.body
|
210
|
-
end
|
211
|
-
|
212
|
-
private
|
213
|
-
|
214
|
-
# Saves raw data to a file.
|
215
|
-
def self.save_to_file(data, path)
|
216
|
-
open(path, 'wb') { |file| file.puts(data) } if path
|
217
|
-
end
|
218
|
-
|
219
|
-
# Generates default report URL with given parameters.
|
220
|
-
def self.get_report_url(wrapper, parameters)
|
221
|
-
return AdwordsApi::ApiConfig.report_download_url(
|
222
|
-
wrapper.api.config.read('service.environment'),
|
223
|
-
wrapper.version) + parameters
|
224
|
-
end
|
225
|
-
|
226
|
-
# Gets a report response for a given parameters.
|
227
|
-
def self.get_report_response(wrapper, url)
|
228
|
-
headers = get_report_request_headers(wrapper, url)
|
229
|
-
report_response = AdsCommon::Http.get_response(url, wrapper.api.config,
|
230
|
-
headers)
|
231
|
-
return report_response
|
232
|
-
end
|
233
|
-
|
234
|
-
def self.get_report_request_headers(wrapper, url)
|
235
|
-
headers = {}
|
236
|
-
credentials = wrapper.api.credential_handler.credentials
|
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))
|
241
|
-
headers['developerToken'] = credentials[:developerToken]
|
242
|
-
if credentials[:clientCustomerId]
|
243
|
-
headers['clientCustomerId'] = credentials[:clientCustomerId]
|
244
|
-
elsif credentials[:clientEmail]
|
245
|
-
headers['clientEmail'] = credentials[:clientEmail]
|
246
|
-
elsif credentials[:email]
|
247
|
-
headers['clientEmail'] = credentials[:email]
|
248
|
-
end
|
249
|
-
money_in_micros =
|
250
|
-
wrapper.api.config.read('library.return_money_in_micros')
|
251
|
-
unless money_in_micros.nil?
|
252
|
-
headers['returnMoneyInMicros'] = money_in_micros
|
253
|
-
end
|
254
|
-
return headers
|
255
|
-
end
|
256
|
-
|
257
|
-
# Checks for old-style v13 reporting error.
|
258
|
-
def self.check_old_error(response_text)
|
259
|
-
error_message_regex = '^!!!(-?\d+)\|\|\|(-?\d+)\|\|\|(.*)\?\?\?'
|
260
|
-
matches = response_text.match(error_message_regex)
|
261
|
-
if matches
|
262
|
-
message = (matches[3].nil?) ? response_text : matches[3]
|
263
|
-
raise AdwordsApi::Errors::ApiException,
|
264
|
-
"Report download error occured: %s" % message
|
265
|
-
end
|
266
|
-
return nil
|
267
|
-
end
|
268
|
-
end
|
269
|
-
end
|