google-adwords-api 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. checksums.yaml +8 -8
  2. data/ChangeLog +3 -0
  3. data/examples/v201402/basic_operations/delete_ad_group.rb +1 -22
  4. data/examples/{v201309/basic_operations/delete_ad_group.rb → v201402/basic_operations/delete_ad_group.rb~} +2 -8
  5. data/examples/v201402/basic_operations/delete_campaign.rb +2 -23
  6. data/examples/{v201309/basic_operations/update_campaign.rb → v201402/basic_operations/delete_campaign.rb~} +13 -12
  7. data/examples/v201406/basic_operations/remove_ad_group.rb +1 -22
  8. data/examples/{v201309/basic_operations/update_ad_group.rb → v201406/basic_operations/remove_ad_group.rb~} +14 -13
  9. data/examples/v201406/basic_operations/remove_campaign.rb +4 -24
  10. data/examples/{v201309/basic_operations/delete_campaign.rb → v201406/basic_operations/remove_campaign.rb~} +11 -11
  11. data/lib/adwords_api.rb +5 -8
  12. data/lib/adwords_api/api_config.rb +0 -76
  13. data/lib/adwords_api/report_utils.rb +9 -0
  14. data/lib/adwords_api/report_utils.rb~ +283 -0
  15. data/lib/adwords_api/version.rb +1 -1
  16. data/lib/adwords_api/version.rb~ +26 -0
  17. data/test/adwords_api/test_adwords_api.rb +5 -21
  18. data/test/adwords_api/test_adwords_api.rb~ +114 -0
  19. data/test/adwords_api/test_api_config.rb +8 -8
  20. data/test/adwords_api/test_report_utils.rb +29 -1
  21. data/test/adwords_api/test_report_utils.rb~ +216 -0
  22. data/test/templates/{v201309 → v201402}/basic_operations_get_campaigns.def +7 -7
  23. data/test/templates/{v201309 → v201402}/misc_use_oauth2_jwt.def +7 -7
  24. data/test/templates/v201406/basic_operations_get_campaigns.def +114 -0
  25. data/test/templates/v201406/misc_use_oauth2_jwt.def +131 -0
  26. metadata +14 -139
  27. data/examples/v201309/account_management/create_account.rb +0 -95
  28. data/examples/v201309/account_management/get_account_alerts.rb +0 -122
  29. data/examples/v201309/account_management/get_account_changes.rb +0 -145
  30. data/examples/v201309/account_management/get_account_hierarchy.rb +0 -103
  31. data/examples/v201309/advanced_operations/add_ad_group_bid_modifier.rb +0 -105
  32. data/examples/v201309/advanced_operations/add_click_to_download_ad.rb +0 -137
  33. data/examples/v201309/advanced_operations/add_site_links.rb +0 -306
  34. data/examples/v201309/advanced_operations/create_and_attach_shared_keyword_set.rb +0 -147
  35. data/examples/v201309/advanced_operations/find_and_remove_criteria_from_shared_set.rb +0 -181
  36. data/examples/v201309/advanced_operations/get_ad_group_bid_modifiers.rb +0 -106
  37. data/examples/v201309/advanced_operations/update_site_links.rb +0 -194
  38. data/examples/v201309/advanced_operations/upload_offline_conversions.rb +0 -117
  39. data/examples/v201309/advanced_operations/use_shared_bidding_strategy.rb +0 -163
  40. data/examples/v201309/basic_operations/add_ad_groups.rb +0 -143
  41. data/examples/v201309/basic_operations/add_campaigns.rb +0 -162
  42. data/examples/v201309/basic_operations/add_keywords.rb +0 -116
  43. data/examples/v201309/basic_operations/add_text_ads.rb +0 -113
  44. data/examples/v201309/basic_operations/delete_ad.rb +0 -93
  45. data/examples/v201309/basic_operations/delete_keyword.rb +0 -98
  46. data/examples/v201309/basic_operations/get_ad_groups.rb +0 -106
  47. data/examples/v201309/basic_operations/get_campaigns.rb +0 -101
  48. data/examples/v201309/basic_operations/get_campaigns_with_awql.rb +0 -93
  49. data/examples/v201309/basic_operations/get_keywords.rb +0 -112
  50. data/examples/v201309/basic_operations/get_text_ads.rb +0 -114
  51. data/examples/v201309/basic_operations/pause_ad.rb +0 -92
  52. data/examples/v201309/basic_operations/update_keyword.rb +0 -110
  53. data/examples/v201309/campaign_management/add_experiment.rb +0 -166
  54. data/examples/v201309/campaign_management/add_keywords_in_bulk.rb +0 -158
  55. data/examples/v201309/campaign_management/add_location_extension.rb +0 -125
  56. data/examples/v201309/campaign_management/get_all_disapproved_ads.rb +0 -101
  57. data/examples/v201309/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -93
  58. data/examples/v201309/campaign_management/promote_experiment.rb +0 -85
  59. data/examples/v201309/campaign_management/set_ad_parameters.rb +0 -122
  60. data/examples/v201309/campaign_management/set_criterion_bid_modifier.rb +0 -108
  61. data/examples/v201309/campaign_management/validate_text_ad.rb +0 -114
  62. data/examples/v201309/error_handling/handle_captcha_challenge.rb +0 -93
  63. data/examples/v201309/error_handling/handle_partial_failures.rb +0 -134
  64. data/examples/v201309/error_handling/handle_policy_violation_error.rb +0 -145
  65. data/examples/v201309/error_handling/handle_two_factor_authorization_error.rb +0 -88
  66. data/examples/v201309/misc/get_all_images_and_videos.rb +0 -108
  67. data/examples/v201309/misc/setup_oauth2.rb +0 -88
  68. data/examples/v201309/misc/upload_image.rb +0 -97
  69. data/examples/v201309/misc/use_oauth2_jwt.rb +0 -97
  70. data/examples/v201309/optimization/estimate_keyword_traffic.rb +0 -137
  71. data/examples/v201309/optimization/get_keyword_bid_simulations.rb +0 -100
  72. data/examples/v201309/optimization/get_keyword_ideas.rb +0 -130
  73. data/examples/v201309/optimization/get_placement_ideas.rb +0 -112
  74. data/examples/v201309/remarketing/add_audience.rb +0 -123
  75. data/examples/v201309/remarketing/add_conversion_tracker.rb +0 -104
  76. data/examples/v201309/reporting/download_criteria_report.rb +0 -87
  77. data/examples/v201309/reporting/download_criteria_report_with_awql.rb +0 -86
  78. data/examples/v201309/reporting/get_report_fields.rb +0 -79
  79. data/examples/v201309/reporting/parallel_report_download.rb +0 -171
  80. data/examples/v201309/targeting/add_campaign_targeting_criteria.rb +0 -123
  81. data/examples/v201309/targeting/add_demographic_targeting_criteria.rb +0 -116
  82. data/examples/v201309/targeting/get_campaign_targeting_criteria.rb +0 -110
  83. data/examples/v201309/targeting/get_targetable_languages_and_carriers.rb +0 -94
  84. data/examples/v201309/targeting/lookup_location.rb +0 -112
  85. data/lib/adwords_api/v201309/ad_group_ad_service.rb +0 -42
  86. data/lib/adwords_api/v201309/ad_group_ad_service_registry.rb +0 -46
  87. data/lib/adwords_api/v201309/ad_group_bid_modifier_service.rb +0 -38
  88. data/lib/adwords_api/v201309/ad_group_bid_modifier_service_registry.rb +0 -46
  89. data/lib/adwords_api/v201309/ad_group_criterion_service.rb +0 -42
  90. data/lib/adwords_api/v201309/ad_group_criterion_service_registry.rb +0 -46
  91. data/lib/adwords_api/v201309/ad_group_feed_service.rb +0 -38
  92. data/lib/adwords_api/v201309/ad_group_feed_service_registry.rb +0 -46
  93. data/lib/adwords_api/v201309/ad_group_service.rb +0 -42
  94. data/lib/adwords_api/v201309/ad_group_service_registry.rb +0 -46
  95. data/lib/adwords_api/v201309/ad_param_service.rb +0 -38
  96. data/lib/adwords_api/v201309/ad_param_service_registry.rb +0 -46
  97. data/lib/adwords_api/v201309/adwords_user_list_service.rb +0 -38
  98. data/lib/adwords_api/v201309/adwords_user_list_service_registry.rb +0 -46
  99. data/lib/adwords_api/v201309/alert_service.rb +0 -34
  100. data/lib/adwords_api/v201309/alert_service_registry.rb +0 -46
  101. data/lib/adwords_api/v201309/bidding_strategy_service.rb +0 -38
  102. data/lib/adwords_api/v201309/bidding_strategy_service_registry.rb +0 -46
  103. data/lib/adwords_api/v201309/budget_order_service.rb +0 -42
  104. data/lib/adwords_api/v201309/budget_order_service_registry.rb +0 -46
  105. data/lib/adwords_api/v201309/budget_service.rb +0 -38
  106. data/lib/adwords_api/v201309/budget_service_registry.rb +0 -46
  107. data/lib/adwords_api/v201309/campaign_ad_extension_service.rb +0 -38
  108. data/lib/adwords_api/v201309/campaign_ad_extension_service_registry.rb +0 -46
  109. data/lib/adwords_api/v201309/campaign_criterion_service.rb +0 -42
  110. data/lib/adwords_api/v201309/campaign_criterion_service_registry.rb +0 -46
  111. data/lib/adwords_api/v201309/campaign_feed_service.rb +0 -38
  112. data/lib/adwords_api/v201309/campaign_feed_service_registry.rb +0 -46
  113. data/lib/adwords_api/v201309/campaign_service.rb +0 -42
  114. data/lib/adwords_api/v201309/campaign_service_registry.rb +0 -46
  115. data/lib/adwords_api/v201309/campaign_shared_set_service.rb +0 -38
  116. data/lib/adwords_api/v201309/campaign_shared_set_service_registry.rb +0 -47
  117. data/lib/adwords_api/v201309/constant_data_service.rb +0 -62
  118. data/lib/adwords_api/v201309/constant_data_service_registry.rb +0 -46
  119. data/lib/adwords_api/v201309/conversion_tracker_service.rb +0 -38
  120. data/lib/adwords_api/v201309/conversion_tracker_service_registry.rb +0 -46
  121. data/lib/adwords_api/v201309/customer_service.rb +0 -34
  122. data/lib/adwords_api/v201309/customer_service_registry.rb +0 -46
  123. data/lib/adwords_api/v201309/customer_sync_service.rb +0 -34
  124. data/lib/adwords_api/v201309/customer_sync_service_registry.rb +0 -47
  125. data/lib/adwords_api/v201309/data_service.rb +0 -38
  126. data/lib/adwords_api/v201309/data_service_registry.rb +0 -46
  127. data/lib/adwords_api/v201309/experiment_service.rb +0 -38
  128. data/lib/adwords_api/v201309/experiment_service_registry.rb +0 -46
  129. data/lib/adwords_api/v201309/feed_item_service.rb +0 -38
  130. data/lib/adwords_api/v201309/feed_item_service_registry.rb +0 -46
  131. data/lib/adwords_api/v201309/feed_mapping_service.rb +0 -38
  132. data/lib/adwords_api/v201309/feed_mapping_service_registry.rb +0 -46
  133. data/lib/adwords_api/v201309/feed_service.rb +0 -38
  134. data/lib/adwords_api/v201309/feed_service_registry.rb +0 -46
  135. data/lib/adwords_api/v201309/geo_location_service.rb +0 -34
  136. data/lib/adwords_api/v201309/geo_location_service_registry.rb +0 -46
  137. data/lib/adwords_api/v201309/location_criterion_service.rb +0 -34
  138. data/lib/adwords_api/v201309/location_criterion_service_registry.rb +0 -46
  139. data/lib/adwords_api/v201309/managed_customer_service.rb +0 -50
  140. data/lib/adwords_api/v201309/managed_customer_service_registry.rb +0 -46
  141. data/lib/adwords_api/v201309/media_service.rb +0 -38
  142. data/lib/adwords_api/v201309/media_service_registry.rb +0 -46
  143. data/lib/adwords_api/v201309/mutate_job_service.rb +0 -42
  144. data/lib/adwords_api/v201309/mutate_job_service_registry.rb +0 -46
  145. data/lib/adwords_api/v201309/offline_conversion_feed_service.rb +0 -34
  146. data/lib/adwords_api/v201309/offline_conversion_feed_service_registry.rb +0 -46
  147. data/lib/adwords_api/v201309/report_definition_service.rb +0 -34
  148. data/lib/adwords_api/v201309/report_definition_service_registry.rb +0 -46
  149. data/lib/adwords_api/v201309/shared_criterion_service.rb +0 -38
  150. data/lib/adwords_api/v201309/shared_criterion_service_registry.rb +0 -47
  151. data/lib/adwords_api/v201309/shared_set_service.rb +0 -38
  152. data/lib/adwords_api/v201309/shared_set_service_registry.rb +0 -47
  153. data/lib/adwords_api/v201309/targeting_idea_service.rb +0 -38
  154. data/lib/adwords_api/v201309/targeting_idea_service_registry.rb +0 -46
  155. data/lib/adwords_api/v201309/traffic_estimator_service.rb +0 -34
  156. data/lib/adwords_api/v201309/traffic_estimator_service_registry.rb +0 -46
  157. data/test/bugs/test_issue_00000031.rb +0 -75
