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.
Files changed (192) hide show
  1. data/ChangeLog +7 -0
  2. data/README +4 -4
  3. data/examples/v201109_1/account_management/create_account.rb +80 -0
  4. data/examples/v201109_1/account_management/get_account_alerts.rb +111 -0
  5. data/examples/v201109_1/account_management/get_account_changes.rb +137 -0
  6. data/examples/v201109_1/account_management/get_account_hierarchy.rb +93 -0
  7. data/examples/v201109_1/account_management/get_client_customer_id.rb +85 -0
  8. data/examples/v201109_1/account_management/get_client_unit_usage.rb +87 -0
  9. data/examples/v201109_1/basic_operations/add_ad_groups.rb +111 -0
  10. data/examples/v201109_1/basic_operations/add_campaigns.rb +140 -0
  11. data/examples/v201109_1/basic_operations/add_keywords.rb +108 -0
  12. data/examples/v201109_1/basic_operations/add_text_ads.rb +105 -0
  13. data/examples/v201109_1/basic_operations/delete_ad.rb +85 -0
  14. data/examples/v201109_1/basic_operations/delete_ad_group.rb +102 -0
  15. data/examples/v201109_1/basic_operations/delete_campaign.rb +103 -0
  16. data/examples/v201109_1/basic_operations/delete_keyword.rb +90 -0
  17. data/examples/v201109_1/basic_operations/get_ad_groups.rb +98 -0
  18. data/examples/v201109_1/basic_operations/get_campaigns.rb +93 -0
  19. data/examples/v201109_1/basic_operations/get_keywords.rb +104 -0
  20. data/examples/v201109_1/basic_operations/get_text_ads.rb +106 -0
  21. data/examples/v201109_1/basic_operations/pause_ad.rb +84 -0
  22. data/examples/v201109_1/basic_operations/update_ad_group.rb +81 -0
  23. data/examples/v201109_1/basic_operations/update_campaign.rb +84 -0
  24. data/examples/v201109_1/basic_operations/update_keyword.rb +99 -0
  25. data/examples/v201109_1/campaign_management/add_experiment.rb +158 -0
  26. data/examples/v201109_1/campaign_management/add_keywords_in_bulk.rb +150 -0
  27. data/examples/v201109_1/campaign_management/add_location_extension.rb +117 -0
  28. data/examples/v201109_1/campaign_management/add_location_extension_override.rb +83 -0
  29. data/examples/v201109_1/campaign_management/get_all_disapproved_ads.rb +93 -0
  30. data/examples/v201109_1/campaign_management/promote_experiment.rb +77 -0
  31. data/examples/v201109_1/campaign_management/set_ad_parameters.rb +114 -0
  32. data/examples/v201109_1/campaign_management/validate_text_ad.rb +106 -0
  33. data/examples/v201109_1/error_handling/handle_captcha_challenge.rb +93 -0
  34. data/examples/v201109_1/error_handling/handle_partial_failures.rb +126 -0
  35. data/examples/v201109_1/error_handling/handle_policy_violation_error.rb +137 -0
  36. data/examples/v201109_1/error_handling/handle_two_factor_authorization_error.rb +87 -0
  37. data/examples/v201109_1/misc/get_all_images_and_videos.rb +101 -0
  38. data/examples/v201109_1/misc/upload_image.rb +90 -0
  39. data/examples/v201109_1/misc/use_oauth.rb +97 -0
  40. data/examples/v201109_1/optimization/estimate_keyword_traffic.rb +129 -0
  41. data/examples/v201109_1/optimization/get_keyword_bid_simulations.rb +92 -0
  42. data/examples/v201109_1/optimization/get_keyword_ideas.rb +113 -0
  43. data/examples/v201109_1/optimization/get_placement_ideas.rb +106 -0
  44. data/examples/v201109_1/remarketing/add_audience.rb +115 -0
  45. data/examples/v201109_1/remarketing/add_conversion_tracker.rb +97 -0
  46. data/examples/v201109_1/reporting/download_criteria_report.rb +79 -0
  47. data/examples/v201109_1/reporting/get_campaign_stats.rb +105 -0
  48. data/examples/v201109_1/reporting/get_defined_reports.rb +75 -0
  49. data/examples/{v201109/reporting/download_defined_report.rb → v201109_1/reporting/get_report_fields.rb} +15 -11
  50. data/examples/v201109_1/reporting/parallel_report_download.rb +159 -0
  51. data/examples/v201109_1/targeting/add_campaign_targeting_criteria.rb +118 -0
  52. data/examples/v201109_1/targeting/get_campaign_targeting_criteria.rb +102 -0
  53. data/examples/v201109_1/targeting/get_targetable_languages_and_carriers.rb +86 -0
  54. data/examples/v201109_1/targeting/lookup_location.rb +103 -0
  55. data/lib/adwords_api.rb +15 -88
  56. data/lib/adwords_api/api_config.rb +75 -33
  57. data/lib/adwords_api/client_login_header_handler.rb +17 -26
  58. data/lib/adwords_api/credential_handler.rb +29 -65
  59. data/lib/adwords_api/report_header_handler.rb +65 -0
  60. data/lib/adwords_api/report_utils.rb +12 -36
  61. data/lib/adwords_api/v201109/ad_extension_override_service.rb +3 -3
  62. data/lib/adwords_api/v201109/ad_extension_override_service_registry.rb +2 -2
  63. data/lib/adwords_api/v201109/ad_group_ad_service.rb +3 -3
  64. data/lib/adwords_api/v201109/ad_group_ad_service_registry.rb +1 -1
  65. data/lib/adwords_api/v201109/ad_group_criterion_service.rb +3 -3
  66. data/lib/adwords_api/v201109/ad_group_criterion_service_registry.rb +1 -1
  67. data/lib/adwords_api/v201109/ad_group_service.rb +3 -3
  68. data/lib/adwords_api/v201109/ad_group_service_registry.rb +1 -1
  69. data/lib/adwords_api/v201109/ad_param_service.rb +3 -3
  70. data/lib/adwords_api/v201109/ad_param_service_registry.rb +1 -1
  71. data/lib/adwords_api/v201109/alert_service.rb +3 -3
  72. data/lib/adwords_api/v201109/alert_service_registry.rb +1 -1
  73. data/lib/adwords_api/v201109/budget_order_service.rb +42 -0
  74. data/lib/adwords_api/v201109/budget_order_service_registry.rb +46 -0
  75. data/lib/adwords_api/v201109/bulk_mutate_job_service.rb +3 -3
  76. data/lib/adwords_api/v201109/bulk_mutate_job_service_registry.rb +1 -1
  77. data/lib/adwords_api/v201109/campaign_ad_extension_service.rb +3 -3
  78. data/lib/adwords_api/v201109/campaign_ad_extension_service_registry.rb +2 -2
  79. data/lib/adwords_api/v201109/campaign_criterion_service.rb +3 -3
  80. data/lib/adwords_api/v201109/campaign_criterion_service_registry.rb +1 -1
  81. data/lib/adwords_api/v201109/campaign_service.rb +3 -3
  82. data/lib/adwords_api/v201109/campaign_service_registry.rb +1 -1
  83. data/lib/adwords_api/v201109/campaign_target_service.rb +3 -3
  84. data/lib/adwords_api/v201109/campaign_target_service_registry.rb +1 -1
  85. data/lib/adwords_api/v201109/constant_data_service.rb +3 -3
  86. data/lib/adwords_api/v201109/constant_data_service_registry.rb +1 -1
  87. data/lib/adwords_api/v201109/conversion_tracker_service.rb +3 -3
  88. data/lib/adwords_api/v201109/conversion_tracker_service_registry.rb +1 -1
  89. data/lib/adwords_api/v201109/create_account_service.rb +3 -3
  90. data/lib/adwords_api/v201109/create_account_service_registry.rb +1 -1
  91. data/lib/adwords_api/v201109/customer_sync_service.rb +3 -3
  92. data/lib/adwords_api/v201109/customer_sync_service_registry.rb +1 -1
  93. data/lib/adwords_api/v201109/data_service.rb +3 -3
  94. data/lib/adwords_api/v201109/data_service_registry.rb +1 -1
  95. data/lib/adwords_api/v201109/experiment_service.rb +3 -3
  96. data/lib/adwords_api/v201109/experiment_service_registry.rb +1 -1
  97. data/lib/adwords_api/v201109/geo_location_service.rb +3 -3
  98. data/lib/adwords_api/v201109/geo_location_service_registry.rb +1 -1
  99. data/lib/adwords_api/v201109/info_service.rb +3 -3
  100. data/lib/adwords_api/v201109/info_service_registry.rb +1 -1
  101. data/lib/adwords_api/v201109/location_criterion_service.rb +3 -3
  102. data/lib/adwords_api/v201109/location_criterion_service_registry.rb +1 -1
  103. data/lib/adwords_api/v201109/media_service.rb +3 -3
  104. data/lib/adwords_api/v201109/media_service_registry.rb +1 -1
  105. data/lib/adwords_api/v201109/mutate_job_service.rb +3 -3
  106. data/lib/adwords_api/v201109/mutate_job_service_registry.rb +1 -1
  107. data/lib/adwords_api/v201109/report_definition_service.rb +3 -12
  108. data/lib/adwords_api/v201109/report_definition_service_registry.rb +1 -1
  109. data/lib/adwords_api/v201109/serviced_account_service.rb +3 -3
  110. data/lib/adwords_api/v201109/serviced_account_service_registry.rb +1 -1
  111. data/lib/adwords_api/v201109/targeting_idea_service.rb +3 -3
  112. data/lib/adwords_api/v201109/targeting_idea_service_registry.rb +1 -1
  113. data/lib/adwords_api/v201109/traffic_estimator_service.rb +3 -3
  114. data/lib/adwords_api/v201109/traffic_estimator_service_registry.rb +1 -1
  115. data/lib/adwords_api/v201109/user_list_service.rb +3 -3
  116. data/lib/adwords_api/v201109/user_list_service_registry.rb +1 -1
  117. data/lib/adwords_api/v201109_1/ad_extension_override_service.rb +38 -0
  118. data/lib/adwords_api/v201109_1/ad_extension_override_service_registry.rb +46 -0
  119. data/lib/adwords_api/v201109_1/ad_group_ad_service.rb +38 -0
  120. data/lib/adwords_api/v201109_1/ad_group_ad_service_registry.rb +46 -0
  121. data/lib/adwords_api/v201109_1/ad_group_criterion_service.rb +38 -0
  122. data/lib/adwords_api/v201109_1/ad_group_criterion_service_registry.rb +46 -0
  123. data/lib/adwords_api/v201109_1/ad_group_service.rb +38 -0
  124. data/lib/adwords_api/v201109_1/ad_group_service_registry.rb +46 -0
  125. data/lib/adwords_api/v201109_1/ad_param_service.rb +38 -0
  126. data/lib/adwords_api/v201109_1/ad_param_service_registry.rb +46 -0
  127. data/lib/adwords_api/v201109_1/alert_service.rb +34 -0
  128. data/lib/adwords_api/v201109_1/alert_service_registry.rb +46 -0
  129. data/lib/adwords_api/v201109_1/budget_order_service.rb +42 -0
  130. data/lib/adwords_api/v201109_1/budget_order_service_registry.rb +46 -0
  131. data/lib/adwords_api/v201109_1/bulk_mutate_job_service.rb +38 -0
  132. data/lib/adwords_api/v201109_1/bulk_mutate_job_service_registry.rb +46 -0
  133. data/lib/adwords_api/v201109_1/campaign_ad_extension_service.rb +38 -0
  134. data/lib/adwords_api/v201109_1/campaign_ad_extension_service_registry.rb +46 -0
  135. data/lib/adwords_api/v201109_1/campaign_criterion_service.rb +38 -0
  136. data/lib/adwords_api/v201109_1/campaign_criterion_service_registry.rb +46 -0
  137. data/lib/adwords_api/v201109_1/campaign_service.rb +38 -0
  138. data/lib/adwords_api/v201109_1/campaign_service_registry.rb +46 -0
  139. data/lib/adwords_api/v201109_1/campaign_target_service.rb +38 -0
  140. data/lib/adwords_api/v201109_1/campaign_target_service_registry.rb +46 -0
  141. data/lib/adwords_api/v201109_1/constant_data_service.rb +38 -0
  142. data/lib/adwords_api/v201109_1/constant_data_service_registry.rb +46 -0
  143. data/lib/adwords_api/v201109_1/conversion_tracker_service.rb +38 -0
  144. data/lib/adwords_api/v201109_1/conversion_tracker_service_registry.rb +46 -0
  145. data/lib/adwords_api/v201109_1/create_account_service.rb +34 -0
  146. data/lib/adwords_api/v201109_1/create_account_service_registry.rb +47 -0
  147. data/lib/adwords_api/v201109_1/customer_sync_service.rb +34 -0
  148. data/lib/adwords_api/v201109_1/customer_sync_service_registry.rb +47 -0
  149. data/lib/adwords_api/v201109_1/data_service.rb +38 -0
  150. data/lib/adwords_api/v201109_1/data_service_registry.rb +46 -0
  151. data/lib/adwords_api/v201109_1/experiment_service.rb +38 -0
  152. data/lib/adwords_api/v201109_1/experiment_service_registry.rb +46 -0
  153. data/lib/adwords_api/v201109_1/geo_location_service.rb +34 -0
  154. data/lib/adwords_api/v201109_1/geo_location_service_registry.rb +46 -0
  155. data/lib/adwords_api/v201109_1/info_service.rb +34 -0
  156. data/lib/adwords_api/v201109_1/info_service_registry.rb +46 -0
  157. data/lib/adwords_api/v201109_1/location_criterion_service.rb +34 -0
  158. data/lib/adwords_api/v201109_1/location_criterion_service_registry.rb +46 -0
  159. data/lib/adwords_api/v201109_1/media_service.rb +38 -0
  160. data/lib/adwords_api/v201109_1/media_service_registry.rb +46 -0
  161. data/lib/adwords_api/v201109_1/mutate_job_service.rb +42 -0
  162. data/lib/adwords_api/v201109_1/mutate_job_service_registry.rb +46 -0
  163. data/lib/adwords_api/v201109_1/report_definition_service.rb +38 -0
  164. data/lib/adwords_api/v201109_1/report_definition_service_registry.rb +46 -0
  165. data/lib/adwords_api/v201109_1/serviced_account_service.rb +34 -0
  166. data/lib/adwords_api/v201109_1/serviced_account_service_registry.rb +46 -0
  167. data/lib/adwords_api/v201109_1/targeting_idea_service.rb +38 -0
  168. data/lib/adwords_api/v201109_1/targeting_idea_service_registry.rb +46 -0
  169. data/lib/adwords_api/v201109_1/traffic_estimator_service.rb +34 -0
  170. data/lib/adwords_api/v201109_1/traffic_estimator_service_registry.rb +46 -0
  171. data/lib/adwords_api/v201109_1/user_list_service.rb +38 -0
  172. data/lib/adwords_api/v201109_1/user_list_service_registry.rb +46 -0
  173. data/lib/adwords_api/version.rb +1 -1
  174. data/test/adwords_api/test_api_config.rb +24 -8
  175. data/test/adwords_api/test_credential_handler.rb +32 -52
  176. data/test/coverage.rb +38 -0
  177. data/test/examples/v201109/test_reporting.rb +0 -12
  178. data/test/examples/v201109_1/test_account_management.rb +60 -0
  179. data/test/examples/v201109_1/test_basic_operations.rb +172 -0
  180. data/test/examples/v201109_1/test_campaign_management.rb +116 -0
  181. data/test/examples/v201109_1/test_error_handling.rb +63 -0
  182. data/{lib/adwords_api/v13_login_handler.rb → test/examples/v201109_1/test_misc.rb} +24 -10
  183. data/test/examples/v201109_1/test_optimization.rb +63 -0
  184. data/test/{suite_exampletests.rb → examples/v201109_1/test_remarketing.rb} +16 -8
  185. data/test/examples/v201109_1/test_reporting.rb +77 -0
  186. data/test/examples/v201109_1/test_targeting.rb +60 -0
  187. data/test/examples/v201109_1/utils.rb +239 -0
  188. data/test/suite_exampletests_v201109.rb +37 -0
  189. data/test/suite_exampletests_v201109_1.rb +37 -0
  190. data/test/suite_unittests.rb +7 -5
  191. metadata +136 -11
  192. data/lib/adwords_api/extensions.rb +0 -269
