google-adwords-api 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (201) hide show
  1. data/ChangeLog +4 -0
  2. data/examples/v201109/misc/get_all_images_and_videos.rb +3 -4
  3. data/examples/v201109/misc/upload_image.rb +6 -7
  4. data/examples/v201109/optimization/get_keyword_ideas.rb +1 -2
  5. data/examples/v201109/optimization/get_placement_ideas.rb +1 -3
  6. data/examples/v201109_1/misc/get_all_images_and_videos.rb +3 -4
  7. data/examples/v201109_1/misc/upload_image.rb +6 -7
  8. data/examples/v201109_1/optimization/get_keyword_ideas.rb +1 -2
  9. data/examples/v201109_1/optimization/get_placement_ideas.rb +1 -3
  10. data/examples/v201206/misc/get_all_images_and_videos.rb +3 -4
  11. data/examples/v201206/misc/upload_image.rb +6 -7
  12. data/examples/v201206/optimization/get_keyword_ideas.rb +1 -2
  13. data/examples/v201206/optimization/get_placement_ideas.rb +1 -3
  14. data/examples/v201206/reporting/parallel_report_download.rb +12 -12
  15. data/lib/adwords_api.rb +9 -13
  16. data/lib/adwords_api/api_config.rb +2 -3
  17. data/lib/adwords_api/client_login_header_handler.rb +0 -47
  18. data/lib/adwords_api/credential_handler.rb +5 -17
  19. data/lib/adwords_api/errors.rb +7 -2
  20. data/lib/adwords_api/report_header_handler.rb +1 -1
  21. data/lib/adwords_api/utils.rb +0 -16
  22. data/lib/adwords_api/v201109/ad_extension_override_service.rb +1 -1
  23. data/lib/adwords_api/v201109/ad_extension_override_service_registry.rb +3 -3
  24. data/lib/adwords_api/v201109/ad_group_ad_service.rb +1 -1
  25. data/lib/adwords_api/v201109/ad_group_ad_service_registry.rb +3 -3
  26. data/lib/adwords_api/v201109/ad_group_criterion_service.rb +1 -1
  27. data/lib/adwords_api/v201109/ad_group_criterion_service_registry.rb +3 -3
  28. data/lib/adwords_api/v201109/ad_group_service.rb +1 -1
  29. data/lib/adwords_api/v201109/ad_group_service_registry.rb +3 -3
  30. data/lib/adwords_api/v201109/ad_param_service.rb +1 -1
  31. data/lib/adwords_api/v201109/ad_param_service_registry.rb +3 -3
  32. data/lib/adwords_api/v201109/alert_service.rb +1 -1
  33. data/lib/adwords_api/v201109/alert_service_registry.rb +3 -3
  34. data/lib/adwords_api/v201109/budget_order_service.rb +1 -1
  35. data/lib/adwords_api/v201109/budget_order_service_registry.rb +3 -3
  36. data/lib/adwords_api/v201109/bulk_mutate_job_service.rb +1 -1
  37. data/lib/adwords_api/v201109/bulk_mutate_job_service_registry.rb +3 -3
  38. data/lib/adwords_api/v201109/campaign_ad_extension_service.rb +1 -1
  39. data/lib/adwords_api/v201109/campaign_ad_extension_service_registry.rb +3 -3
  40. data/lib/adwords_api/v201109/campaign_criterion_service.rb +1 -1
  41. data/lib/adwords_api/v201109/campaign_criterion_service_registry.rb +3 -3
  42. data/lib/adwords_api/v201109/campaign_service.rb +1 -1
  43. data/lib/adwords_api/v201109/campaign_service_registry.rb +3 -3
  44. data/lib/adwords_api/v201109/campaign_target_service.rb +1 -1
  45. data/lib/adwords_api/v201109/campaign_target_service_registry.rb +3 -3
  46. data/lib/adwords_api/v201109/constant_data_service.rb +1 -1
  47. data/lib/adwords_api/v201109/constant_data_service_registry.rb +3 -3
  48. data/lib/adwords_api/v201109/conversion_tracker_service.rb +1 -1
  49. data/lib/adwords_api/v201109/conversion_tracker_service_registry.rb +3 -3
  50. data/lib/adwords_api/v201109/create_account_service.rb +1 -1
  51. data/lib/adwords_api/v201109/create_account_service_registry.rb +3 -3
  52. data/lib/adwords_api/v201109/customer_sync_service.rb +1 -1
  53. data/lib/adwords_api/v201109/customer_sync_service_registry.rb +3 -3
  54. data/lib/adwords_api/v201109/data_service.rb +1 -1
  55. data/lib/adwords_api/v201109/data_service_registry.rb +3 -3
  56. data/lib/adwords_api/v201109/experiment_service.rb +1 -1
  57. data/lib/adwords_api/v201109/experiment_service_registry.rb +3 -3
  58. data/lib/adwords_api/v201109/geo_location_service.rb +1 -1
  59. data/lib/adwords_api/v201109/geo_location_service_registry.rb +3 -3
  60. data/lib/adwords_api/v201109/info_service.rb +1 -1
  61. data/lib/adwords_api/v201109/info_service_registry.rb +3 -3
  62. data/lib/adwords_api/v201109/location_criterion_service.rb +1 -1
  63. data/lib/adwords_api/v201109/location_criterion_service_registry.rb +3 -3
  64. data/lib/adwords_api/v201109/media_service.rb +1 -1
  65. data/lib/adwords_api/v201109/media_service_registry.rb +3 -3
  66. data/lib/adwords_api/v201109/mutate_job_service.rb +1 -1
  67. data/lib/adwords_api/v201109/mutate_job_service_registry.rb +3 -3
  68. data/lib/adwords_api/v201109/report_definition_service.rb +1 -1
  69. data/lib/adwords_api/v201109/report_definition_service_registry.rb +3 -3
  70. data/lib/adwords_api/v201109/serviced_account_service.rb +1 -1
  71. data/lib/adwords_api/v201109/serviced_account_service_registry.rb +3 -3
  72. data/lib/adwords_api/v201109/targeting_idea_service.rb +1 -1
  73. data/lib/adwords_api/v201109/targeting_idea_service_registry.rb +3 -3
  74. data/lib/adwords_api/v201109/traffic_estimator_service.rb +1 -1
  75. data/lib/adwords_api/v201109/traffic_estimator_service_registry.rb +3 -3
  76. data/lib/adwords_api/v201109/user_list_service.rb +1 -1
  77. data/lib/adwords_api/v201109/user_list_service_registry.rb +3 -3
  78. data/lib/adwords_api/v201109_1/ad_extension_override_service.rb +1 -1
  79. data/lib/adwords_api/v201109_1/ad_extension_override_service_registry.rb +3 -3
  80. data/lib/adwords_api/v201109_1/ad_group_ad_service.rb +1 -1
  81. data/lib/adwords_api/v201109_1/ad_group_ad_service_registry.rb +3 -3
  82. data/lib/adwords_api/v201109_1/ad_group_criterion_service.rb +1 -1
  83. data/lib/adwords_api/v201109_1/ad_group_criterion_service_registry.rb +3 -3
  84. data/lib/adwords_api/v201109_1/ad_group_service.rb +1 -1
  85. data/lib/adwords_api/v201109_1/ad_group_service_registry.rb +3 -3
  86. data/lib/adwords_api/v201109_1/ad_param_service.rb +1 -1
  87. data/lib/adwords_api/v201109_1/ad_param_service_registry.rb +3 -3
  88. data/lib/adwords_api/v201109_1/alert_service.rb +1 -1
  89. data/lib/adwords_api/v201109_1/alert_service_registry.rb +3 -3
  90. data/lib/adwords_api/v201109_1/budget_order_service.rb +1 -1
  91. data/lib/adwords_api/v201109_1/budget_order_service_registry.rb +3 -3
  92. data/lib/adwords_api/v201109_1/bulk_mutate_job_service.rb +1 -1
  93. data/lib/adwords_api/v201109_1/bulk_mutate_job_service_registry.rb +3 -3
  94. data/lib/adwords_api/v201109_1/campaign_ad_extension_service.rb +1 -1
  95. data/lib/adwords_api/v201109_1/campaign_ad_extension_service_registry.rb +3 -3
  96. data/lib/adwords_api/v201109_1/campaign_criterion_service.rb +1 -1
  97. data/lib/adwords_api/v201109_1/campaign_criterion_service_registry.rb +3 -3
  98. data/lib/adwords_api/v201109_1/campaign_service.rb +1 -1
  99. data/lib/adwords_api/v201109_1/campaign_service_registry.rb +3 -3
  100. data/lib/adwords_api/v201109_1/campaign_target_service.rb +1 -1
  101. data/lib/adwords_api/v201109_1/campaign_target_service_registry.rb +3 -3
  102. data/lib/adwords_api/v201109_1/constant_data_service.rb +1 -1
  103. data/lib/adwords_api/v201109_1/constant_data_service_registry.rb +3 -3
  104. data/lib/adwords_api/v201109_1/conversion_tracker_service.rb +1 -1
  105. data/lib/adwords_api/v201109_1/conversion_tracker_service_registry.rb +3 -3
  106. data/lib/adwords_api/v201109_1/create_account_service.rb +1 -1
  107. data/lib/adwords_api/v201109_1/create_account_service_registry.rb +3 -3
  108. data/lib/adwords_api/v201109_1/customer_service.rb +1 -1
  109. data/lib/adwords_api/v201109_1/customer_service_registry.rb +3 -3
  110. data/lib/adwords_api/v201109_1/customer_sync_service.rb +1 -1
  111. data/lib/adwords_api/v201109_1/customer_sync_service_registry.rb +3 -3
  112. data/lib/adwords_api/v201109_1/data_service.rb +1 -1
  113. data/lib/adwords_api/v201109_1/data_service_registry.rb +3 -3
  114. data/lib/adwords_api/v201109_1/experiment_service.rb +1 -1
  115. data/lib/adwords_api/v201109_1/experiment_service_registry.rb +3 -3
  116. data/lib/adwords_api/v201109_1/geo_location_service.rb +1 -1
  117. data/lib/adwords_api/v201109_1/geo_location_service_registry.rb +3 -3
  118. data/lib/adwords_api/v201109_1/info_service.rb +1 -1
  119. data/lib/adwords_api/v201109_1/info_service_registry.rb +3 -3
  120. data/lib/adwords_api/v201109_1/location_criterion_service.rb +1 -1
  121. data/lib/adwords_api/v201109_1/location_criterion_service_registry.rb +3 -3
  122. data/lib/adwords_api/v201109_1/managed_customer_service.rb +1 -1
  123. data/lib/adwords_api/v201109_1/managed_customer_service_registry.rb +3 -3
  124. data/lib/adwords_api/v201109_1/media_service.rb +1 -1
  125. data/lib/adwords_api/v201109_1/media_service_registry.rb +3 -3
  126. data/lib/adwords_api/v201109_1/mutate_job_service.rb +1 -1
  127. data/lib/adwords_api/v201109_1/mutate_job_service_registry.rb +3 -3
  128. data/lib/adwords_api/v201109_1/report_definition_service.rb +1 -1
  129. data/lib/adwords_api/v201109_1/report_definition_service_registry.rb +3 -3
  130. data/lib/adwords_api/v201109_1/serviced_account_service.rb +1 -1
  131. data/lib/adwords_api/v201109_1/serviced_account_service_registry.rb +3 -3
  132. data/lib/adwords_api/v201109_1/targeting_idea_service.rb +1 -1
  133. data/lib/adwords_api/v201109_1/targeting_idea_service_registry.rb +3 -3
  134. data/lib/adwords_api/v201109_1/traffic_estimator_service.rb +1 -1
  135. data/lib/adwords_api/v201109_1/traffic_estimator_service_registry.rb +3 -3
  136. data/lib/adwords_api/v201109_1/user_list_service.rb +1 -1
  137. data/lib/adwords_api/v201109_1/user_list_service_registry.rb +3 -3
  138. data/lib/adwords_api/v201206/ad_extension_override_service.rb +1 -1
  139. data/lib/adwords_api/v201206/ad_extension_override_service_registry.rb +3 -3
  140. data/lib/adwords_api/v201206/ad_group_ad_service.rb +1 -1
  141. data/lib/adwords_api/v201206/ad_group_ad_service_registry.rb +3 -3
  142. data/lib/adwords_api/v201206/ad_group_criterion_service.rb +1 -1
  143. data/lib/adwords_api/v201206/ad_group_criterion_service_registry.rb +3 -3
  144. data/lib/adwords_api/v201206/ad_group_service.rb +1 -1
  145. data/lib/adwords_api/v201206/ad_group_service_registry.rb +3 -3
  146. data/lib/adwords_api/v201206/ad_param_service.rb +1 -1
  147. data/lib/adwords_api/v201206/ad_param_service_registry.rb +3 -3
  148. data/lib/adwords_api/v201206/alert_service.rb +1 -1
  149. data/lib/adwords_api/v201206/alert_service_registry.rb +3 -3
  150. data/lib/adwords_api/v201206/budget_order_service.rb +1 -1
  151. data/lib/adwords_api/v201206/budget_order_service_registry.rb +3 -3
  152. data/lib/adwords_api/v201206/bulk_mutate_job_service.rb +1 -1
  153. data/lib/adwords_api/v201206/bulk_mutate_job_service_registry.rb +3 -3
  154. data/lib/adwords_api/v201206/campaign_ad_extension_service.rb +1 -1
  155. data/lib/adwords_api/v201206/campaign_ad_extension_service_registry.rb +3 -3
  156. data/lib/adwords_api/v201206/campaign_criterion_service.rb +1 -1
  157. data/lib/adwords_api/v201206/campaign_criterion_service_registry.rb +3 -3
  158. data/lib/adwords_api/v201206/campaign_service.rb +1 -1
  159. data/lib/adwords_api/v201206/campaign_service_registry.rb +3 -3
  160. data/lib/adwords_api/v201206/constant_data_service.rb +1 -1
  161. data/lib/adwords_api/v201206/constant_data_service_registry.rb +3 -3
  162. data/lib/adwords_api/v201206/conversion_tracker_service.rb +1 -1
  163. data/lib/adwords_api/v201206/conversion_tracker_service_registry.rb +3 -3
  164. data/lib/adwords_api/v201206/customer_service.rb +1 -1
  165. data/lib/adwords_api/v201206/customer_service_registry.rb +3 -3
  166. data/lib/adwords_api/v201206/customer_sync_service.rb +1 -1
  167. data/lib/adwords_api/v201206/customer_sync_service_registry.rb +3 -3
  168. data/lib/adwords_api/v201206/data_service.rb +1 -1
  169. data/lib/adwords_api/v201206/data_service_registry.rb +3 -3
  170. data/lib/adwords_api/v201206/experiment_service.rb +1 -1
  171. data/lib/adwords_api/v201206/experiment_service_registry.rb +3 -3
  172. data/lib/adwords_api/v201206/geo_location_service.rb +1 -1
  173. data/lib/adwords_api/v201206/geo_location_service_registry.rb +3 -3
  174. data/lib/adwords_api/v201206/info_service.rb +1 -1
  175. data/lib/adwords_api/v201206/info_service_registry.rb +3 -3
  176. data/lib/adwords_api/v201206/location_criterion_service.rb +1 -1
  177. data/lib/adwords_api/v201206/location_criterion_service_registry.rb +3 -3
  178. data/lib/adwords_api/v201206/managed_customer_service.rb +1 -1
  179. data/lib/adwords_api/v201206/managed_customer_service_registry.rb +3 -3
  180. data/lib/adwords_api/v201206/media_service.rb +1 -1
  181. data/lib/adwords_api/v201206/media_service_registry.rb +3 -3
  182. data/lib/adwords_api/v201206/mutate_job_service.rb +1 -1
  183. data/lib/adwords_api/v201206/mutate_job_service_registry.rb +3 -3
  184. data/lib/adwords_api/v201206/report_definition_service.rb +1 -1
  185. data/lib/adwords_api/v201206/report_definition_service_registry.rb +3 -3
  186. data/lib/adwords_api/v201206/targeting_idea_service.rb +1 -1
  187. data/lib/adwords_api/v201206/targeting_idea_service_registry.rb +3 -3
  188. data/lib/adwords_api/v201206/traffic_estimator_service.rb +1 -1
  189. data/lib/adwords_api/v201206/traffic_estimator_service_registry.rb +3 -3
  190. data/lib/adwords_api/v201206/user_list_service.rb +1 -1
  191. data/lib/adwords_api/v201206/user_list_service_registry.rb +3 -3
  192. data/lib/adwords_api/version.rb +1 -1
  193. data/test/adwords_api/test_utils.rb +0 -13
  194. data/test/examples/v201109/test_reporting.rb +0 -5
  195. data/test/examples/v201109/utils.rb +1 -2
  196. data/test/examples/v201109_1/test_reporting.rb +0 -5
  197. data/test/examples/v201109_1/utils.rb +1 -2
  198. data/test/examples/v201206/test_reporting.rb +0 -5
  199. data/test/examples/v201206/utils.rb +1 -2
  200. metadata +4 -5
  201. data/examples/v201206/reporting/get_defined_reports.rb +0 -75
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 0.7.0:
2
+ - MapEntry structures are returned as Hashes now (#26).
3
+ - Require google-ads-common 0.8.0 or later from now on.
4
+
1
5
  0.6.3:
2
6
  - Support and examples for v201206.
3
7
 
@@ -25,7 +25,6 @@
25
25
  # Tags: MediaService.get
26
26
 
27
27
  require 'adwords_api'
28
- require 'adwords_api/utils'
29
28
 
30
29
  def get_all_images_and_videos()
31
30
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -60,10 +59,10 @@ def get_all_images_and_videos()
60
59
  page = media_srv.get(selector)
61
60
  if page[:entries]
62
61
  page[:entries].each do |entry|
63
- dimensions = AdwordsApi::Utils.map(entry[:dimensions])
62
+ full_dimensions = entry[:dimensions]['FULL']
64
63
  puts "Entry ID %d with dimensions %dx%d and MIME type is '%s'" %
65
- [entry[:media_id], dimensions['FULL'][:height],
66
- dimensions['FULL'][:width], entry[:mime_type]]
64
+ [entry[:media_id], full_dimensions[:height],
65
+ full_dimensions[:width], entry[:mime_type]]
67
66
  end
68
67
  # Increment values to request the next page.
69
68
  offset += PAGE_SIZE
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Encoding: utf-8
3
3
  #
4
- # Author:: api.sgomes@gmail.com (Sérgio Gomes)
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
6
  # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
7
  #
@@ -23,7 +23,6 @@
23
23
  # Tags: MediaService.upload
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
  require 'base64'
28
27
 
29
28
  def upload_image()
@@ -57,12 +56,12 @@ def upload_image()
57
56
  response = media_srv.upload([image])
58
57
  if response and !response.empty?
59
58
  ret_image = response.first
60
- dimensions = AdwordsApi::Utils.map(ret_image[:dimensions])
61
- puts "Image with id #{ret_image[:media_id]}, dimensions " +
62
- "#{dimensions['FULL'][:height]}x#{dimensions['FULL'][:width]} " +
63
- "and MIME type \"#{ret_image[:mime_type]}\" uploaded successfully."
59
+ full_dimensions = ret_image[:dimensions]['FULL']
60
+ puts ("Image with ID %d, dimensions %dx%d and MIME type '%s' uploaded " +
61
+ "successfully.") % [ret_image[:media_id], full_dimensions[:height],
62
+ full_dimensions[:width], ret_image[:mime_type]]
64
63
  else
65
- puts "No images uploaded."
64
+ puts 'No images uploaded.'
66
65
  end
67
66
  end
68
67
 
@@ -23,7 +23,6 @@
23
23
  # Tags: TargetingIdeaService.get
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
 
28
27
  def get_keyword_ideas(keyword_text)
29
28
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -73,7 +72,7 @@ def get_keyword_ideas(keyword_text)
73
72
 
74
73
  # Display results.
75
74
  results.each do |result|
76
- data = AdwordsApi::Utils.map(result[:data])
75
+ data = result[:data]
77
76
  keyword = data['CRITERION'][:value]
78
77
  puts "Found keyword with text '%s' and match type '%s'" %
79
78
  [keyword[:text], keyword[:match_type]]
@@ -24,7 +24,6 @@
24
24
  # Tags: TargetingIdeaService.get
25
25
 
26
26
  require 'adwords_api'
27
- require 'adwords_api/utils'
28
27
 
29
28
  def get_placement_ideas(url)
30
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -72,8 +71,7 @@ def get_placement_ideas(url)
72
71
 
73
72
  # Display results.
74
73
  results.each do |result|
75
- data = AdwordsApi::Utils.map(result[:data])
76
- placement = data['CRITERION'][:value]
74
+ placement = result[:data]['CRITERION'][:value]
77
75
  puts "Related placement found at URL [%s]" % placement[:url]
78
76
  end
79
77
  puts "Total URLs found with keywords related to keywords at [%s]: %d." %
@@ -25,7 +25,6 @@
25
25
  # Tags: MediaService.get
26
26
 
27
27
  require 'adwords_api'
28
- require 'adwords_api/utils'
29
28
 
30
29
  def get_all_images_and_videos()
31
30
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -60,10 +59,10 @@ def get_all_images_and_videos()
60
59
  page = media_srv.get(selector)
61
60
  if page[:entries]
62
61
  page[:entries].each do |entry|
63
- dimensions = AdwordsApi::Utils.map(entry[:dimensions])
62
+ full_dimensions = entry[:dimensions]['FULL']
64
63
  puts "Entry ID %d with dimensions %dx%d and MIME type is '%s'" %
65
- [entry[:media_id], dimensions['FULL'][:height],
66
- dimensions['FULL'][:width], entry[:mime_type]]
64
+ [entry[:media_id], full_dimensions[:height],
65
+ full_dimensions[:width], entry[:mime_type]]
67
66
  end
68
67
  # Increment values to request the next page.
69
68
  offset += PAGE_SIZE
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Encoding: utf-8
3
3
  #
4
- # Author:: api.sgomes@gmail.com (Sérgio Gomes)
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
6
  # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
7
  #
@@ -23,7 +23,6 @@
23
23
  # Tags: MediaService.upload
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
  require 'base64'
28
27
 
29
28
  def upload_image()
@@ -57,12 +56,12 @@ def upload_image()
57
56
  response = media_srv.upload([image])
58
57
  if response and !response.empty?
59
58
  ret_image = response.first
60
- dimensions = AdwordsApi::Utils.map(ret_image[:dimensions])
61
- puts "Image with id #{ret_image[:media_id]}, dimensions " +
62
- "#{dimensions['FULL'][:height]}x#{dimensions['FULL'][:width]} " +
63
- "and MIME type \"#{ret_image[:mime_type]}\" uploaded successfully."
59
+ full_dimensions = ret_image[:dimensions]['FULL']
60
+ puts ("Image with ID %d, dimensions %dx%d and MIME type '%s' uploaded " +
61
+ "successfully.") % [ret_image[:media_id], full_dimensions[:height],
62
+ full_dimensions[:width], ret_image[:mime_type]]
64
63
  else
65
- puts "No images uploaded."
64
+ puts 'No images uploaded.'
66
65
  end
67
66
  end
68
67
 
@@ -23,7 +23,6 @@
23
23
  # Tags: TargetingIdeaService.get
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
 
28
27
  def get_keyword_ideas(keyword_text)
29
28
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -74,7 +73,7 @@ def get_keyword_ideas(keyword_text)
74
73
 
75
74
  # Display results.
76
75
  results.each do |result|
77
- data = AdwordsApi::Utils.map(result[:data])
76
+ data = result[:data]
78
77
  keyword = data['CRITERION'][:value]
79
78
  puts "Found keyword with text '%s' and match type '%s'" %
80
79
  [keyword[:text], keyword[:match_type]]
@@ -24,7 +24,6 @@
24
24
  # Tags: TargetingIdeaService.get
25
25
 
26
26
  require 'adwords_api'
27
- require 'adwords_api/utils'
28
27
 
29
28
  def get_placement_ideas(url)
30
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -72,8 +71,7 @@ def get_placement_ideas(url)
72
71
 
73
72
  # Display results.
74
73
  results.each do |result|
75
- data = AdwordsApi::Utils.map(result[:data])
76
- placement = data['CRITERION'][:value]
74
+ placement = result[:data]['CRITERION'][:value]
77
75
  puts "Related placement found at URL [%s]" % placement[:url]
78
76
  end
79
77
  puts "Total URLs found with keywords related to keywords at [%s]: %d." %
@@ -25,7 +25,6 @@
25
25
  # Tags: MediaService.get
26
26
 
27
27
  require 'adwords_api'
28
- require 'adwords_api/utils'
29
28
 
30
29
  def get_all_images_and_videos()
31
30
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -60,10 +59,10 @@ def get_all_images_and_videos()
60
59
  page = media_srv.get(selector)
61
60
  if page[:entries]
62
61
  page[:entries].each do |entry|
63
- dimensions = AdwordsApi::Utils.map(entry[:dimensions])
62
+ full_dimensions = entry[:dimensions]['FULL']
64
63
  puts "Entry ID %d with dimensions %dx%d and MIME type is '%s'" %
65
- [entry[:media_id], dimensions['FULL'][:height],
66
- dimensions['FULL'][:width], entry[:mime_type]]
64
+ [entry[:media_id], full_dimensions[:height],
65
+ full_dimensions[:width], entry[:mime_type]]
67
66
  end
68
67
  # Increment values to request the next page.
69
68
  offset += PAGE_SIZE
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Encoding: utf-8
3
3
  #
4
- # Author:: api.sgomes@gmail.com (Sérgio Gomes)
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
5
  #
6
6
  # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
7
  #
@@ -23,7 +23,6 @@
23
23
  # Tags: MediaService.upload
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
  require 'base64'
28
27
 
29
28
  def upload_image()
@@ -57,12 +56,12 @@ def upload_image()
57
56
  response = media_srv.upload([image])
58
57
  if response and !response.empty?
59
58
  ret_image = response.first
60
- dimensions = AdwordsApi::Utils.map(ret_image[:dimensions])
61
- puts "Image with id #{ret_image[:media_id]}, dimensions " +
62
- "#{dimensions['FULL'][:height]}x#{dimensions['FULL'][:width]} " +
63
- "and MIME type \"#{ret_image[:mime_type]}\" uploaded successfully."
59
+ full_dimensions = ret_image[:dimensions]['FULL']
60
+ puts ("Image with ID %d, dimensions %dx%d and MIME type '%s' uploaded " +
61
+ "successfully.") % [ret_image[:media_id], full_dimensions[:height],
62
+ full_dimensions[:width], ret_image[:mime_type]]
64
63
  else
65
- puts "No images uploaded."
64
+ puts 'No images uploaded.'
66
65
  end
67
66
  end
68
67
 
@@ -23,7 +23,6 @@
23
23
  # Tags: TargetingIdeaService.get
24
24
 
25
25
  require 'adwords_api'
26
- require 'adwords_api/utils'
27
26
 
28
27
  def get_keyword_ideas(keyword_text)
29
28
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -73,7 +72,7 @@ def get_keyword_ideas(keyword_text)
73
72
 
74
73
  # Display results.
75
74
  results.each do |result|
76
- data = AdwordsApi::Utils.map(result[:data])
75
+ data = result[:data]
77
76
  keyword = data['KEYWORD_TEXT'][:value]
78
77
  puts "Found keyword with text '%s'" % keyword
79
78
  products_and_services = data['CATEGORY_PRODUCTS_AND_SERVICES'][:value]
@@ -24,7 +24,6 @@
24
24
  # Tags: TargetingIdeaService.get
25
25
 
26
26
  require 'adwords_api'
27
- require 'adwords_api/utils'
28
27
 
29
28
  def get_placement_ideas(url)
30
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
@@ -72,8 +71,7 @@ def get_placement_ideas(url)
72
71
 
73
72
  # Display results.
74
73
  results.each do |result|
75
- data = AdwordsApi::Utils.map(result[:data])
76
- placement = data['CRITERION'][:value]
74
+ placement = result[:data]['CRITERION'][:value]
77
75
  puts "Related placement found at URL [%s]" % placement[:url]
78
76
  end
79
77
  puts "Total URLs found with keywords related to keywords at [%s]: %d." %
@@ -35,21 +35,21 @@ def parallel_report_download()
35
35
  # adwords.logger = Logger.new('adwords_xml.log')
36
36
 
37
37
  # Determine list of customer IDs to retrieve report for. For this example we
38
- # will use ServicedAccountService to get all IDs in hierarchy.
38
+ # will use ManagedCustomerService to get all IDs in hierarchy.
39
39
 
40
- serviced_account_srv = adwords.service(:ServicedAccountService, API_VERSION)
40
+ managed_customer_srv = adwords.service(:ManagedCustomerService, API_VERSION)
41
41
 
42
42
  # Get the account hierarchy for this account.
43
- selector = {:enable_paging => false}
43
+ selector = {:fields => ['CustomerId']}
44
44
 
45
45
  # Run the request at the MCC level.
46
- graph = adwords.use_mcc() {serviced_account_srv.get(selector)}
46
+ graph = adwords.use_mcc() {managed_customer_srv.get(selector)}
47
47
 
48
48
  # Using queue to balance load between threads.
49
49
  queue = Queue.new()
50
50
 
51
- if graph and graph[:accounts] and !graph[:accounts].empty?
52
- graph[:accounts].each {|account| queue << account[:customer_id]}
51
+ if graph and graph[:entries] and !graph[:entries].empty?
52
+ graph[:entries].each {|account| queue << account[:customer_id]}
53
53
  else
54
54
  raise StandardError, 'Can not retrieve any customer ID'
55
55
  end
@@ -76,7 +76,7 @@ def parallel_report_download()
76
76
  :include_zero_impressions => false
77
77
  }