@@ -36,8 +36,7 @@ end
36
36
 
37
37
  class TestAdwordsApi < Test::Unit::TestCase
38
38
 
39
- API_VERSION = :v201402
40
- LAST_CLIENT_LOGIN_API_VERSION = :v201309
39
+ API_VERSION = :v201406
41
40
 
42
41
  def setup()
43
42
  @logger = LoggerStub.new
@@ -102,29 +101,14 @@ class TestAdwordsApi < Test::Unit::TestCase
102
101
  service = adwords_api.service(:ManagedCustomerService, API_VERSION)
103
102
  end
104
103
 
105
- def test_clientlogin_deprecation_warning()
104
+ def test_clientlogin_error()
106
105
  adwords_api = AdwordsApi::Api.new({
107
106
  :library => {:logger => @logger},
108
107
  :authentication => {:method => 'ClientLogin'},
109
108
  :service => {:environment => 'PRODUCTION'}
110
109
  })
111
- service = adwords_api.service(:CampaignService,
112
- LAST_CLIENT_LOGIN_API_VERSION)
113
- assert_not_nil(@logger.last_warning)
114
- end
115
-
116
- def test_clientlogin_removal()
117
- adwords_api = AdwordsApi::Api.new({
118
- :library => {:logger => @logger},
119
- :authentication => {:method => 'ClientLogin'},
120
- :service => {:environment => 'PRODUCTION'}
121
- })
122
- assert_nothing_raised do
123
- service = adwords_api.service(:CampaignService,
124
- LAST_CLIENT_LOGIN_API_VERSION)
125
- end
126
- assert_raise(AdsCommon::Errors::AuthError) do
127
- service = adwords_api.service(:CampaignService, API_VERSION)
128
- end
110
+ assert_raise AdsCommon::Errors::AuthError do
111
+ service = adwords_api.service(:CampaignService, API_VERSION)
112
+ end
129
113
  end