@@ -1,6 +1,6 @@
1
1
  # Encoding: utf-8
2
2
  #
3
- # Authors:: api.sgomes@gmail.com (Sérgio Gomes)
3
+ # Authors:: api.dklimkin@gmail.com (Danial Klimkin)
4
4
  #
5
5
  # Copyright:: Copyright 2010, Google Inc. All Rights Reserved.
6
6
  #
@@ -54,6 +54,37 @@ module AdwordsApi
54
54
  :AdGroupService,
55
55
  :AdParamService,
56
56
  :AlertService,
57
+ :BudgetOrderService,
58
+ :BulkMutateJobService,
59
+ :CampaignAdExtensionService,
60
+ :CampaignCriterionService,
61
+ :CampaignService,
62
+ :CampaignTargetService,
63
+ :ConstantDataService,
64
+ :ConversionTrackerService,
65
+ :CreateAccountService,
66
+ :CustomerSyncService,
67
+ :DataService,
68
+ :ExperimentService,
69
+ :GeoLocationService,
70
+ :InfoService,
71
+ :LocationCriterionService,
72
+ :MediaService,
73
+ :MutateJobService,
74
+ :ReportDefinitionService,
75
+ :ServicedAccountService,
76
+ :TargetingIdeaService,
77
+ :TrafficEstimatorService,
78
+ :UserListService
79
+ ],
80
+ :v201109_1 => [
81
+ :AdExtensionOverrideService,
82
+ :AdGroupAdService,
83
+ :AdGroupCriterionService,
84
+ :AdGroupService,
85
+ :AdParamService,
86
+ :AlertService,
87
+ :BudgetOrderService,
57
88
  :BulkMutateJobService,
58
89
  :CampaignAdExtensionService,
59
90
  :CampaignCriterionService,
@@ -82,11 +113,13 @@ module AdwordsApi
82
113
  @@environment_config = {
83
114
  :PRODUCTION => {
84
115
  :oauth_scope => 'https://adwords.google.com/api/adwords/',
85
- :v201109 => 'https://adwords.google.com/api/adwords/'
116
+ :v201109 => 'https://adwords.google.com/api/adwords/',
117
+ :v201109_1 => 'https://adwords.google.com/api/adwords/'
86
118
  },
87
119
  :SANDBOX => {
88
120
  :oauth_scope => 'https://adwords-sandbox.google.com/api/adwords/',
89
- :v201109 => 'https://adwords-sandbox.google.com/api/adwords/'
121
+ :v201109 => 'https://adwords-sandbox.google.com/api/adwords/',
122
+ :v201109_1 => 'https://adwords-sandbox.google.com/api/adwords/'
90
123
  }
91
124
  }
92
125
 
@@ -100,6 +133,7 @@ module AdwordsApi
100
133
  [:v201109, :AdGroupService] => 'cm/',
101
134
  [:v201109, :AdParamService] => 'cm/',
102
135
  [:v201109, :AlertService] => 'mcm/',
136
+ [:v201109, :BudgetOrderService] => 'billing/',
103
137
  [:v201109, :BulkMutateJobService] => 'job/',
104
138
  [:v201109, :CampaignAdExtensionService] => 'cm/',
105
139
  [:v201109, :CampaignCriterionService] => 'cm/',
@@ -120,17 +154,41 @@ module AdwordsApi
120
154
  [:v201109, :ServicedAccountService] => 'mcm/',
121
155
  [:v201109, :TargetingIdeaService] => 'o/',
122
156
  [:v201109, :TrafficEstimatorService] => 'o/',
123
- [:v201109, :UserListService] => 'cm/'
157
+ [:v201109, :UserListService] => 'cm/',
158
+ # v201109_1
159
+ [:v201109_1, :AdExtensionOverrideService] => 'cm/',
160
+ [:v201109_1, :AdGroupAdService] => 'cm/',
161
+ [:v201109_1, :AdGroupCriterionService] => 'cm/',
162
+ [:v201109_1, :AdGroupService] => 'cm/',
163
+ [:v201109_1, :AdParamService] => 'cm/',
164
+ [:v201109_1, :AlertService] => 'mcm/',
165
+ [:v201109_1, :BudgetOrderService] => 'billing/',
166
+ [:v201109_1, :BulkMutateJobService] => 'job/',
167
+ [:v201109_1, :CampaignAdExtensionService] => 'cm/',
168
+ [:v201109_1, :CampaignCriterionService] => 'cm/',
169
+ [:v201109_1, :CampaignService] => 'cm/',
170
+ [:v201109_1, :CampaignTargetService] => 'cm/',
171
+ [:v201109_1, :ConstantDataService] => 'cm/',
172
+ [:v201109_1, :ConversionTrackerService] => 'cm/',
173
+ [:v201109_1, :CreateAccountService] => 'mcm/',
174
+ [:v201109_1, :CustomerSyncService] => 'ch/',
175
+ [:v201109_1, :DataService] => 'cm/',
176
+ [:v201109_1, :ExperimentService] => 'cm/',
177
+ [:v201109_1, :GeoLocationService] => 'cm/',
178
+ [:v201109_1, :InfoService] => 'info/',
179
+ [:v201109_1, :LocationCriterionService] => 'cm/',
180
+ [:v201109_1, :MediaService] => 'cm/',
181
+ [:v201109_1, :MutateJobService] => 'cm/',
182
+ [:v201109_1, :ReportDefinitionService] => 'cm/',
183
+ [:v201109_1, :ServicedAccountService] => 'mcm/',
184
+ [:v201109_1, :TargetingIdeaService] => 'o/',
185
+ [:v201109_1, :TrafficEstimatorService] => 'o/',
186
+ [:v201109_1, :UserListService] => 'cm/'
124
187
  }