78
78
 
79
- puts "Retrieving %d reports with %d threads:" % [queue.size, THREADS]
79
+ puts 'Retrieving %d reports with %d threads:' % [queue.size, THREADS]
80
80
 
81
81
  reports_succeeded = Queue.new()
82
82
  reports_failed = Queue.new()
@@ -92,7 +92,7 @@ def parallel_report_download()
92
92
  cid = queue_mutex.synchronize {(queue.empty?) ? nil : queue.pop(true)}
93
93
  if cid
94
94
  retry_count = 0
95
- file_name = "adgroup_%010d.csv" % cid
95
+ file_name = 'adgroup_%010d.csv' % cid
96
96
  puts "[%2d/%d] Loading report for customer ID %s into '%s'..." %
97
97
  [thread_id, retry_count,
98
98
  AdwordsApi::Utils.format_id(cid), file_name]
@@ -105,8 +105,8 @@ def parallel_report_download()
105
105
  sleep(retry_count * BACKOFF_FACTOR)
106
106
  retry
107
107
  else
108
- puts(("Report failed for customer ID %s with code %d after %d " +
109
- "retries.") % [cid, e.http_code, retry_count + 1])
108
+ puts(('Report failed for customer ID %s with code %d after %d ' +
109
+ 'retries.') % [cid, e.http_code, retry_count + 1])
110
110
  reports_failed <<