130
114
  end
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
+ #
6
+ # Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
7
+ #
8
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
+ # implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ # Tests the AdWords API class features.
22
+
23
+ require 'test/unit'
24
+
25
+ require 'ads_common/config'
26
+ require 'ads_common/api_config'
27
+ require 'adwords_api'
28
+
29
+
30
+ class LoggerStub
31
+ attr_reader :last_warning
32
+ def warn(message)
33
+ @last_warning = message
34
+ end
35
+ end
36
+
37
+ class TestAdwordsApi < Test::Unit::TestCase
38
+
39
+ API_VERSION = :v201406
40
+
41
+ def setup()
42
+ @logger = LoggerStub.new
43
+ end
44
+
45
+ def test_initialize()
46
+ assert_nothing_raised do
47
+ adwords_api = AdwordsApi::Api.new({})
48
+ end
49
+ end
50
+
51
+ def test_api_config()
52
+ assert_nothing_raised do
53
+ adwords_api = AdwordsApi::Api.new({})
54
+ api_config = adwords_api.api_config()
55
+ assert_not_nil(api_config)
56
+ assert_kind_of(AdsCommon::ApiConfig, api_config)
57
+ end
58
+ end
59
+
60
+ def test_use_mcc()
61
+ adwords_api = AdwordsApi::Api.new({})
62
+ adwords_api.use_mcc = false
63
+ assert(!adwords_api.use_mcc)
64
+ adwords_api.use_mcc do
65
+ assert(adwords_api.use_mcc)
66
+ end
67
+ end
68
+
69
+ def test_validate_only()
70
+ adwords_api = AdwordsApi::Api.new({})
71
+ adwords_api.validate_only = false
72
+ assert(!adwords_api.validate_only)
73
+ adwords_api.validate_only do
74
+ assert(adwords_api.validate_only)
75
+ end
76
+ end
77
+
78
+ def test_partial_failure()
79
+ adwords_api = AdwordsApi::Api.new({})
80
+ adwords_api.partial_failure = false
81
+ assert(!adwords_api.partial_failure)
82
+ adwords_api.partial_failure do
83
+ assert(adwords_api.partial_failure)
84
+ end
85
+ end
86
+
87
+ def test_no_sandbox_env()
88
+ adwords_api = AdwordsApi::Api.new({
89
+ :service => {:environment => 'SANDBOX'}
90
+ })
91
+ assert_raise(AdsCommon::Errors::Error) do
92
+ service = adwords_api.service(:ManagedCustomerService, API_VERSION)
93
+ end
94
+ end
95
+
96
+ def test_prod_env()
97
+ adwords_api = AdwordsApi::Api.new({
98
+ :library => {:logger => @logger},
99
+ :service => {:environment => 'PRODUCTION'}
100
+ })
101
+ service = adwords_api.service(:ManagedCustomerService, API_VERSION)
102
+ end
103
+
104
+ def test_clientlogin_error()
105
+ adwords_api = AdwordsApi::Api.new({
106
+ :library => {:logger => @logger},
107
+ :authentication => {:method => 'ClientLogin'},
108
+ :service => {:environment => 'PRODUCTION'}
109
+ })
110
+ assert_raise do
111
+ service = adwords_api.service(:CampaignService, API_VERSION)
112
+ end
113
+ end
114
+ end
@@ -32,27 +32,27 @@ class TestApiConfig < Test::Unit::TestCase
32
32
 
