google-adwords-api 0.15.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +8 -8
  2. data/ChangeLog +4 -0
  3. data/examples/v201502/extensions/add_google_my_business_location_extensions.rb +4 -4
  4. data/examples/v201506/account_management/create_account.rb +92 -0
  5. data/examples/v201506/account_management/get_account_changes.rb +143 -0
  6. data/examples/v201506/account_management/get_account_hierarchy.rb +98 -0
  7. data/examples/v201506/advanced_operations/add_ad_customizers.rb +189 -0
  8. data/examples/v201506/advanced_operations/add_ad_group_bid_modifier.rb +105 -0
  9. data/examples/v201506/advanced_operations/add_click_to_download_ad.rb +137 -0
  10. data/examples/v201506/advanced_operations/add_text_ad_with_upgraded_urls.rb +138 -0
  11. data/examples/v201506/advanced_operations/create_and_attach_shared_keyword_set.rb +137 -0
  12. data/examples/v201506/advanced_operations/find_and_remove_criteria_from_shared_set.rb +171 -0
  13. data/examples/v201506/advanced_operations/get_ad_group_bid_modifiers.rb +106 -0
  14. data/examples/v201506/advanced_operations/upload_offline_conversions.rb +117 -0
  15. data/examples/v201506/advanced_operations/use_shared_bidding_strategy.rb +152 -0
  16. data/examples/v201506/basic_operations/add_ad_groups.rb +144 -0
  17. data/examples/v201506/basic_operations/add_campaigns.rb +143 -0
  18. data/examples/v201506/basic_operations/add_keywords.rb +118 -0
  19. data/examples/v201506/basic_operations/add_text_ads.rb +113 -0
  20. data/examples/v201506/basic_operations/get_ad_groups.rb +106 -0
  21. data/examples/v201506/basic_operations/get_campaigns.rb +101 -0
  22. data/examples/v201506/basic_operations/get_campaigns_with_awql.rb +93 -0
  23. data/examples/v201506/basic_operations/get_keywords.rb +112 -0
  24. data/examples/v201506/basic_operations/get_text_ads.rb +114 -0
  25. data/examples/v201506/basic_operations/pause_ad.rb +92 -0
  26. data/examples/v201506/basic_operations/remove_ad.rb +93 -0
  27. data/examples/v201506/basic_operations/remove_ad_group.rb +89 -0
  28. data/examples/v201506/basic_operations/remove_campaign.rb +91 -0
  29. data/examples/v201506/basic_operations/remove_keyword.rb +98 -0
  30. data/examples/v201506/basic_operations/update_ad_group.rb +89 -0
  31. data/examples/v201506/basic_operations/update_campaign.rb +90 -0
  32. data/examples/v201506/basic_operations/update_keyword.rb +110 -0
  33. data/examples/v201506/campaign_management/add_campaign_labels.rb +86 -0
  34. data/examples/v201506/campaign_management/add_experiment.rb +166 -0
  35. data/examples/v201506/campaign_management/add_keywords_in_bulk.rb +158 -0
  36. data/examples/v201506/campaign_management/get_all_disapproved_ads.rb +101 -0
  37. data/examples/v201506/campaign_management/get_all_disapproved_ads_with_awql.rb +93 -0
  38. data/examples/v201506/campaign_management/get_campaigns_by_label.rb +112 -0
  39. data/examples/v201506/campaign_management/promote_experiment.rb +85 -0
  40. data/examples/v201506/campaign_management/set_ad_parameters.rb +122 -0
  41. data/examples/v201506/campaign_management/set_criterion_bid_modifier.rb +108 -0
  42. data/examples/v201506/campaign_management/validate_text_ad.rb +114 -0
  43. data/examples/v201506/error_handling/handle_partial_failures.rb +134 -0
  44. data/examples/v201506/error_handling/handle_policy_violation_error.rb +145 -0
  45. data/examples/v201506/extensions/add_google_my_business_location_extensions.rb +190 -0
  46. data/examples/v201506/extensions/add_site_links.rb +168 -0
  47. data/examples/v201506/extensions/add_site_links_using_feeds.rb +276 -0
  48. data/examples/v201506/migration/migrate_to_extension_settings.rb +392 -0
  49. data/examples/v201506/migration/upgrade_ad_url.rb +97 -0
  50. data/examples/v201506/misc/create_ad_words_session_without_properties_file.rb +94 -0
  51. data/examples/v201506/misc/get_all_images_and_videos.rb +108 -0
  52. data/examples/v201506/misc/setup_oauth2.rb +88 -0
  53. data/examples/v201506/misc/upload_image.rb +97 -0
  54. data/examples/v201506/misc/use_oauth2_jwt.rb +97 -0
  55. data/examples/v201506/optimization/estimate_keyword_traffic.rb +150 -0
  56. data/examples/v201506/optimization/get_keyword_bid_simulations.rb +99 -0
  57. data/examples/v201506/optimization/get_keyword_ideas.rb +130 -0
  58. data/examples/v201506/remarketing/add_audience.rb +122 -0
  59. data/examples/v201506/remarketing/add_conversion_tracker.rb +104 -0
  60. data/examples/v201506/remarketing/add_rule_based_user_lists.rb +171 -0
  61. data/examples/v201506/reporting/download_criteria_report.rb +94 -0
  62. data/examples/v201506/reporting/download_criteria_report_with_awql.rb +95 -0
  63. data/examples/v201506/reporting/get_report_fields.rb +79 -0
  64. data/examples/v201506/reporting/parallel_report_download.rb +168 -0
  65. data/examples/v201506/shopping_campaigns/add_product_partition_tree.rb +269 -0
  66. data/examples/v201506/shopping_campaigns/add_product_scope.rb +133 -0
  67. data/examples/v201506/shopping_campaigns/add_shopping_campaign.rb +133 -0
  68. data/examples/v201506/shopping_campaigns/get_product_category_taxonomy.rb +117 -0
  69. data/examples/v201506/targeting/add_campaign_targeting_criteria.rb +184 -0
  70. data/examples/v201506/targeting/add_demographic_targeting_criteria.rb +116 -0
  71. data/examples/v201506/targeting/get_campaign_targeting_criteria.rb +110 -0
  72. data/examples/v201506/targeting/get_targetable_languages_and_carriers.rb +94 -0
  73. data/examples/v201506/targeting/lookup_location.rb +112 -0
  74. data/lib/adwords_api.rb +9 -0
  75. data/lib/adwords_api/api_config.rb +90 -4
  76. data/lib/adwords_api/report_header_handler.rb +5 -0
  77. data/lib/adwords_api/v201506/account_label_service.rb +38 -0
  78. data/lib/adwords_api/v201506/account_label_service_registry.rb +46 -0
  79. data/lib/adwords_api/v201506/ad_customizer_feed_service.rb +38 -0
  80. data/lib/adwords_api/v201506/ad_customizer_feed_service_registry.rb +46 -0
  81. data/lib/adwords_api/v201506/ad_group_ad_service.rb +50 -0
  82. data/lib/adwords_api/v201506/ad_group_ad_service_registry.rb +46 -0
  83. data/lib/adwords_api/v201506/ad_group_bid_modifier_service.rb +42 -0
  84. data/lib/adwords_api/v201506/ad_group_bid_modifier_service_registry.rb +46 -0
  85. data/lib/adwords_api/v201506/ad_group_criterion_service.rb +46 -0
  86. data/lib/adwords_api/v201506/ad_group_criterion_service_registry.rb +46 -0
  87. data/lib/adwords_api/v201506/ad_group_extension_setting_service.rb +42 -0
  88. data/lib/adwords_api/v201506/ad_group_extension_setting_service_registry.rb +46 -0
  89. data/lib/adwords_api/v201506/ad_group_feed_service.rb +42 -0
  90. data/lib/adwords_api/v201506/ad_group_feed_service_registry.rb +46 -0
  91. data/lib/adwords_api/v201506/ad_group_service.rb +46 -0
  92. data/lib/adwords_api/v201506/ad_group_service_registry.rb +46 -0
  93. data/lib/adwords_api/v201506/ad_param_service.rb +38 -0
  94. data/lib/adwords_api/v201506/ad_param_service_registry.rb +46 -0
  95. data/lib/adwords_api/v201506/adwords_user_list_service.rb +38 -0
  96. data/lib/adwords_api/v201506/adwords_user_list_service_registry.rb +46 -0
  97. data/lib/adwords_api/v201506/bidding_strategy_service.rb +42 -0
  98. data/lib/adwords_api/v201506/bidding_strategy_service_registry.rb +46 -0
  99. data/lib/adwords_api/v201506/budget_order_service.rb +42 -0
  100. data/lib/adwords_api/v201506/budget_order_service_registry.rb +46 -0
  101. data/lib/adwords_api/v201506/budget_service.rb +42 -0
  102. data/lib/adwords_api/v201506/budget_service_registry.rb +46 -0
  103. data/lib/adwords_api/v201506/campaign_criterion_service.rb +42 -0
  104. data/lib/adwords_api/v201506/campaign_criterion_service_registry.rb +46 -0
  105. data/lib/adwords_api/v201506/campaign_extension_setting_service.rb +42 -0
  106. data/lib/adwords_api/v201506/campaign_extension_setting_service_registry.rb +46 -0
  107. data/lib/adwords_api/v201506/campaign_feed_service.rb +42 -0
  108. data/lib/adwords_api/v201506/campaign_feed_service_registry.rb +46 -0
  109. data/lib/adwords_api/v201506/campaign_service.rb +46 -0
  110. data/lib/adwords_api/v201506/campaign_service_registry.rb +46 -0
  111. data/lib/adwords_api/v201506/campaign_shared_set_service.rb +42 -0
  112. data/lib/adwords_api/v201506/campaign_shared_set_service_registry.rb +46 -0
  113. data/lib/adwords_api/v201506/constant_data_service.rb +66 -0
  114. data/lib/adwords_api/v201506/constant_data_service_registry.rb +46 -0
  115. data/lib/adwords_api/v201506/conversion_tracker_service.rb +42 -0
  116. data/lib/adwords_api/v201506/conversion_tracker_service_registry.rb +46 -0
  117. data/lib/adwords_api/v201506/customer_extension_setting_service.rb +42 -0
  118. data/lib/adwords_api/v201506/customer_extension_setting_service_registry.rb +46 -0
  119. data/lib/adwords_api/v201506/customer_feed_service.rb +42 -0
  120. data/lib/adwords_api/v201506/customer_feed_service_registry.rb +46 -0
  121. data/lib/adwords_api/v201506/customer_service.rb +38 -0
  122. data/lib/adwords_api/v201506/customer_service_registry.rb +46 -0
  123. data/lib/adwords_api/v201506/customer_sync_service.rb +34 -0
  124. data/lib/adwords_api/v201506/customer_sync_service_registry.rb +47 -0
  125. data/lib/adwords_api/v201506/data_service.rb +54 -0
  126. data/lib/adwords_api/v201506/data_service_registry.rb +46 -0
  127. data/lib/adwords_api/v201506/experiment_service.rb +38 -0
  128. data/lib/adwords_api/v201506/experiment_service_registry.rb +46 -0
  129. data/lib/adwords_api/v201506/feed_item_service.rb +42 -0
  130. data/lib/adwords_api/v201506/feed_item_service_registry.rb +46 -0
  131. data/lib/adwords_api/v201506/feed_mapping_service.rb +42 -0
  132. data/lib/adwords_api/v201506/feed_mapping_service_registry.rb +46 -0
  133. data/lib/adwords_api/v201506/feed_service.rb +42 -0
  134. data/lib/adwords_api/v201506/feed_service_registry.rb +46 -0
  135. data/lib/adwords_api/v201506/geo_location_service.rb +34 -0
  136. data/lib/adwords_api/v201506/geo_location_service_registry.rb +46 -0
  137. data/lib/adwords_api/v201506/label_service.rb +42 -0
  138. data/lib/adwords_api/v201506/label_service_registry.rb +46 -0
  139. data/lib/adwords_api/v201506/location_criterion_service.rb +38 -0
  140. data/lib/adwords_api/v201506/location_criterion_service_registry.rb +46 -0
  141. data/lib/adwords_api/v201506/managed_customer_service.rb +54 -0
  142. data/lib/adwords_api/v201506/managed_customer_service_registry.rb +46 -0
  143. data/lib/adwords_api/v201506/media_service.rb +42 -0
  144. data/lib/adwords_api/v201506/media_service_registry.rb +46 -0
  145. data/lib/adwords_api/v201506/mutate_job_service.rb +42 -0
  146. data/lib/adwords_api/v201506/mutate_job_service_registry.rb +46 -0
  147. data/lib/adwords_api/v201506/offline_conversion_feed_service.rb +34 -0
  148. data/lib/adwords_api/v201506/offline_conversion_feed_service_registry.rb +46 -0
  149. data/lib/adwords_api/v201506/report_definition_service.rb +34 -0
  150. data/lib/adwords_api/v201506/report_definition_service_registry.rb +46 -0
  151. data/lib/adwords_api/v201506/shared_criterion_service.rb +42 -0
  152. data/lib/adwords_api/v201506/shared_criterion_service_registry.rb +46 -0
  153. data/lib/adwords_api/v201506/shared_set_service.rb +42 -0
  154. data/lib/adwords_api/v201506/shared_set_service_registry.rb +46 -0
  155. data/lib/adwords_api/v201506/targeting_idea_service.rb +34 -0
  156. data/lib/adwords_api/v201506/targeting_idea_service_registry.rb +46 -0
  157. data/lib/adwords_api/v201506/traffic_estimator_service.rb +34 -0
  158. data/lib/adwords_api/v201506/traffic_estimator_service_registry.rb +46 -0
  159. data/lib/adwords_api/version.rb +1 -1
  160. data/test/adwords_api/test_adwords_api.rb +1 -1
  161. data/test/adwords_api/test_api_config.rb +8 -8
  162. data/test/adwords_api/test_choices.rb +2 -2
  163. data/test/adwords_api/test_report_utils.rb +1 -1
  164. data/test/templates/v201506/basic_operations_get_campaigns.def +116 -0
  165. data/test/templates/v201506/misc_use_oauth2_jwt.def +131 -0
  166. metadata +156 -2
