google-adwords-api 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. data/ChangeLog +3 -0
  2. data/examples/v201306/misc/setup_oauth2.rb +4 -4
  3. data/examples/v201306/optimization/get_keyword_ideas.rb +1 -1
  4. data/examples/v201309/advanced_operations/add_site_links.rb +71 -9
  5. data/examples/v201309/advanced_operations/update_site_links.rb +194 -0
  6. data/examples/v201309/misc/setup_oauth2.rb +4 -4
  7. data/examples/v201309/optimization/get_keyword_ideas.rb +1 -1
  8. data/lib/adwords_api/api_config.rb +0 -88
  9. data/lib/adwords_api/version.rb +1 -1
  10. data/test/templates/v201306/basic_operations_get_campaigns.def +1 -1
  11. data/test/templates/v201306/misc_use_oauth2_jwt.def +1 -1
  12. data/test/templates/v201309/basic_operations_get_campaigns.def +1 -1
  13. data/test/templates/v201309/misc_use_oauth2_jwt.def +1 -1
  14. metadata +266 -429
  15. data/examples/v201302/account_management/create_account.rb +0 -95
  16. data/examples/v201302/account_management/get_account_alerts.rb +0 -122
  17. data/examples/v201302/account_management/get_account_changes.rb +0 -145
  18. data/examples/v201302/account_management/get_account_hierarchy.rb +0 -103
  19. data/examples/v201302/advanced_operations/add_ad_group_bid_modifier.rb +0 -105
  20. data/examples/v201302/advanced_operations/add_click_to_download_ad.rb +0 -137
  21. data/examples/v201302/advanced_operations/add_site_links.rb +0 -221
  22. data/examples/v201302/advanced_operations/create_and_attach_shared_keyword_set.rb +0 -147
  23. data/examples/v201302/advanced_operations/find_and_remove_criteria_from_shared_set.rb +0 -181
  24. data/examples/v201302/advanced_operations/get_ad_group_bid_modifiers.rb +0 -106
  25. data/examples/v201302/adwords_for_video/add_video_call_to_action.rb +0 -94
  26. data/examples/v201302/adwords_for_video/add_video_campaign.rb +0 -103
  27. data/examples/v201302/adwords_for_video/find_videos.rb +0 -92
  28. data/examples/v201302/adwords_for_video/get_keyword_criteria.rb +0 -101
  29. data/examples/v201302/adwords_for_video/get_targeting_groups.rb +0 -93
  30. data/examples/v201302/adwords_for_video/get_video_campaign_criteria.rb +0 -99
  31. data/examples/v201302/adwords_for_video/get_video_campaign_stats.rb +0 -126
  32. data/examples/v201302/adwords_for_video/get_video_campaigns.rb +0 -94
  33. data/examples/v201302/basic_operations/add_ad_groups.rb +0 -143
  34. data/examples/v201302/basic_operations/add_campaigns.rb +0 -162
  35. data/examples/v201302/basic_operations/add_keywords.rb +0 -116
  36. data/examples/v201302/basic_operations/add_text_ads.rb +0 -113
  37. data/examples/v201302/basic_operations/delete_ad.rb +0 -93
  38. data/examples/v201302/basic_operations/delete_ad_group.rb +0 -110
  39. data/examples/v201302/basic_operations/delete_campaign.rb +0 -111
  40. data/examples/v201302/basic_operations/delete_keyword.rb +0 -98
  41. data/examples/v201302/basic_operations/get_ad_groups.rb +0 -106
  42. data/examples/v201302/basic_operations/get_campaigns.rb +0 -101
  43. data/examples/v201302/basic_operations/get_campaigns_with_awql.rb +0 -93
  44. data/examples/v201302/basic_operations/get_keywords.rb +0 -112
  45. data/examples/v201302/basic_operations/get_text_ads.rb +0 -114
  46. data/examples/v201302/basic_operations/pause_ad.rb +0 -92
  47. data/examples/v201302/basic_operations/update_ad_group.rb +0 -89
  48. data/examples/v201302/basic_operations/update_campaign.rb +0 -90
  49. data/examples/v201302/basic_operations/update_keyword.rb +0 -110
  50. data/examples/v201302/campaign_management/add_experiment.rb +0 -166
  51. data/examples/v201302/campaign_management/add_keywords_in_bulk.rb +0 -158
  52. data/examples/v201302/campaign_management/add_location_extension.rb +0 -125
  53. data/examples/v201302/campaign_management/add_location_extension_override.rb +0 -91
  54. data/examples/v201302/campaign_management/get_all_disapproved_ads.rb +0 -101
  55. data/examples/v201302/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -92
  56. data/examples/v201302/campaign_management/promote_experiment.rb +0 -85
  57. data/examples/v201302/campaign_management/set_ad_parameters.rb +0 -122
  58. data/examples/v201302/campaign_management/set_criterion_bid_modifier.rb +0 -110
  59. data/examples/v201302/campaign_management/validate_text_ad.rb +0 -114
  60. data/examples/v201302/error_handling/handle_captcha_challenge.rb +0 -93
  61. data/examples/v201302/error_handling/handle_partial_failures.rb +0 -134
  62. data/examples/v201302/error_handling/handle_policy_violation_error.rb +0 -145
  63. data/examples/v201302/error_handling/handle_two_factor_authorization_error.rb +0 -88
  64. data/examples/v201302/migration/set_campaign_enhanced.rb +0 -91
  65. data/examples/v201302/migration/upgrade_legacy_sitelinks.rb +0 -313
  66. data/examples/v201302/misc/get_all_images_and_videos.rb +0 -108
  67. data/examples/v201302/misc/setup_oauth2.rb +0 -88
  68. data/examples/v201302/misc/upload_image.rb +0 -97
  69. data/examples/v201302/misc/use_oauth2_jwt.rb +0 -93
  70. data/examples/v201302/optimization/estimate_keyword_traffic.rb +0 -137
  71. data/examples/v201302/optimization/get_keyword_bid_simulations.rb +0 -100
  72. data/examples/v201302/optimization/get_keyword_ideas.rb +0 -130
  73. data/examples/v201302/optimization/get_placement_ideas.rb +0 -112
  74. data/examples/v201302/remarketing/add_audience.rb +0 -123
  75. data/examples/v201302/remarketing/add_conversion_tracker.rb +0 -104
  76. data/examples/v201302/reporting/download_criteria_report.rb +0 -87
  77. data/examples/v201302/reporting/download_criteria_report_with_awql.rb +0 -86
  78. data/examples/v201302/reporting/get_campaign_stats.rb +0 -113
  79. data/examples/v201302/reporting/get_report_fields.rb +0 -79
  80. data/examples/v201302/reporting/parallel_report_download.rb +0 -171
  81. data/examples/v201302/targeting/add_campaign_targeting_criteria.rb +0 -123
  82. data/examples/v201302/targeting/add_demographic_targeting_criteria.rb +0 -116
  83. data/examples/v201302/targeting/get_campaign_targeting_criteria.rb +0 -110
  84. data/examples/v201302/targeting/get_targetable_languages_and_carriers.rb +0 -94
  85. data/examples/v201302/targeting/lookup_location.rb +0 -112
  86. data/examples/v201309/campaign_management/add_location_extension_override.rb +0 -91
  87. data/examples/v201309/reporting/get_campaign_stats.rb +0 -113
  88. data/lib/adwords_api/v201302/ad_extension_override_service.rb +0 -38
  89. data/lib/adwords_api/v201302/ad_extension_override_service_registry.rb +0 -46
  90. data/lib/adwords_api/v201302/ad_group_ad_service.rb +0 -42
  91. data/lib/adwords_api/v201302/ad_group_ad_service_registry.rb +0 -46
  92. data/lib/adwords_api/v201302/ad_group_bid_modifier_service.rb +0 -38
  93. data/lib/adwords_api/v201302/ad_group_bid_modifier_service_registry.rb +0 -46
  94. data/lib/adwords_api/v201302/ad_group_criterion_service.rb +0 -42
  95. data/lib/adwords_api/v201302/ad_group_criterion_service_registry.rb +0 -46
  96. data/lib/adwords_api/v201302/ad_group_feed_service.rb +0 -38
  97. data/lib/adwords_api/v201302/ad_group_feed_service_registry.rb +0 -47
  98. data/lib/adwords_api/v201302/ad_group_service.rb +0 -42
  99. data/lib/adwords_api/v201302/ad_group_service_registry.rb +0 -46
  100. data/lib/adwords_api/v201302/ad_param_service.rb +0 -38
  101. data/lib/adwords_api/v201302/ad_param_service_registry.rb +0 -46
  102. data/lib/adwords_api/v201302/alert_service.rb +0 -34
  103. data/lib/adwords_api/v201302/alert_service_registry.rb +0 -46
  104. data/lib/adwords_api/v201302/budget_order_service.rb +0 -42
  105. data/lib/adwords_api/v201302/budget_order_service_registry.rb +0 -46
  106. data/lib/adwords_api/v201302/budget_service.rb +0 -38
  107. data/lib/adwords_api/v201302/budget_service_registry.rb +0 -46
  108. data/lib/adwords_api/v201302/campaign_ad_extension_service.rb +0 -38
  109. data/lib/adwords_api/v201302/campaign_ad_extension_service_registry.rb +0 -46
  110. data/lib/adwords_api/v201302/campaign_criterion_service.rb +0 -42
  111. data/lib/adwords_api/v201302/campaign_criterion_service_registry.rb +0 -46
  112. data/lib/adwords_api/v201302/campaign_feed_service.rb +0 -38
  113. data/lib/adwords_api/v201302/campaign_feed_service_registry.rb +0 -46
  114. data/lib/adwords_api/v201302/campaign_service.rb +0 -42
  115. data/lib/adwords_api/v201302/campaign_service_registry.rb +0 -46
  116. data/lib/adwords_api/v201302/campaign_shared_set_service.rb +0 -38
  117. data/lib/adwords_api/v201302/campaign_shared_set_service_registry.rb +0 -47
  118. data/lib/adwords_api/v201302/constant_data_service.rb +0 -62
  119. data/lib/adwords_api/v201302/constant_data_service_registry.rb +0 -46
  120. data/lib/adwords_api/v201302/conversion_tracker_service.rb +0 -38
  121. data/lib/adwords_api/v201302/conversion_tracker_service_registry.rb +0 -46
  122. data/lib/adwords_api/v201302/customer_service.rb +0 -34
  123. data/lib/adwords_api/v201302/customer_service_registry.rb +0 -46
  124. data/lib/adwords_api/v201302/customer_sync_service.rb +0 -34
  125. data/lib/adwords_api/v201302/customer_sync_service_registry.rb +0 -47
  126. data/lib/adwords_api/v201302/data_service.rb +0 -38
  127. data/lib/adwords_api/v201302/data_service_registry.rb +0 -46
  128. data/lib/adwords_api/v201302/experiment_service.rb +0 -38
  129. data/lib/adwords_api/v201302/experiment_service_registry.rb +0 -46
  130. data/lib/adwords_api/v201302/feed_item_service.rb +0 -38
  131. data/lib/adwords_api/v201302/feed_item_service_registry.rb +0 -46
  132. data/lib/adwords_api/v201302/feed_mapping_service.rb +0 -38
  133. data/lib/adwords_api/v201302/feed_mapping_service_registry.rb +0 -46
  134. data/lib/adwords_api/v201302/feed_service.rb +0 -38
  135. data/lib/adwords_api/v201302/feed_service_registry.rb +0 -46
  136. data/lib/adwords_api/v201302/geo_location_service.rb +0 -34
  137. data/lib/adwords_api/v201302/geo_location_service_registry.rb +0 -46
  138. data/lib/adwords_api/v201302/location_criterion_service.rb +0 -34
  139. data/lib/adwords_api/v201302/location_criterion_service_registry.rb +0 -46
  140. data/lib/adwords_api/v201302/managed_customer_service.rb +0 -50
  141. data/lib/adwords_api/v201302/managed_customer_service_registry.rb +0 -46
  142. data/lib/adwords_api/v201302/media_service.rb +0 -38
  143. data/lib/adwords_api/v201302/media_service_registry.rb +0 -46
  144. data/lib/adwords_api/v201302/mutate_job_service.rb +0 -42
  145. data/lib/adwords_api/v201302/mutate_job_service_registry.rb +0 -46
  146. data/lib/adwords_api/v201302/report_definition_service.rb +0 -34
  147. data/lib/adwords_api/v201302/report_definition_service_registry.rb +0 -46
  148. data/lib/adwords_api/v201302/shared_criterion_service.rb +0 -38
  149. data/lib/adwords_api/v201302/shared_criterion_service_registry.rb +0 -47
  150. data/lib/adwords_api/v201302/shared_set_service.rb +0 -38
  151. data/lib/adwords_api/v201302/shared_set_service_registry.rb +0 -47
  152. data/lib/adwords_api/v201302/targeting_idea_service.rb +0 -38
  153. data/lib/adwords_api/v201302/targeting_idea_service_registry.rb +0 -46
  154. data/lib/adwords_api/v201302/traffic_estimator_service.rb +0 -34
  155. data/lib/adwords_api/v201302/traffic_estimator_service_registry.rb +0 -46
  156. data/lib/adwords_api/v201302/user_list_service.rb +0 -38
  157. data/lib/adwords_api/v201302/user_list_service_registry.rb +0 -46
  158. data/lib/adwords_api/v201302/video_ad_service.rb +0 -38
  159. data/lib/adwords_api/v201302/video_ad_service_registry.rb +0 -46
  160. data/lib/adwords_api/v201302/video_campaign_criterion_service.rb +0 -38
  161. data/lib/adwords_api/v201302/video_campaign_criterion_service_registry.rb +0 -47
  162. data/lib/adwords_api/v201302/video_campaign_service.rb +0 -38
  163. data/lib/adwords_api/v201302/video_campaign_service_registry.rb +0 -46
  164. data/lib/adwords_api/v201302/video_service.rb +0 -42
  165. data/lib/adwords_api/v201302/video_service_registry.rb +0 -46
  166. data/lib/adwords_api/v201302/video_targeting_group_criterion_service.rb +0 -38
  167. data/lib/adwords_api/v201302/video_targeting_group_criterion_service_registry.rb +0 -46
  168. data/lib/adwords_api/v201302/video_targeting_group_service.rb +0 -38
  169. data/lib/adwords_api/v201302/video_targeting_group_service_registry.rb +0 -46
  170. data/test/examples/v201302/test_account_management.rb +0 -50
  171. data/test/examples/v201302/test_advanced_operations.rb +0 -81
  172. data/test/examples/v201302/test_basic_operations.rb +0 -177
  173. data/test/examples/v201302/test_campaign_management.rb +0 -132
  174. data/test/examples/v201302/test_error_handling.rb +0 -63
  175. data/test/examples/v201302/test_migration.rb +0 -49
  176. data/test/examples/v201302/test_misc.rb +0 -39
  177. data/test/examples/v201302/test_optimization.rb +0 -63
  178. data/test/examples/v201302/test_remarketing.rb +0 -39
  179. data/test/examples/v201302/test_reporting.rb +0 -84
  180. data/test/examples/v201302/test_targeting.rb +0 -68
  181. data/test/examples/v201302/utils.rb +0 -267
  182. data/test/suite_exampletests_v201302.rb +0 -37
  183. data/test/templates/v201302/basic_operations_get_campaigns.def +0 -114
  184. data/test/templates/v201302/misc_use_oauth2_jwt.def +0 -131
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.11.0:
2
+ - Removed deprecated API version v201302.
3
+
1
4
  0.10.0:
2
5
  - Support and examples for v201309.
3
6
  - Removed deprecated API version v201209.
@@ -33,7 +33,7 @@ def setup_oauth2()
33
33
  # the configuration file or provide your own logger:
34
34
  # adwords.logger = Logger.new('adwords_xml.log')
35
35
 
36
- # You can call authorize explicitely to obtain the access token. Otherwise, it
36
+ # You can call authorize explicitly to obtain the access token. Otherwise, it
37
37
  # will be invoked automatically on the first API call.
38
38
  # There are two ways to provide verification code, first one is via the block:
39
39
  token = adwords.authorize() do |auth_url|
@@ -44,7 +44,7 @@ def setup_oauth2()
44
44
  end
45
45
  if token
46
46
  print "\nWould you like to update your adwords_api.yml to save " +
47
- "OAuth2 crdentials? (y/N): "
47
+ "OAuth2 credentials? (y/N): "
48
48
  response = gets.chomp
49
49
  if ('y'.casecmp(response) == 0) or ('yes'.casecmp(response) == 0)
50
50
  adwords.save_oauth2_token(token)
@@ -54,12 +54,12 @@ def setup_oauth2()
54
54
  end
55
55
 
56
56
  # Alternatively, you can provide one within the parameters:
57
- #token = adwords.authorize({:oauth2_verification_code => verification_code})
57
+ # token = adwords.authorize({:oauth2_verification_code => verification_code})
58
58
 