33
33
  # Tests correct require path.
34
34
  def test_do_require()
35
- name1 = @config.do_require(:v201309, :CampaignService)
36
- assert_equal('adwords_api/v201309/campaign_service', name1)
35
+ name1 = @config.do_require(:v201406, :CampaignService)
36
+ assert_equal('adwords_api/v201406/campaign_service', name1)
37
37
  end
38
38
 
39
39
  # Tests correct module name.
40
40
  def test_module_name()
41
- name1 = @config.module_name(:v201309, :CampaignService)
42
- assert_equal('AdwordsApi::V201309::CampaignService', name1)
41
+ name1 = @config.module_name(:v201406, :CampaignService)
42
+ assert_equal('AdwordsApi::V201406::CampaignService', name1)
43
43
  end
44
44
 
45
45
  # Tests correct interface name.
46
46
  def test_interface_name()
47
- name1 = @config.interface_name(:v201309, :CampaignService)
48
- assert_equal('AdwordsApi::V201309::CampaignService::CampaignService', name1)
47
+ name1 = @config.interface_name(:v201406, :CampaignService)
48
+ assert_equal('AdwordsApi::V201406::CampaignService::CampaignService', name1)
49
49
  end
50
50
 
51
51
  # Tests AdHoc report URL generator (prod).