111
111
  {:cid => cid, :http_code => e.http_code, :message => e.message}
112
112
  end
@@ -150,10 +150,10 @@ if __FILE__ == $0
150
150
 
151
151
  # HTTP errors.
152
152
  rescue AdsCommon::Errors::HttpError => e
153
- puts "HTTP Error: %s" % e
153
+ puts 'HTTP Error: %s' % e
154
154
 
155
155
  # API errors.
156
156
  rescue AdwordsApi::Errors::ReportError => e
157
- puts "Reporting Error: %s" % e.message
157
+ puts 'Reporting Error: %s' % e.message
158
158
  end
159
159
  end
data/lib/adwords_api.rb CHANGED
@@ -54,24 +54,20 @@ module AdwordsApi
54
54
  # - auth_handler: instance of an AdsCommon::Auth::BaseHandler subclass to
55
55
  # handle authentication
56
56
  # - version: intended API version
57
- # - namespace: namespace to use as default for body
57
+ # - header_ns: header namespace
58
+ # - default_ns: default namespace
58
59
  #
59
60
  # Returns:
60
- # - a list of SOAP header handlers; one per provided header
61
+ # - SOAP header handler
61
62
  #
62
- def soap_header_handler(auth_handler, version, namespace)
63
+ def soap_header_handler(auth_handler, version, header_ns, default_ns)
63
64
  auth_method = @config.read('authentication.method', :CLIENTLOGIN)