59
59
  # Note, 'token' is a Hash. Its value is not used in this example. If you need
60
60
  # to be able to access the API in offline mode, with no user present, you
61
61
  # should persist it to be used in subsequent invocations like this:
62
- #adwords.authorize({:oauth2_token => token})
62
+ # adwords.authorize({:oauth2_token => token})
63
63
 
64
64
  # No exception thrown - we are good to make a request.
65
65
  end
@@ -53,7 +53,7 @@ def get_keyword_ideas(keyword_text)
53
53
  # Language setting (optional).
54
54
  # The ID can be found in the documentation:
55
55
  # https://developers.google.com/adwords/api/docs/appendix/languagecodes
56
- # As of v201302 only one LanguageSearchParameter is allowed per request.
56
+ # Only one LanguageSearchParameter is allowed per request.
57
57
  :xsi_type => 'LanguageSearchParameter',
58
58
  :languages => [{:id => 1000}]
59
59
  }
@@ -46,7 +46,9 @@ def add_site_links(campaign_id)
46
46
  :name => 'Feed For Site Links',
47
47
  :attributes => [
48
48
  {:type => 'STRING', :name => 'Link Text'},
49
- {:type => 'URL', :name => 'Link URL'}
49
+ {:type => 'URL', :name => 'Link URL'},
50
+ {:type => 'STRING', :name => 'Line 1 Description'},
51
+ {:type => 'STRING', :name => 'Line 2 Description'}
50
52
  ]