125
188
 
126
- # Configure the auth servers to use for each environment
127
- @@auth_server_config = {
128
- :PRODUCTION => 'https://www.google.com',
129
- :SANDBOX => 'https://www.google.com'
130
- }
131
-
132
- @@headers_config = {
133
- :REQUEST_HEADER => 'RequestHeader',
189
+ # Auth constants for ClientLogin method.
190
+ @@client_login_config = {
191
+ :AUTH_SERVER => 'https://www.google.com',
134
192
  :AUTH_NAMESPACE_PREAMBLE =>
135
193
  'https://adwords.google.com/api/adwords/cm/',
136
194
  :LOGIN_SERVICE_NAME => 'adwords'
@@ -159,16 +217,17 @@ module AdwordsApi
159
217
  @@service_config
160
218
  end
161
219
 
162
- def self.environment_config
163
- @@environment_config
220
+ def self.environment_config(environment, key)
221
+ return @@environment_config.include?(environment) ?
222
+ @@environment_config[environment][key] : nil
164
223
  end
165
224
 
166
225
  def self.subdir_config
167
226
  @@subdir_config
168
227
  end
169
228
 
170
- def self.auth_server_config
171
- @@auth_server_config
229
+ def self.client_login_config(key)
230
+ return @@client_login_config[key]
172
231
  end
173
232
 
174
233
  def self.default_config_filename
@@ -179,23 +238,6 @@ module AdwordsApi
179
238
  @@headers_config
180
239
  end
181
240
 
182
- # Get the download URL for reports.
183
- #
184
- # Args:
185
- # - environment: the service environment to be used
186
- # - version: the API version (as a symbol)
187
- #
188
- # Returns:
189
- # - The endpoint URL (as a string)
190
- #
191
- def self.report_download_url(environment, version)
192
- base = get_wsdl_base(environment, version)
193
- if base and service_config[version].include?(:ReportDefinitionService)
194
- base += 'reportdownload'
195
- end
196
- return base
197
- end
198
-
199
241
  # Get the download URL for Ad Hoc reports.
200
242
  #
201
243
  # Args:
@@ -19,10 +19,10 @@
19
19
  #
20
20
  # Handles SOAP headers and namespaces definition for ClientLogin type header.
21
21
 
22
- require 'ads_common/savon_headers/simple_header_handler'
22
+ require 'ads_common/savon_headers/base_header_handler'
23
23
 
24
24
  module AdwordsApi
25
- class ClientLoginHeaderHandler < AdsCommon::SavonHeaders::SimpleHeaderHandler
25
+ class ClientLoginHeaderHandler < AdsCommon::SavonHeaders::BaseHeaderHandler
26
26
  # Initializes a header handler.
27
27
  #
28
28
  # Args:
@@ -33,9 +33,9 @@ module AdwordsApi
33
33
  # - auth_namespace: namespace to use for auth headers
34
34
  # - version: services version
35
35
  #
36
- def initialize(credential_handler, auth_handler, element_name,
37
- namespace, auth_namespace, version)
38
- super(credential_handler, auth_handler, element_name, namespace, version)
36
+ def initialize(credential_handler, auth_handler, namespace, auth_namespace,
37
+ version)
38
+ super(credential_handler, auth_handler, namespace, version)
39
39
  @auth_namespace = auth_namespace
40
40
  end
41
41
 
@@ -51,32 +51,15 @@ module AdwordsApi
51
51
  # Returns:
52
52
  # - Modified soap structure
53
53
  #
54
- def prepare_request(request, soap, args)
55
- super(request, soap, args)
54
+ def prepare_request(request, soap)
55
+ super(request, soap)
56
56
  soap.header[:attributes!] ||= {}
57
- header_name = prepend_namespace(@element_name)
57
+ header_name = prepend_namespace(get_header_element_name())
58
58
  soap.header[:attributes!][header_name] ||= {}
59
59
  soap.header[:attributes!][header_name]['xmlns'] = @auth_namespace
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
-
80
63
  # Skips namespace prefixes for all elements except top level. Use default
81
64
  # (inherited) prefixing for the top level key.
82
65
  #
@@ -87,7 +70,15 @@ module AdwordsApi
87
70
  # - String with a namespace
88
71
  #
89
72
  def prepend_namespace(str)
90
- return str.equal?(@element_name) ? super(str) : str
73
+ return get_header_element_name().eql?(str) ? super(str) : str
74
+ end
75
+
76
+ # Generates AdWords API specific request header with ClientLogin data.
77
+ def generate_request_header()
78
+ request_header = super()
79
+ credentials = @credential_handler.credentials
80
+ request_header['authToken'] = @auth_handler.get_token(credentials)
81
+ return request_header
91
82
  end
92
83
  end
93
84
  end
@@ -1,7 +1,6 @@
1
1
  # Encoding: utf-8
2
2
  #
3
- # Authors:: api.sgomes@gmail.com (Sérgio Gomes)
4
- # api.dklimkin@gmail.com (Danial Klimkin)
3
+ # Authors:: api.dklimkin@gmail.com (Danial Klimkin)
5
4
  #
6
5
  # Copyright:: Copyright 2010, Google Inc. All Rights Reserved.
7
6
  #
@@ -41,42 +40,27 @@ module AdwordsApi
41
40
 
42
41
  # Create the list of credentials to be used by the auth handler for header
43
42
  # generation.
44
- def credentials(version = nil)
45
- validate_headers_for_server(version)
46
- result = case @credentials[:method]
47
- when :CLIENTLOGIN
48
- {:email => @credentials[:email],
49
- :password => @credentials[:password],
50
- :logintoken => @credentials[:logintoken],
51
- :logincaptcha => @credentials[:logincaptcha]}
52
- when :OAUTH
53
- {:oauth_consumer_key => @credentials[:oauth_consumer_key],
54
- :oauth_consumer_secret => @credentials[:oauth_consumer_secret],
55
- :oauth_verification_code => @credentials[:oauth_verification_code],
56
- :oauth_token => @credentials[:oauth_token],
57
- :oauth_token_secret => @credentials[:oauth_token_secret],
58
- :oauth_callback => @credentials[:oauth_callback],
59
- :oauth_method => @credentials[:oauth_method],
60
- :oauth_request_token => @credentials[:oauth_request_token]}
61
- end
62
- client_lib = 'AwApi-Ruby-%s|' % AdwordsApi::ApiConfig::CLIENT_LIB_VERSION
63
- user_agent = @credentials[:user_agent] || $0
64
- user_agent = client_lib + user_agent
65
- user_agent_symbol = (version == :v13) ? :useragent : :userAgent
66
- result[user_agent_symbol] = user_agent
67
- result[:developerToken] = @credentials[:developer_token]
68
- unless @use_mcc
69
- if @credentials[:client_customer_id]
70
- result[:clientCustomerId] = @credentials[:client_customer_id]
71
- elsif @credentials[:client_email] and version != :v201109
72
- result[:clientEmail] = @credentials[:client_email]
73
- end
74
- end
75
- if version != :v13
76
- result[:validateOnly] = 'true' if @validate_only
77
- result[:partialFailure] = 'true' if @partial_failure
43
+ def credentials(credentials_override = nil)
44
+ result = super(credentials_override)
45
+ validate_headers_for_server(result)
46
+
47
+ extra_headers = {
48
+ 'userAgent' => generate_soap_user_agent(),
49
+ 'developerToken' => result[:developer_token]
50
+ }
51
+ if !@use_mcc and result[:client_customer_id]
52
+ extra_headers['clientCustomerId'] = result[:client_customer_id]
78
53
  end
79
- return result.reject {|k,v| v.nil?}
54
+ extra_headers['validateOnly'] = 'true' if @validate_only
55
+ extra_headers['partialFailure'] = 'true' if @partial_failure
56
+ result[:extra_headers] = extra_headers
57
+ return result
58
+ end
59
+
60
+ # Generates string to user as user agent in SOAP headers.
61
+ def generate_soap_user_agent(extra_ids = [])
62
+ extra_ids << ["AwApi-Ruby-%s" % AdwordsApi::ApiConfig::CLIENT_LIB_VERSION]
63
+ super(extra_ids)
80
64
  end
81
65
 
82
66
  private
@@ -84,25 +68,19 @@ module AdwordsApi
84
68
  # Validates that the right credentials are being used for the chosen
85
69
  # environment.
86
70
  #
87
- # Args:
88
- # - version: API version to validate for
89
- #
90
71
  # Raises:
91
72
  # - AdsCommon::Error::EnvironmentMismatchError if sandbox credentials are
92
73
  # being used for production or vice-versa.
93
74
  # - AdwordsApi::Errors:BadCredentialsError if supplied credentials are not
94
75
  # valid.
95
76
  #
96
- def validate_headers_for_server(version)
97
- token = @credentials[:developer_token]
98
- client_email = @credentials[:client_email]
99
-
100
- if client_email and version == :v201109
77
+ def validate_headers_for_server(credentials)
78
+ if credentials[:client_email]
101
79
  raise AdwordsApi::Errors::BadCredentialsError, 'Deprecated header ' +
102
80
  'clientEmail is no longer supported, please use clientCustomerId'
103
81
  end
104
82
 
105
- client_customer_id = @credentials[:client_customer_id]
83
+ client_customer_id = credentials[:client_customer_id]
106
84
  if client_customer_id and
107
85
  !(client_customer_id.is_a?(Integer) or
108
86
  (client_customer_id =~ /^\d+(-\d+-\d+)?$/))
@@ -110,35 +88,21 @@ module AdwordsApi
110
88
  'Invalid client customer ID: %s' % client_customer_id.to_s
111
89
  end
112
90
 
113
- (sandbox_token, sandbox_client) = case @credentials[:method]
114
- when :CLIENTLOGIN
115
- email = @credentials[:email]
116
- [(token =~ /#{Regexp.escape(email)}\+\+[a-zA-Z]{3}/),
117
- (client_email =~ /client_[1-5]\+#{Regexp.escape(email)}/)]
118
- when :OAUTH
119
- [(token =~ /.+@.+\+\+[a-zA-Z]{3}/),
120
- (client_email =~ /client_[1-5]\+.+@.+/)]
121
- else
122
- [nil, nil]
123
- end
91
+ token = credentials[:developer_token]
92
+ sandbox_token = (token =~ /.+@.+\+\+[a-zA-Z]{3}/)
124
93
  environment = @config.read('service.environment')
125
94
  case environment
126
95
  when :PRODUCTION
127
- # Only check the token, because 'client_n+x@y.tld' may be a valid
128
- # client email for some customers.
129
96
  if sandbox_token
130
97
  raise AdsCommon::Errors::EnvironmentMismatchError,
131
98
  'Attempting to connect to production with sandbox credentials.'
132
99
  end
133
100
  when :SANDBOX
134
- # Check if either the token or client email do not follow the
135
- # correct format. Client email may not exist, though.
136
- if (!sandbox_token or (client_email and !sandbox_client))
101
+ if (!sandbox_token)
137
102
  raise AdsCommon::Errors::EnvironmentMismatchError,
138
103
  'Attempting to connect to the sandbox with malformatted ' +
139
- 'credentials. Please check ' +
140
- 'http://code.google.com/apis/adwords/docs/developer/' +
141
- 'adwords_api_sandbox.html#requestheaders for details.'
104
+ 'credentials. Please check http://code.google.com/apis/' +
105
+ 'adwords/docs/sandbox.html#request-headers for details.'
142
106
  end
143
107
  end
144
108
  return nil
@@ -0,0 +1,65 @@
1
+ # Encoding: utf-8
2
+ #
3
+ # Authors:: api.dklimkin@gmail.com (Danial Klimkin)
4
+ #
5
+ # Copyright:: Copyright 2012, 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
+ # Handles HTTP headers for AdHoc reporting requests.
21
+
22
+ module AdwordsApi
23
+ class ReportHeaderHandler
24
+
25
+ # Initializes a header handler.
26
+ #
27
+ # Args:
28
+ # - credential_handler: a header with credential data
29
+ # - auth_handler: a header with auth data
30
+ # - config: API config
31
+ #
32
+ def initialize(credential_handler, auth_handler, config)
33
+ @credential_handler = credential_handler
34
+ @auth_handler = auth_handler
35
+ @config = config
36
+ end
37
+
38
+ # Returns the headers set for the report request.
39
+ #
40
+ # Args:
41
+ # - url: URL for the report requests
42
+ # - cid: clientCustomerId to use
43
+ #
44
+ # Returns:
45
+ # - a Hash with HTTP headers.
46
+ #
47
+ def headers(url, cid)
48
+ override = (cid.nil?) ? nil : {:client_customer_id => cid}
49
+ credentials = @credential_handler.credentials(override)
50
+ headers = {
51
+ 'Content-Type' => 'application/x-www-form-urlencoded',
52
+ 'Authorization' =>
53
+ @auth_handler.auth_string(credentials, HTTPI::Request.new(url)),
54
+ 'clientCustomerId' => credentials[:client_customer_id],
55
+ 'developerToken' => credentials[:developer_token],
56
+ 'userAgent' => @credential_handler.generate_http_user_agent()
57
+ }
58
+ money_in_micros = @config.read('library.return_money_in_micros')
59
+ unless money_in_micros.nil?
60
+ headers['returnMoneyInMicros'] = money_in_micros
61
+ end
62
+ return headers
63
+ end
64
+ end
65
+ end
@@ -21,10 +21,10 @@
21
21
 
22
22
  require 'cgi'
23
23
  require 'gyoku'
24
- require 'httpi/request'
25
24
 
26
25
  require 'ads_common/http'
27
26
  require 'adwords_api/errors'
27
+ require 'adwords_api/report_header_handler'
28
28
 
29
29
  module AdwordsApi
30
30
  class ReportUtils
@@ -101,6 +101,7 @@ module AdwordsApi
101
101
  url = @api.api_config.adhoc_report_download_url(
102
102
  @api.config.read('service.environment'), @version)
103
103
  headers = get_report_request_headers(url, cid)
104
+ log_request(url, headers, definition_text)
104
105
  response = AdsCommon::Http.post_response(url, data, @api.config, headers)
105
106
  check_for_errors(response)
106
107
  return response
@@ -121,29 +122,9 @@ module AdwordsApi
121
122
 
122
123
  # Prepares headers for report request.
123
124
  def get_report_request_headers(url, cid)
124
- credentials = @api.credential_handler.credentials
125
- auth_handler = @api.get_auth_handler(
126
- @api.config.read('service.environment'), @version)
127
- auth_string = auth_handler.auth_string(
128
- credentials, HTTPI::Request.new(url))
129
- customer_id = validate_cid(cid || credentials[:clientCustomerId])
130
- app_name = credentials[:userAgent] || credentials[:useragent]
131
- headers = {
132
- 'Authorization' => auth_string,
133
- 'ClientCustomerId' => customer_id,
134
- 'Content-Type' => 'application/x-www-form-urlencoded',
135
- 'developerToken' => credentials[:developerToken],
136
- 'User-Agent' => "HTTPI/%s (%s)" % [HTTPI::VERSION, app_name]
137
- }
138
- if @api.config.read('connection.enable_gzip', false)
139
- headers['User-Agent'] += ' (gzip)'
140
- headers['Accept-Encoding'] = 'gzip,deflate'
141
- end
142
- money_in_micros = @api.config.read('library.return_money_in_micros')
143
- unless money_in_micros.nil?
144
- headers['returnMoneyInMicros'] = money_in_micros
145
- end
146
- return headers
125
+ @header_handler ||= AdwordsApi::ReportHeaderHandler.new(
126
+ @api.credential_handler, @api.get_auth_handler(), @api.config)
127
+ return @header_handler.headers(url, cid)
147
128
  end
148
129
 
149
130
  # Saves raw data to a file.
@@ -151,18 +132,13 @@ module AdwordsApi
151
132
  open(path, 'wb') { |file| file.write(data) } if path
152
133
  end
153
134
 
154
- # Validates the customer ID specified is correct.
155
- def validate_cid(cid)
156
- if (cid.kind_of?(Integer) || (
157
- cid.kind_of?(String) && (
158
- ((/\d{3}-\d{3}-\d{4}/ =~ cid) == 0) ||
159
- ((/\d{10}/ =~ cid) == 0)
160
- )))
161
- return cid
162
- else
163
- raise AdwordsApi::Errors::BadCredentialsError,
164
- "Invalid client customer ID: %s" % cid
165
- end
135
+ # Logs the request on debug level.
136
+ def log_request(url, headers, body)
137
+ logger = @api.logger
138
+ logger.debug("Report request to: '%s'" % url)
139
+ logger.debug("HTTP headers: [%s]" %
140
+ (headers.map {|k, v| [k, v].join(': ')}.join(', ')))
141
+ logger.debug(body)
166
142
  end
167
143
 
168
144
  # Checks downloaded data for error signature. Raises ReportError if it