64
- handler = case auth_method
65
- when :CLIENTLOGIN
66
- auth_ns = api_config.client_login_config(:AUTH_NAMESPACE_PREAMBLE) +
67
- version.to_s
68
- AdwordsApi::ClientLoginHeaderHandler.new(
69
- @credential_handler, auth_handler, namespace, auth_ns, version)
70
- when :OAUTH, :OAUTH2
71
- AdsCommon::SavonHeaders::OAuthHeaderHandler.new(
72
- @credential_handler, auth_handler, namespace, version)
65
+ handler_class = case auth_method
66
+ when :CLIENTLOGIN then AdwordsApi::ClientLoginHeaderHandler
67
+ when :OAUTH, :OAUTH2 then AdsCommon::SavonHeaders::OAuthHeaderHandler
73
68
  end
74
- return handler
69
+ return handler_class.new(@credential_handler, auth_handler, header_ns,
70
+ default_ns, version)
75
71
  end
76
72
 
77
73
  # Helper method to provide a simple way of doing an MCC-level operation
@@ -142,12 +142,14 @@ module AdwordsApi
142
142
  @@environment_config = {
143
143
  :PRODUCTION => {
144
144
  :oauth_scope => 'https://adwords.google.com/api/adwords/',
145
+ :header_ns => 'https://adwords.google.com/api/adwords/cm/',
145
146
  :v201109 => 'https://adwords.google.com/api/adwords/',
146
147
  :v201109_1 => 'https://adwords.google.com/api/adwords/',
147
148
  :v201206 => 'https://adwords.google.com/api/adwords/'
148
149
  },
149
150
  :SANDBOX => {
150
151
  :oauth_scope => 'https://adwords-sandbox.google.com/api/adwords/',
152
+ :header_ns => 'https://adwords.google.com/api/adwords/cm/',
151
153
  :v201109 => 'https://adwords-sandbox.google.com/api/adwords/',
152
154
  :v201109_1 => 'https://adwords-sandbox.google.com/api/adwords/',
153
155
  :v201206 => 'https://adwords-sandbox.google.com/api/adwords/'
@@ -240,7 +242,6 @@ module AdwordsApi
240
242
  [:v201206, :MediaService] => 'cm/',
241
243
  [:v201206, :MutateJobService] => 'cm/',
242
244
  [:v201206, :ReportDefinitionService] => 'cm/',
243
- [:v201206, :ServicedAccountService] => 'mcm/',
244
245
  [:v201206, :TargetingIdeaService] => 'o/',
245
246
  [:v201206, :TrafficEstimatorService] => 'o/',
246
247
  [:v201206, :UserListService] => 'cm/',
@@ -251,8 +252,6 @@ module AdwordsApi
251
252
  # Auth constants for ClientLogin method.
252
253
  @@client_login_config = {
253
254
  :AUTH_SERVER => 'https://www.google.com',
254
- :AUTH_NAMESPACE_PREAMBLE =>
255
- 'https://adwords.google.com/api/adwords/cm/',
256
255
  :LOGIN_SERVICE_NAME => 'adwords'
257
256
  }
258
257
 
@@ -23,55 +23,8 @@ require 'ads_common/savon_headers/base_header_handler'
23
23
 
24
24
  module AdwordsApi
25
25
  class ClientLoginHeaderHandler < AdsCommon::SavonHeaders::BaseHeaderHandler
26
- # Initializes a header handler.
27
- #
28
- # Args:
29
- # - credential_handler: a header with credential data
30
- # - auth_handler: a header with auth data
31
- # - element_name: an API-specific name of header element
32
- # - namespace: default namespace to use
33
- # - auth_namespace: namespace to use for auth headers
34
- # - version: services version
35
- #
36
- def initialize(credential_handler, auth_handler, namespace, auth_namespace,
37
- version)
38
- super(credential_handler, auth_handler, namespace, version)
39
- @auth_namespace = auth_namespace
40
- end
41
-
42
- # Enriches soap object with API-specific headers like namespaces, login
43
- # credentials etc. Sets the default namespace for the body to the one
44
- # specified in initializer.
45
- #
46
- # Args:
47
- # - request: a HTTPI Request for extra configuration (unused)
48
- # - soap: a Savon soap object to fill fields in
49
- #
50
- # Returns:
51
- # - modified soap structure
52
- #
53
- def prepare_request(request, soap)
54
- super(request, soap)
55
- soap.header[:attributes!] ||= {}
56
- header_name = prepend_namespace(get_header_element_name())
57
- soap.header[:attributes!][header_name] ||= {}
58
- soap.header[:attributes!][header_name]['xmlns'] = @auth_namespace
59
- return soap
60
- end
61
26
 
62
27
  private
63
- # Skips namespace prefixes for all elements except top level. Use default
64
- # (inherited) prefixing for the top level key.
65
- #
66
- # Args:
67
- # - str: String to prepend with a namespace
68
- #
69
- # Returns:
70
- # - String with a namespace
71
- #
72
- def prepend_namespace(str)
73
- return get_header_element_name().eql?(str) ? super(str) : str
74
- end
75
28
 
76
29
  # Generates AdWords API specific request header with ClientLogin data.
77
30
  def generate_request_header()