51
53
  }
52
54
 
@@ -59,25 +61,67 @@ def add_site_links(campaign_id)
59
61
  link_text_feed_attribute_id = feed[:attributes][0][:id]
60
62
  # Attribute of type URL.
61
63
  link_url_feed_attribute_id = feed[:attributes][1][:id]
64
+ # Attribute of type STRING.
65
+ line_1_feed_attribute_id = feed[:attributes][2][:id]
66
+ #Attribute of type STRING.
67
+ line_2_feed_attribute_id = feed[:attributes][3][:id]
62
68
  puts "Feed with name '%s' and ID %d was added with" %
63
69
  [feed[:name], feed[:id]]
64
- puts "\tText attribute ID %d and URL attribute ID %d." %
65
- [link_text_feed_attribute_id, link_url_feed_attribute_id]
70
+ puts "\tText attribute ID %d and URL attribute ID %d " +
71
+ "and Line 1 attribute ID %d and Line 2 attribute ID %d." % [
72
+ link_text_feed_attribute_id,
73
+ link_url_feed_attribute_id,
74
+ line_1_feed_attribute_id,
75
+ line_2_feed_attribute_id
76
+ ]
77
+
66
78
  sitelinks_data[:feed_id] = feed[:id]
67
79
  sitelinks_data[:link_text_feed_id] = link_text_feed_attribute_id