@@ -0,0 +1,145 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.sgomes@gmail.com (Sérgio Gomes)
5
+ #
6
+ # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
+ #
8
+ # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
+ # implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+ # This example demonstrates how to handle policy violation errors. To create
22
+ # an ad group, run add_ad_group.rb.
23
+ #
24
+ # Tags: AdGroupAdService.mutate
25
+
26
+ require 'adwords_api'
27
+ require 'adwords_api/utils'
28
+
29
+ def handle_policy_violation_error(ad_group_id)
30
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
31
+ # when called without parameters.
32
+ adwords = AdwordsApi::Api.new
33
+
34
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
35
+ # the configuration file or provide your own logger:
36
+ # adwords.logger = Logger.new('adwords_xml.log')
37
+
38
+ ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
39
+
40
+ # Create text ad.
41
+ text_ad_operation = {
42
+ :operator => 'ADD',
43
+ :operand => {
44
+ :ad_group_id => ad_group_id,
45
+ :ad => {
46
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
47
+ # being created. It's only necessary when you must provide an explicit
48
+ # type that the client library can't infer.
49
+ :xsi_type => 'TextAd',
50
+ :headline => 'Mars Cruise!!!',
51
+ :description1 => 'Visit the Red Planet in style.',
52
+ :description2 => 'Low-gravity fun for everyone!',
53
+ :final_urls => ['http://www.example.com'],
54
+ :display_url => 'www.example.com',
55
+ }
56
+ }
57
+ }
58
+
59
+ operations = [text_ad_operation]
60
+
61
+ # Validate ad.
62
+ begin
63
+ # Enable "validate only" for the length of this block
64
+ adwords.validate_only do
65
+ ad_group_ad_srv.mutate(operations)
66
+ end
67
+ puts 'Validation successful, no errors returned.'
68
+ rescue AdwordsApi::Errors::ApiException => e
69
+ e.errors.each do |error|
70
+ if error[:xsi_type] == 'PolicyViolationError'
71
+ operation_index = AdwordsApi::Utils.operation_index_for_error(error)
72
+ operation = operations[operation_index]
73
+ puts "Ad with headline '%s' violated %s policy '%s'." %
74
+ [operation[:operand][:ad][:headline],
75
+ error[:is_exemptable] ? 'exemptable' : 'non-exemptable',
76
+ error[:external_policy_name]]
77
+ if error[:is_exemptable]
78
+ # Add exemption request to the operation.
79
+ puts "Adding exemption request for policy name '%s' on text '%s'." %
80
+ [error[:key][:policy_name], error[:key][:violating_text]]
81
+ unless operation[:exemption_requests]
82
+ operation[:exemption_requests] = []
83
+ end
84
+ operation[:exemption_requests] << {
85
+ :key => error[:key]
86
+ }
87
+ else
88
+ # Remove non-exemptable operation
89
+ puts "Removing the operation from the request."
90
+ operations.delete(operation)
91
+ end
92
+ else
93
+ # Non-policy error returned, re-throw exception.
94
+ raise e
95
+ end
96
+ end
97
+ end
98
+
99
+ # Add ads.
100
+ if operations.size > 0
101
+ response = ad_group_ad_srv.mutate(operations)
102
+ if response and response[:value]
103
+ ads = response[:value]
104
+ puts "Added #{ads.length} ad(s) to ad group #{ad_group_id}."
105
+ ads.each do |ad|
106
+ puts " Ad id is #{ad[:ad][:id]}, type is #{ad[:ad][:xsi_type]} and " +
107
+ "status is \"#{ad[:status]}\"."
108
+ end
109
+ else
110
+ puts "No ads were added."
111
+ end
112
+ end
113
+ end
114
+
115
+ if __FILE__ == $0
116
+ API_VERSION = :v201506
117
+
118
+ begin
119
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
120
+ handle_policy_violation_error(ad_group_id)
121
+
122
+ # Authorization error.
123
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
124
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
125
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
126
+ "to retrieve and store OAuth2 tokens."
127
+ puts "See this wiki page for more details:\n\n " +
128
+ 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
129
+
130
+ # HTTP errors.
131
+ rescue AdsCommon::Errors::HttpError => e
132
+ puts "HTTP Error: %s" % e
133
+
134
+ # API errors.
135
+ rescue AdwordsApi::Errors::ApiException => e
136
+ puts "Message: %s" % e.message
137
+ puts 'Errors:'
138
+ e.errors.each_with_index do |error, index|
139
+ puts "\tError [%d]:" % (index + 1)
140
+ error.each do |field, value|
141
+ puts "\t\t%s: %s" % [field, value]
142
+ end
143
+ end
144
+ end
145
+ end
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.mcloonan@gmail.com (Michael Cloonan)
5
+ #
6
+ # Copyright:: Copyright 2014, 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 adds a feed that syncs feed items from a Google My Business (GMB)
22
+ # account and associates the feed with a customer.
23
+ #
24
+ # Tags: CustomerFeedService.mutate, FeedService.mutate
25
+
26
+ require 'adwords_api'
27
+ require 'date'
28
+
29
+ def add_gmb_location_extensions(gmb_email_address, gmb_access_token,
30
+ business_account_identifier)
31
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
+ # when called without parameters.
33
+ adwords = AdwordsApi::Api.new
34
+
35
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
36
+ # the configuration file or provide your own logger:
37
+ # adwords.logger = Logger.new('adwords_xml.log')
38
+
39
+ feed_srv = adwords.service(:FeedService, API_VERSION)
40
+ customer_feed_srv = adwords.service(:CustomerFeedService, API_VERSION)
41
+
42
+ if gmb_access_token.nil?
43
+ gmb_access_token = adwords.get_auth_handler.get_token(
44
+ adwords.credential_handler.credentials)[:access_token]
45
+ end
46
+
47
+ # Create a feed that will sync to the Google My Business account specified
48
+ # by gmb_email_address. Do not add FeedAttributes to this object, as AdWords
49
+ # will add them automatically because this will be a system generated feed.
50
+ gmb_feed = {
51
+ :name => "GMB feed #%d" % (Time.new.to_f * 1000).to_i,
52
+ :system_feed_generation_data => {
53
+ :xsi_type => 'PlacesLocationFeedData',
54
+ :o_auth_info => {
55
+ :http_method => 'GET',
56
+ :http_request_url => 'https://www.googleapis.com/auth/adwords',
57
+ :http_authorization_header => "Bearer %s" % gmb_access_token
58
+ },
59
+ :email_address => gmb_email_address
60
+ },
61
+ # Since this feed's feed items will be managed by AdWords, you must set
62
+ # its origin to ADWORDS.
63
+ :origin => 'ADWORDS'
64
+ }
65
+ # Only include the business_account_identifier if it's specified.
66
+ # A nil value will cause an invalid request.
67
+ unless business_account_identifier.nil?
68
+ gmb_feed[:system_feed_generation_data][:business_account_identifier] =
69
+ business_account_identifier
70
+ end
71
+
72
+ gmb_operation = {
73
+ :operator => 'ADD',
74
+ :operand => gmb_feed
75
+ }
76
+
77
+ result = feed_srv.mutate([gmb_operation])
78
+ added_feed = result[:value].first
79
+ puts "Added GMB feed with ID %d" % added_feed[:id]
80
+
81
+ # Add a CustomerFeed that associates the feed with this customer for the
82
+ # LOCATION placeholder type.
83
+ customer_feed = {
84
+ :feed_id => added_feed[:id],
85
+ :placeholder_types => [PLACEHOLDER_TYPE_LOCATION],
86
+ :matching_function => {
87
+ :operator => 'IDENTITY',
88
+ :lhs_operand => {
89
+ :xsi_type => 'ConstantOperand',
90
+ :type => 'BOOLEAN',
91
+ :boolean_value => true
92
+ }
93
+ }
94
+ }
95
+
96
+ customer_feed_operation = {
97
+ :xsi_type => 'CustomerFeedOperation',
98
+ :operator => 'ADD',
99
+ :operand => customer_feed
100
+ }
101
+
102
+ added_customer_feed = nil
103
+ number_of_attempts = 0
104
+ while i < MAX_CUSTOMER_FEED_ADD_ATTEMPTS && !added_customer_feed
105
+ number_of_attempts += 1
106
+ begin
107
+ result = customer_feed_srv.mutate([customer_feed_operation])
108
+ added_customer_feed = result[:value].first
109
+ puts "Attempt #%d to add the CustomerFeed was successful" %
110
+ number_of_attempts
111
+ rescue
112
+ sleep_seconds = 5 * (2 ** number_of_attempts)
113
+ puts ("Attempt #%d to add the CustomerFeed was not succeessful. " +
114
+ "Waiting %d seconds before trying again.") %
115
+ [number_of_attempts, sleep_seconds]
116
+ sleep(sleep_seconds)
117
+ end
118
+ end
119
+
120
+ unless added_customer_feed
121
+ raise StandardError, ("Could not create the CustomerFeed after %d " +
122
+ "attempts. Please retry the CustomerFeed ADD operation later.") %
123
+ MAX_CUSTOMER_FEED_ADD_ATTEMPTS
124
+ end
125
+
126
+ puts "Added CustomerFeed for feed ID %d and placeholder type %d" %
127
+ [added_customer_feed[:id], added_customer_feed[:placeholder_types].first]
128
+
129
+ # OPTIONAL: Create a CampaignFeed to specify which FeedItems to use at the
130
+ # Campaign level. This will be similar to the CampaignFeed in the
131
+ # add_site_links example, except you can filter based on the business name
132
+ # and category of each FeedItem by using a FeedAttributeOperand in your
133
+ # matching function.
134
+
135
+ # OPTIONAL: Create an AdGroupFeed for even more fine grained control over
136
+ # which feed items are used at the AdGroup level.
137
+ end
138
+
139
+ if __FILE__ == $0
140
+ API_VERSION = :v201506
141
+ PLACEHOLDER_TYPE_LOCATION = 7
142
+ MAX_CUSTOMER_FEED_ADD_ATTEMPTS = 10
143
+
144
+ begin
145
+ # The email address of either an owner or a manager of the GMB account.
146
+ gmb_email_address = 'INSERT_GMB_EMAIL_ADDRESS_HERE'
147
+
148
+ # If the gmbEmailAddress above is the same as you used to generate your
149
+ # AdWords API refresh token, leave the value below as nil.
150
+ # Otherwise, to obtain an access token for your GMB account, generate a
151
+ # refresh token as you did for AdWords, but make sure you are logged in as
152
+ # the same user as gmb_email_address above when you follow the link, then
153
+ # capture the generated access token
154
+ gmb_access_token = nil
155
+
156
+ # If the gmb_email_address above is for a GMB manager instead of
157
+ # the GMB account owner, then set business_account_identifier to the
158
+ # +Page ID of a location for which the manager has access. See the
159
+ # location extensions guide at
160
+ # https://developers.google.com/adwords/api/docs/guides/feed-services-locations
161
+ # for details.
162
+ business_account_identifier = nil
163
+
164
+ add_gmb_location_extensions(gmb_email_address, gmb_access_token,
165
+ business_account_identifier)
166
+
167
+ # Authorization error.
168
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
169
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
170
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
171
+ "to retrieve and store OAuth2 tokens."
172
+ puts "See this wiki page for more details:\n\n " +
173
+ 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
174
+
175
+ # HTTP errors.
176
+ rescue AdsCommon::Errors::HttpError => e
177
+ puts "HTTP Error: %s" % e
178
+
179
+ # API errors.
180
+ rescue AdwordsApi::Errors::ApiException => e
181
+ puts "Message: %s" % e.message
182
+ puts 'Errors:'
183
+ e.errors.each_with_index do |error, index|
184
+ puts "\tError [%d]:" % (index + 1)
185
+ error.each do |field, value|
186
+ puts "\t\t%s: %s" % [field, value]
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.mcloonan@gmail.com (Michael Cloonan)
5
+ #
6
+ # Copyright:: Copyright 2015, 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 adds a sitelinks feed and associates it with a campaign.
22
+ #
23
+ # Tags: CampaignExtensionSettingService.mutate
24
+
25
+ require 'adwords_api'
26
+ require 'date'
27
+
28
+ def add_site_links(campaign_id)
29
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
30
+ # when called without parameters.
31
+ adwords = AdwordsApi::Api.new
32
+
33
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
34
+ # the configuration file or provide your own logger:
35
+ # adwords.logger = Logger.new('adwords_xml.log')
36
+
37
+ customer_srv = adwords.service(:CustomerService, API_VERSION)
38
+ customer = customer_srv.get()
39
+ customer_time_zone = customer[:date_time_zone]
40
+
41
+ campaign_extension_setting_srv =
42
+ adwords.service(:CampaignExtensionSettingService, API_VERSION)
43
+
44
+ sitelink_1 = {
45
+ :xsi_type => "SitelinkFeedItem",
46
+ :sitelink_text => "Store Hours",
47
+ :sitelink_url => "http://www.example.com/storehours"
48
+ }
49
+
50
+ sitelink_2 = {
51
+ :xsi_type => "SitelinkFeedItem",
52
+ :sitelink_text => "Thanksgiving Specials",
53
+ :sitelink_url => "http://www.example.com/thanksgiving",
54
+ :start_time => DateTime.new(Date.today.year, 11, 20, 0, 0, 0).
55
+ strftime("%Y%m%d %H%M%S ") + customer_time_zone,
56
+ :end_time => DateTime.new(Date.today.year, 11, 27, 23, 59, 59).
57
+ strftime("%Y%m%d %H%M%S ") + customer_time_zone
58
+ }
59
+
60
+ sitelink_3 = {
61
+ :xsi_type => "SitelinkFeedItem",
62
+ :sitelink_text => "Wifi available",
63
+ :sitelink_url => "http://www.example.com/mobile/wifi",
64
+ :device_preference => {:device_preference => 30001}
65
+ }
66
+
67
+ sitelink_4 = {
68
+ :xsi_type => "SitelinkFeedItem",
69
+ :sitelink_text => "Happy hours",
70
+ :sitelink_url => "http://www.example.com/happyhours",
71
+ :scheduling => {
72
+ :feed_item_schedules => [
73
+ {
74
+ :day_of_week => 'MONDAY',
75
+ :start_hour => 18,
76
+ :start_minute => 'ZERO',
77
+ :end_hour => 21,
78
+ :end_minute => 'ZERO'
79
+ },
80
+ {
81
+ :day_of_week => 'TUESDAY',
82
+ :start_hour => 18,
83
+ :start_minute => 'ZERO',
84
+ :end_hour => 21,
85
+ :end_minute => 'ZERO'
86
+ },
87
+ {
88
+ :day_of_week => 'WEDNESDAY',
89
+ :start_hour => 18,
90
+ :start_minute => 'ZERO',
91
+ :end_hour => 21,
92
+ :end_minute => 'ZERO'
93
+ },
94
+ {
95
+ :day_of_week => 'THURSDAY',
96
+ :start_hour => 18,
97
+ :start_minute => 'ZERO',
98
+ :end_hour => 21,
99
+ :end_minute => 'ZERO'
100
+ },
101
+ {
102
+ :day_of_week => 'FRIDAY',
103
+ :start_hour => 18,
104
+ :start_minute => 'ZERO',
105
+ :end_hour => 21,
106
+ :end_minute => 'ZERO'
107
+ }
108
+ ]
109
+ }
110
+ }
111
+
112
+ campaign_extension_setting = {
113
+ :campaign_id => campaign_id,
114
+ :extension_type => 'SITELINK',
115
+ :extension_setting => {
116
+ :extensions => [sitelink_1, sitelink_2, sitelink_3, sitelink_4]
117
+ }
118
+ }
119
+
120
+ operation = {
121
+ :operand => campaign_extension_setting,
122
+ :operator => 'ADD'
123
+ }
124
+
125
+ response = campaign_extension_setting_srv.mutate([operation])
126
+ if response and response[:value]
127
+ new_extension_setting = response[:value].first
128
+ puts "Extension setting wiht type = %s was added to campaign ID %d" % [
129
+ new_extension_setting[:extension_type],
130
+ new_extension_setting[:campaign_id]
131
+ ]
132
+ elsif
133
+ puts "No extension settings were created."
134
+ end
135
+ end
136
+
137
+ if __FILE__ == $0
138
+ API_VERSION = :v201506
139
+
140
+ begin
141
+ # Campaign ID to add site link to.
142
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
143
+ add_site_links(campaign_id)
144
+
145
+ # Authorization error.
146
+ rescue AdsCommon::Errors::OAuth2VerificationRequired => e
147
+ puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
148
+ "OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
149
+ "to retrieve and store OAuth2 tokens."
150
+ puts "See this wiki page for more details:\n\n " +
151
+ 'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
152
+
153
+ # HTTP errors.
154
+ rescue AdsCommon::Errors::HttpError => e
155
+ puts "HTTP Error: %s" % e
156
+
157
+ # API errors.
158
+ rescue AdwordsApi::Errors::ApiException => e
159
+ puts "Message: %s" % e.message
160
+ puts 'Errors:'
161
+ e.errors.each_with_index do |error, index|
162
+ puts "\tError [%d]:" % (index + 1)
163
+ error.each do |field, value|
164
+ puts "\t\t%s: %s" % [field, value]
165
+ end
166
+ end
167
+ end
168
+ end