52
52
  def test_adhoc_report_download_url_prod()
53
- url = AdwordsApi::ApiConfig.adhoc_report_download_url(:PRODUCTION, :v201309)
53
+ url = AdwordsApi::ApiConfig.adhoc_report_download_url(:PRODUCTION, :v201406)
54
54
  expected_url =
55
- 'https://adwords.google.com/api/adwords/reportdownload/v201309'
55
+ 'https://adwords.google.com/api/adwords/reportdownload/v201406'
56
56
  assert_equal(expected_url, url)
57
57
  end
58
58
  end
@@ -30,6 +30,7 @@ module AdwordsApi
30
30
  public :check_for_errors
31
31
  public :check_for_xml_error
32
32
  public :add_report_definition_hash_order
33
+ public :check_report_definition_hash
33
34
  end
34
35
  end
35
36
 
@@ -55,7 +56,7 @@ GZIPPED_REPORT = "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00Sr.-.\xC9\xCFUptq\x0F\xF
55
56
 
56
57
  class TestReportUtils < Test::Unit::TestCase
57
58
 
58
- API_VERSION = :v201309
59
+ API_VERSION = :v201406
59
60
 
60
61
  # Initialize tests.
61
62
  def setup()
@@ -185,4 +186,31 @@ class TestReportUtils < Test::Unit::TestCase
185
186
  assert_not_nil(e.message)