68
80
  sitelinks_data[:link_url_feed_id] = link_url_feed_attribute_id
81
+ sitelinks_data[:line_1_feed_id] = line_1_feed_attribute_id
82
+ sitelinks_data[:line_2_feed_id] = line_2_feed_attribute_id
69
83
  else
70
84
  raise new StandardError, 'No feeds were added.'
71
85
  end
72
86
 
73
87
  # Create site links feed items.
74
88
  items_data = [
75
- {:text => 'Home', :url => 'http://www.example.com'},
76
- {:text => 'Stores', :url => 'http://www.example.com/stores'},
77
- {:text => 'On Sale', :url => 'http://www.example.com/sale'},
78
- {:text => 'Support', :url => 'http://www.example.com/support'},
79
- {:text => 'Products', :url => 'http://www.example.com/products'},
80
- {:text => 'About', :url => 'http://www.example.com/about'}
89
+ {
90
+ :text => 'Home',
91
+ :url => 'http://www.example.com',
92
+ :line_1 => 'Home line 1',
93
+ :line_2 => 'Home line 2'
94
+ },
95
+ {
96
+ :text => 'Stores',
97
+ :url => 'http://www.example.com/stores',
98
+ :line_1 => 'Stores line 1',
99
+ :line_2 => 'Stores line 2'
100
+ },
101
+ {
102
+ :text => 'On Sale',
103
+ :url => 'http://www.example.com/sale',
104
+ :line_1 => 'On Sale line 1',
105
+ :line_2 => 'On Sale line 2'
106
+ },
107
+ {
108
+ :text => 'Support',
109
+ :url => 'http://www.example.com/support',
110
+ :line_1 => 'Support line 1',
111
+ :line_2 => 'Support line 2'
112
+ },
113
+ {
114
+ :text => 'Products',
115
+ :url => 'http://www.example.com/products',
116
+ :line_1 => 'Products line 1',
117
+ :line_2 => 'Products line 2'
118
+ },
119
+ {
120
+ :text => 'About',
121
+ :url => 'http://www.example.com/about',
122
+ :line_1 => 'About line 1',
123
+ :line_2 => 'About line 2'
124
+ }
81
125
  ]
82
126
 
83
127
  feed_items = items_data.map do |item|
@@ -91,6 +135,14 @@ def add_site_links(campaign_id)
91
135
  {
92
136
  :feed_attribute_id => sitelinks_data[:link_url_feed_id],
93
137
  :string_value => item[:url]
138
+ },
139
+ {
140
+ :feed_attribute_id => sitelinks_data[:line_1_feed_id],
141
+ :string_value => item[:line_1]
142
+ },
143
+ {
144
+ :feed_attribute_id => sitelinks_data[:line_2_feed_id],
145
+ :string_value => item[:line_2]
94
146
  }
95
147
  ]
96
148
  }
@@ -123,6 +175,14 @@ def add_site_links(campaign_id)
123
175
  {
124
176
  :feed_attribute_id => sitelinks_data[:link_url_feed_id],
125
177
  :field_id => PLACEHOLDER_FIELD_SITELINK_LINK_URL
178
+ },
179
+ {
180
+ :feed_attribute_id => sitelinks_data[:line_1_feed_id],
181
+ :field_id => PLACEHOLDER_FIELD_SITELINK_LINE_1_TEXT
182
+ },
183
+ {
184
+ :feed_attribute_id => sitelinks_data[:line_2_feed_id],
185
+ :field_id => PLACEHOLDER_FIELD_SITELINK_LINE_2_TEXT
126
186
  }
127
187
  ]
128
188
  }
@@ -212,6 +272,8 @@ if __FILE__ == $0
212
272
  PLACEHOLDER_SITELINKS = 1
213
273
  PLACEHOLDER_FIELD_SITELINK_LINK_TEXT = 1
214
274
  PLACEHOLDER_FIELD_SITELINK_LINK_URL = 2
275
+ PLACEHOLDER_FIELD_SITELINK_LINE_1_TEXT = 3
276
+ PLACEHOLDER_FIELD_SITELINK_LINE_2_TEXT = 4
215
277
 
216
278
  begin