186
187
  end
187
188
  end
189
+
190
+ def test_return_money_in_micros_removal()
191
+ node = {
192
+ :report_name => 'report_name',
193
+ :report_type => 'CAMPAIGN_PERFORMANCE_REPORT',
194
+ :selector => {
195
+ :date_range => {:max=> '20120405', :min => '20120405'},
196
+ :predicates => {:operator => 'IN', :field => 'S', :values => ['A']},
197
+ :fields => ['CampaignId']
198
+ },
199
+ :download_format => 'CSV',
200
+ :date_range_type => 'LAST_7_DAYS'
201
+ }
202
+ assert_nothing_raised do
203
+ @report_utils.check_report_definition_hash(node)
204
+ end
205
+
206
+ node[:return_money_in_micros] = true
207
+ assert_raise AdwordsApi::Errors::InvalidReportDefinitionError do
208
+ @report_utils.check_report_definition_hash(node)
209
+ end
210
+
211
+ node[:return_money_in_micros] = false
212
+ assert_raise AdwordsApi::Errors::InvalidReportDefinitionError do
213
+ @report_utils.check_report_definition_hash(node)
214
+ end
215
+ end
188
216
  end
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
+ #
6
+ # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
+ #
8
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
+ # implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ # Tests report utils.
22
+
23
+ require 'test/unit'
24
+
25
+ require 'adwords_api'
26
+
27
+ # Overriding default access levels to public for tests.
28
+ module AdwordsApi
29
+ class ReportUtils
30
+ public :check_for_errors
31
+ public :check_for_xml_error
32
+ public :add_report_definition_hash_order
33
+ public :check_report_definition_hash
34
+ end
35
+ end
36
+
37
+ # Stub class for HTTP response.
38
+ class ResponseStub
39
+ attr_reader :code
40
+ attr_reader :body
41
+
42
+ def initialize(code, body)
43
+ @code, @body = code, body
44
+ end
45
+ end
46
+
47
+ XML_REPLY = {
48
+ :reply => '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDownloadError><ApiError><type>ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT</type><trigger>foo</trigger><fieldPath>bar</fieldPath></ApiError></reportDownloadError>',
49
+ :type => 'ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT',
50
+ :trigger => 'foo',
51
+ :field_path => 'bar'
52
+ }
53
+
54
+ 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'
55
+ GZIPPED_REPORT = "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00Sr.-.\xC9\xCFUptq\x0F\xF2\x0F\r\x88\x0Fp\rr\xF3\x0F\xF2u\xF4sv\x8D\x0Fr\r\xF0\x0F\nQ\xD0pIMV0\xD2Q0204\xD4\x05\xB1- lM%.\xE7\xC4\xDC\x82\xC4\xCC\xF4<\x05O\x17\x1D\xC7\x14\x85\xF4\xA2\xFC\xD2\x02\x10\xDB3\xB7\xA0(\xB5\xB883?\xAFX\xC79'39\eH\xE5\x17\x97p\x85\xE4\x97$\xE6\xE8(\xE8\xEA\xEA\x18\x80\xA0\x9E\x81\x01\x17\x00\xBE\x1D\xBE\xAD\x81\x00\x00\x00"
56
+
57
+ class TestReportUtils < Test::Unit::TestCase
58
+
59
+ API_VERSION = :v201406
60
+
61
+ # Initialize tests.
62
+ def setup()
63
+ @api = AdwordsApi::Api.new
64
+ @report_utils = @api.report_utils(API_VERSION)
65
+ end
66
+
67
+ # Testing HTTP code 400.
68
+ def test_check_for_errors_400()
69
+ begin
70
+ response = ResponseStub.new(400, XML_REPLY[:reply])
71
+ @report_utils.check_for_errors(response)
72
+ assert(false, 'No exception thrown for code 400')
73
+ rescue AdwordsApi::Errors::ReportXmlError => e
74
+ assert_equal(400, e.http_code)
75
+ assert_equal(XML_REPLY[:type], e.type)
76
+ assert_equal(XML_REPLY[:trigger], e.trigger)
77
+ assert_equal(XML_REPLY[:field_path], e.field_path)
78
+ assert_not_nil(e.message)
79
+ end
80
+ end
81
+
82
+ # Testing HTTP code 500.
83
+ def test_check_for_errors_500()
84
+ begin
85
+ response = ResponseStub.new(500, nil)
86
+ @report_utils.check_for_errors(response)
87
+ assert(false, 'No exception thrown for code 500')
88
+ rescue AdwordsApi::Errors::ReportError => e
89
+ assert_equal(500, e.http_code)
90
+ end
91
+ end
92
+
93
+ # Testing HTTP code 200 with success.
94
+ def test_check_for_errors_200_success()
95
+ response = ResponseStub.new(200, VALID_REPORT)
96
+ assert_nothing_raised do
97
+ @report_utils.check_for_errors(response)
98
+ end
99
+ end
100
+
101
+ # Testing correct gzipped reply.
102
+ def test_gzipped_data()
103
+ report = (RUBY_VERSION >= '1.9.1') ?
104
+ GZIPPED_REPORT.force_encoding('UTF-8') : GZIPPED_REPORT
105
+ response = ResponseStub.new(200, report)
106
+ assert_nothing_raised do
107
+ @report_utils.check_for_errors(response)
108
+ end
109
+ end
110
+
111
+ # Tests generated hash order for root (complete set).
112
+ def test_add_report_definition_hash_order_root1()
113
+ node = {
114
+ :include_zero_impressions => false,
115
+ :download_format => 'CSV',
116
+ :report_type => 'CRITERIA_PERFORMANCE_REPORT',
117
+ :selector => {},
118
+ :report_name => 'report_name',
119
+ :date_range_type => 'LAST_7_DAYS'
120
+ }
121
+ expected = [:selector, :report_name, :report_type, :date_range_type,
122
+ :download_format, :include_zero_impressions]
123
+ @report_utils.add_report_definition_hash_order(node)
124
+ assert_not_nil(node[:order!])
125
+ assert_equal(expected, node[:order!])
126
+ end
127
+
128
+ # Tests generated hash order for root (incomplete set).
129
+ def test_add_report_definition_hash_order_root2()
130
+ node = {
131
+ :download_format => 'CSV',
132
+ :report_type => 'CRITERIA_PERFORMANCE_REPORT',
133
+ :selector => {},
134
+ :report_name => 'report_name',
135
+ :date_range_type => 'LAST_7_DAYS'
136
+ }
137
+ expected = [:selector, :report_name, :report_type, :date_range_type,
138
+ :download_format]
139
+ @report_utils.add_report_definition_hash_order(node)
140
+ assert_not_nil(node[:order!])
141
+ assert_equal(expected, node[:order!])
142
+ end
143
+
144
+ # Tests generated hash order for whole structure.
145
+ def test_add_report_definition_hash_order_deep()
146
+ node = {
147
+ :report_name => 'report_name',
148
+ :report_type => 'CRITERIA_PERFORMANCE_REPORT',
149
+ :selector => {
150
+ :date_range => {:max => '20120405', :min => '20120405'},
151
+ :predicates => {:operator => 'IN', :field => 'S', :values => ['A']},
152
+ :fields => ['CampaignId']
153
+ },
154
+ :include_zero_impressions => false,
155
+ :download_format => 'CSV',
156
+ :date_range_type => 'LAST_7_DAYS'
157
+ }
158
+ expected1 = [:selector, :report_name, :report_type, :date_range_type,
159
+ :download_format, :include_zero_impressions]
160
+ expected2 = [:fields, :predicates, :date_range]
161
+ expected3 = [:min, :max]
162
+ expected4 = [:field, :operator, :values]
163
+
164
+ @report_utils.add_report_definition_hash_order(node)
165
+ assert_not_nil(node[:order!])
166
+ assert_not_nil(node[:selector][:order!])
167
+ assert_not_nil(node[:selector][:date_range][:order!])
168
+ assert_not_nil(node[:selector][:predicates][:order!])
169
+
170
+ assert_equal(expected1, node[:order!])
171
+ assert_equal(expected2, node[:selector][:order!])
172
+ assert_equal(expected3, node[:selector][:date_range][:order!])
173
+ assert_equal(expected4, node[:selector][:predicates][:order!])
174
+ end
175
+
176
+ # Testing check_for_xml_error.
177
+ def check_for_xml_error()
178
+ begin
179
+ @report_utils.check_for_xml_error(XML_REPLY[:reply], 42)
180
+ assert(false, 'No exception thrown for code 42')
181
+ rescue AdwordsApi::Errors::ReportXmlError => e
182
+ assert_equal(42, e.http_code)
183
+ assert_equal(XML_REPLY[:type], e.type)
184
+ assert_equal(XML_REPLY[:trigger], e.trigger)
185
+ assert_equal(XML_REPLY[:field_path], e.field_path)
186
+ assert_not_nil(e.message)
187
+ end
188
+ end
189
+
190
+ def test_return_money_in_micros_removal()
191
+ node = {
192
+ :report_name => 'report_name',
193
+ :report_type => 'CAMPAIGN_PERFORMANCE_REPORT',
194
+ :selector => {
195
+ :date_range => {:max=> '20120405', :min => '20120405'},
196
+ :predicates => {:operator => 'IN', :field => 'S', :values => ['A']},
197
+ :fields => ['CampaignId']
198
+ },
199
+ :download_format => 'CSV',
200
+ :date_range_type => 'LAST_7_DAYS'
201
+ }
202
+ assert_nothing_raised do
203
+ @report_utils.check_report_definition_hash(node)
204
+ end
205
+
206
+ node[:return_money_in_micros] = true
207
+ assert_raise AdwordsApi::Errors::InvalidReportDefinitionError do
208
+ @report_utils.check_report_definition_hash(node)
209
+ end
210
+
211
+ node[:return_money_in_micros] = false
212
+ assert_raise AdwordsApi::Errors::InvalidReportDefinitionError do
213
+ @report_utils.check_report_definition_hash(node)
214
+ end
215
+ end
216
+ end