217
279
  # Campaign ID to add site link to.
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.mcloonan@gmail.com (Michael Cloonan)
5
+ #
6
+ # Copyright:: Copyright 2013, 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
+ # This example updates an existing sitelinks feed as follows:
22
+ # * Adds FeedItemAttributes for line 1 and line 2 descriptions to the Feed
23
+ # * Populates the new FeedItemAttributes on FeedItems in the Feed
24
+ # * Replaces the Feed's existing FeedMapping with one that contains the new
25
+ # set of FeedItemAttributes
26
+ #
27
+ # The end result of this is that any campaign or ad group whose CampaignFeed
28
+ # or AdGroupFeed points to the Feed's ID will now serve line 1 and line 2
29
+ # descriptions in its sitelinks.
30
+ #
31
+ # Tags: FeedItemService.mutate
32
+ # Tags: FeedMappingService.mutate, FeedService.mutate
33
+
34
+ require 'adwords_api'
35
+
36
+ def update_site_links(feed_id, feed_item_descriptions)
37
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
38
+ # when called without parameters.
39
+ adwords = AdwordsApi::Api.new
40
+
41
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
42
+ # the configuration file or provide your own logger:
43
+ # adwords.logger = Logger.new('adwords_xml.log')
44
+
45
+ feed_srv = adwords.service(:FeedService, API_VERSION)
46
+ feed_item_srv = adwords.service(:FeedItemService, API_VERSION)
47
+ feed_mapping_srv = adwords.service(:FeedMappingService, API_VERSION)
48
+
49
+ feed_selector = {
50
+ :fields => ['Id', 'Attributes'],
51
+ :predicates => [
52
+ {:field => 'Id', :operator => 'EQUALS', :values => [feed_id]}
53
+ ]
54
+ }
55
+
56
+ feed = feed_srv.get(feed_selector)[:entries][0]
57
+
58
+ # Add new line1 and line2 feed attributes.
59
+ next_attribute_index = feed[:attributes].length()
60
+
61
+ feed[:attributes] = [
62
+ {:type => 'STRING', :name => 'Line 1 Description'},
63
+ {:type => 'STRING', :name => 'Line 2 Description'}
64
+ ]
65
+
66
+ mutated_feed_result = feed_srv.mutate([
67
+ {:operator => 'SET', :operand => feed}
68
+ ])
69
+
70
+ mutated_feed = mutated_feed_result[:value][0]
71
+ line_1_attribute = mutated_feed[:attributes][next_attribute_index]
72
+ line_2_attribute = mutated_feed[:attributes][next_attribute_index + 1]
73
+
74
+ # Update feed items.
75
+ feed_item_ids = feed_item_descriptions.keys
76
+ item_selector = {
77
+ :fields => ['FeedId', 'FeedItemId', 'AttributeValues'],
78
+ :predicates => [
79
+ {:field => 'FeedId', :operator => 'EQUALS', :values => [feed_id]},
80
+ {:field => 'FeedItemId', :operator => 'IN', :values => feed_item_ids}
81
+ ]
82
+ }
83
+
84
+ feed_items = feed_item_srv.get(item_selector)[:entries]
85
+
86
+ item_operations = feed_items.map do |feed_item|
87
+ feed_item[:attribute_values] = [
88
+ {
89
+ :feed_attribute_id => line_1_attribute[:id],
90
+ :string_value => feed_item_descriptions[feed_item[:feed_item_id]][0]
91
+ },
92
+ {
93
+ :feed_attribute_id => line_2_attribute[:id],
94
+ :string_value => feed_item_descriptions[feed_item[:feed_item_id]][1]
95
+ }
96
+ ]
97
+
98
+ {:operator => 'SET', :operand => feed_item}
99
+ end
100
+ items_update_result = feed_item_srv.mutate(item_operations)
101
+ puts 'Updated %d items' % items_update_result[:value].length
102
+
103
+ # Update feed mapping.
104
+ mapping_selector = {
105
+ :fields => [
106
+ 'FeedId',
107
+ 'FeedMappingId',
108
+ 'PlaceholderType',
109
+ 'AttributeFieldMappings'
110
+ ],
111
+ :predicates => [
112
+ {:field => 'FeedId', :operator => 'EQUALS', :values => [feed_id]}
113
+ ]
114
+ }
115
+ feed_mapping_results = feed_mapping_srv.get(mapping_selector)
116
+ feed_mapping = feed_mapping_results[:entries][0]
117
+
118
+ # Feed mappings are immutable, so we have to delete it and re-add
119
+ # it with modifications.
120
+ feed_mapping_srv.mutate([
121
+ {:operator => 'REMOVE', :operand => feed_mapping}
122
+ ])[:value][0]
123
+
124
+ feed_mapping[:attribute_field_mappings].push(
125
+ {
126
+ :feed_attribute_id => line_1_attribute[:id],
127
+ :field_id => PLACEHOLDER_FIELD_LINE_1_TEXT
128
+ },
129
+ {
130
+ :feed_attribute_id => line_2_attribute[:id],
131
+ :field_id => PLACEHOLDER_FIELD_LINE_2_TEXT
132
+ }
133
+ )
134
+ mapping_update_result = feed_mapping_srv.mutate([
135
+ {:operator => 'ADD', :operand => feed_mapping}
136
+ ])
137
+
138
+ mutated_mapping = mapping_update_result[:value][0]
139
+ puts 'Updated field mappings for feedId %d and feedMappingId %d to:' %
140
+ [mutated_mapping[:feed_id], mutated_mapping[:feed_mapping_id]]
141
+ mutated_mapping[:attribute_field_mappings].each do |field_mapping|
142
+ puts "\tfeedAttributeId %d --> fieldId %d" %
143
+ [field_mapping[:feed_attribute_id], field_mapping[:field_id]]
144
+ end
145
+ end
146
+
147
+ if __FILE__ == $0
148
+ API_VERSION = :v201309
149
+
150
+ # See the Placeholder reference page for a list of all the placeholder types
151
+ # and fields:
152
+ # https://developers.google.com/adwords/api/docs/appendix/placeholders
153
+ PLACEHOLDER_FIELD_LINE_1_TEXT = 3
154
+ PLACEHOLDER_FIELD_LINE_2_TEXT = 4
155
+
156
+ begin
157
+ feed_id = 'INSERT_FEED_ID_HERE'.to_i
158
+ feed_item_descriptions = {
159
+ 'INSERT_FEED_ITEM_A_ID_HERE'.to_i => [
160
+ 'INSERT_FEED_ITEM_A_LINE1_DESC_HERE',
161
+ 'INSERT_FEED_ITEM_A_LINE2_DESC_HERE'
162
+ ],
163
+ 'INSERT_FEED_ITEM_B_ID_HERE'.to_i => [
164
+ 'INSERT_FEED_ITEM_B_LINE1_DESC_HERE',
165
+ 'INSERT_FEED_ITEM_B_LINE2_DESC_HERE'
166
+ ]
167
+ }
168
+
169
+ update_site_links(feed_id, feed_item_descriptions)
170
+
171
+ # Authorization error.
172
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
173
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
174
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
175
+ "to retrieve and store OAuth2 tokens."
176
+ puts "See this wiki page for more details:\n\n " +
177
+ 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
178
+
179
+ # HTTP errors.
180
+ rescue AdsCommon::Errors::HttpError => e
181
+ puts "HTTP Error: %s" % e
182
+
183
+ # API errors.
184
+ rescue AdwordsApi::Errors::ApiException => e
185
+ puts "Message: %s" % e.message
186
+ puts 'Errors:'
187
+ e.errors.each_with_index do |error, index|
188
+ puts "\tError [%d]:" % (index + 1)
189
+ error.each do |field, value|
190
+ puts "\t\t%s: %s" % [field, value]
191
+ end
192
+ end
193
+ end
194
+ end
@@ -33,7 +33,7 @@ def setup_oauth2()
33
33
  # the configuration file or provide your own logger:
34
34
  # adwords.logger = Logger.new('adwords_xml.log')
35
35
 
36
- # You can call authorize explicitely to obtain the access token. Otherwise, it
36
+ # You can call authorize explicitly to obtain the access token. Otherwise, it
37
37
  # will be invoked automatically on the first API call.
38
38
  # There are two ways to provide verification code, first one is via the block:
39
39
  token = adwords.authorize() do |auth_url|
@@ -44,7 +44,7 @@ def setup_oauth2()
44
44
  end
45
45
  if token
46
46
  print "\nWould you like to update your adwords_api.yml to save " +
47
- "OAuth2 crdentials? (y/N): "
47
+ "OAuth2 credentials? (y/N): "
48
48
  response = gets.chomp
49
49
  if ('y'.casecmp(response) == 0) or ('yes'.casecmp(response) == 0)
50
50
  adwords.save_oauth2_token(token)
@@ -54,12 +54,12 @@ def setup_oauth2()
54
54
  end
55
55
 
56
56
  # Alternatively, you can provide one within the parameters:
57
- #token = adwords.authorize({:oauth2_verification_code => verification_code})
57
+ # token = adwords.authorize({:oauth2_verification_code => verification_code})
58
58
 
59
59
  # Note, 'token' is a Hash. Its value is not used in this example. If you need
60
60
  # to be able to access the API in offline mode, with no user present, you
61
61
  # should persist it to be used in subsequent invocations like this:
62
- #adwords.authorize({:oauth2_token => token})
62
+ # adwords.authorize({:oauth2_token => token})
63
63
 
64
64
  # No exception thrown - we are good to make a request.
65
65
  end
@@ -53,7 +53,7 @@ def get_keyword_ideas(keyword_text)
53
53
  # Language setting (optional).
54
54
  # The ID can be found in the documentation:
55
55
  # https://developers.google.com/adwords/api/docs/appendix/languagecodes
56
- # As of v201302 only one LanguageSearchParameter is allowed per request.
56
+ # Only one LanguageSearchParameter is allowed per request.
57
57
  :xsi_type => 'LanguageSearchParameter',
58
58
  :languages => [{:id => 1000}]
59
59
  }
@@ -45,50 +45,6 @@ module AdwordsApi
45
45
 
46
46
  # Configure the services available to each version
47
47
  @@service_config = {
48
- :v201302 => [
49
- :AdExtensionOverrideService,
50
- :AdGroupAdService,
51
- :AdGroupBidModifierService,
52
- :AdGroupCriterionService,
53
- :AdGroupFeedService,
54
- :AdGroupService,
55
- :AdParamService,
56
- :AlertService,
57
- :BudgetOrderService,
58
- :BudgetService,
59
- :CampaignAdExtensionService,
60
- :CampaignCriterionService,
61
- :CampaignFeedService,
62
- :CampaignService,
63
- :CampaignSharedSetService,
64
- :ConstantDataService,
65
- :ConversionTrackerService,
66
- :CustomerService,
67
- :CustomerSyncService,
68
- :DataService,
69
- :ExperimentService,
70
- :FeedItemService,
71
- :FeedMappingService,
72
- :FeedService,
73
- :GeoLocationService,
74
- :LocationCriterionService,
75
- :ManagedCustomerService,
76
- :MediaService,
77
- :MutateJobService,
78
- :ReportDefinitionService,
79
- :SharedCriterionService,
80
- :SharedSetService,
81
- :TargetingIdeaService,
82
- :TrafficEstimatorService,
83
- :UserListService,
84
- # AdWords for Video API Beta services.
85
- :VideoAdService,
86
- :VideoCampaignCriterionService,
87
- :VideoCampaignService,
88
- :VideoService,
89
- :VideoTargetingGroupCriterionService,
90
- :VideoTargetingGroupService
91
- ],
92
48
  :v201306 => [
93
49
  :AdExtensionOverrideService,
94
50
  :AdGroupAdService,
@@ -172,7 +128,6 @@ module AdwordsApi
172
128
  :PRODUCTION => {
173
129
  :oauth_scope => 'https://adwords.google.com/api/adwords/',
174
130
  :header_ns => 'https://adwords.google.com/api/adwords/cm/',
175
- :v201302 => 'https://adwords.google.com/api/adwords/',
176
131
  :v201306 => 'https://adwords.google.com/api/adwords/',
177
132
  :v201309 => 'https://adwords.google.com/api/adwords/'
178
133
  }
@@ -181,49 +136,6 @@ module AdwordsApi
181
136
  # Configure the subdirectories for each version / service pair.
182
137
  # A missing pair means that only the base URL is used.
183
138
  @@subdir_config = {
184
- # v201302
185
- [:v201302, :AdExtensionOverrideService] => 'cm/',
186
- [:v201302, :AdGroupAdService] => 'cm/',
187
- [:v201302, :AdGroupBidModifierService] => 'cm/',
188
- [:v201302, :AdGroupCriterionService] => 'cm/',
189
- [:v201302, :AdGroupFeedService] => 'cm/',
190
- [:v201302, :AdGroupService] => 'cm/',
191
- [:v201302, :AdParamService] => 'cm/',
192
- [:v201302, :AlertService] => 'mcm/',
193
- [:v201302, :BudgetOrderService] => 'billing/',
194
- [:v201302, :CampaignAdExtensionService] => 'cm/',
195
- [:v201302, :CampaignCriterionService] => 'cm/',
196
- [:v201302, :CampaignFeedService] => 'cm/',
197
- [:v201302, :CampaignService] => 'cm/',
198
- [:v201302, :CampaignSharedSetService] => 'cm/',
199
- [:v201302, :ConstantDataService] => 'cm/',
200
- [:v201302, :ConversionTrackerService] => 'cm/',
201
- [:v201302, :CustomerSyncService] => 'ch/',
202
- [:v201302, :DataService] => 'cm/',
203
- [:v201302, :ExperimentService] => 'cm/',
204
- [:v201302, :FeedItemService] => 'cm/',
205
- [:v201302, :FeedMappingService] => 'cm/',
206
- [:v201302, :FeedService] => 'cm/',
207
- [:v201302, :GeoLocationService] => 'cm/',
208
- [:v201302, :LocationCriterionService] => 'cm/',
209
- [:v201302, :MediaService] => 'cm/',
210
- [:v201302, :MutateJobService] => 'cm/',
211
- [:v201302, :ReportDefinitionService] => 'cm/',
212
- [:v201302, :SharedCriterionService] => 'cm/',
213
- [:v201302, :SharedSetService] => 'cm/',
214
- [:v201302, :TargetingIdeaService] => 'o/',
215
- [:v201302, :TrafficEstimatorService] => 'o/',
216
- [:v201302, :UserListService] => 'cm/',
217
- [:v201302, :ManagedCustomerService] => 'mcm/',
218
- [:v201302, :CustomerService] => 'mcm/',
219
- [:v201302, :BudgetService] => 'cm/',
220
- # AdWords for Video API Beta services.
221
- [:v201302, :VideoAdService] => 'video/',
222
- [:v201302, :VideoCampaignCriterionService] => 'video/',
223
- [:v201302, :VideoCampaignService] => 'video/',
224
- [:v201302, :VideoService] => 'video/',
225
- [:v201302, :VideoTargetingGroupCriterionService] => 'video/',
226
- [:v201302, :VideoTargetingGroupService] => 'video/',
227
139
  # v201306
228
140
  [:v201306, :AdExtensionOverrideService] => 'cm/',
229
141
  [:v201306, :AdGroupAdService] => 'cm/',