google-adwords-api 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. data/ChangeLog +6 -0
  2. data/README +3 -3
  3. data/examples/{v201206/basic_operations/delete_ad_group.rb → v201209/adwords_for_video/add_video_campaign.rb} +41 -40
  4. data/examples/{v201206/basic_operations/pause_ad.rb → v201209/adwords_for_video/find_videos.rb} +33 -25
  5. data/examples/{v201206/basic_operations/get_keywords.rb → v201209/adwords_for_video/get_keyword_criteria.rb} +24 -27
  6. data/examples/{v201206/basic_operations/get_campaigns_with_awql.rb → v201209/adwords_for_video/get_targeting_groups.rb} +26 -18
  7. data/examples/{v201206/basic_operations/get_ad_groups.rb → v201209/adwords_for_video/get_video_campaign_criteria.rb} +22 -21
  8. data/examples/v201209/adwords_for_video/get_video_campaign_stats.rb +126 -0
  9. data/examples/{v201206/basic_operations/get_campaigns.rb → v201209/adwords_for_video/get_video_campaigns.rb} +16 -15
  10. data/examples/v201302/advanced_operations/create_and_attach_shared_keyword_set.rb +139 -0
  11. data/examples/v201302/advanced_operations/find_and_remove_criteria_from_shared_set.rb +173 -0
  12. data/lib/adwords_api/api_config.rb +17 -59
  13. data/lib/adwords_api/report_utils.rb +3 -19
  14. data/lib/adwords_api/{v201206/ad_param_service.rb → v201209/video_ad_service.rb} +8 -8
  15. data/lib/adwords_api/v201209/video_ad_service_registry.rb +46 -0
  16. data/lib/adwords_api/{v201206/campaign_ad_extension_service.rb → v201209/video_campaign_criterion_service.rb} +8 -8
  17. data/lib/adwords_api/v201209/video_campaign_criterion_service_registry.rb +47 -0
  18. data/lib/adwords_api/{v201206/bulk_mutate_job_service.rb → v201209/video_campaign_service.rb} +8 -8
  19. data/lib/adwords_api/v201209/video_campaign_service_registry.rb +46 -0
  20. data/lib/adwords_api/v201209/video_service.rb +42 -0
  21. data/lib/adwords_api/v201209/video_service_registry.rb +46 -0
  22. data/lib/adwords_api/{v201206/ad_group_ad_service.rb → v201209/video_targeting_group_criterion_service.rb} +8 -12
  23. data/lib/adwords_api/v201209/video_targeting_group_criterion_service_registry.rb +46 -0
  24. data/lib/adwords_api/{v201206/ad_extension_override_service.rb → v201209/video_targeting_group_service.rb} +8 -8
  25. data/lib/adwords_api/v201209/video_targeting_group_service_registry.rb +46 -0
  26. data/lib/adwords_api/v201302/ad_group_feed_service.rb +1 -1
  27. data/lib/adwords_api/v201302/ad_group_feed_service_registry.rb +2 -2
  28. data/lib/adwords_api/v201302/campaign_feed_service.rb +1 -1
  29. data/lib/adwords_api/v201302/campaign_feed_service_registry.rb +2 -2
  30. data/lib/adwords_api/v201302/feed_item_service.rb +1 -1
  31. data/lib/adwords_api/v201302/feed_item_service_registry.rb +3 -4
  32. data/lib/adwords_api/v201302/feed_service.rb +1 -1
  33. data/lib/adwords_api/v201302/feed_service_registry.rb +4 -5
  34. data/lib/adwords_api/{v201206/user_list_service.rb → v201302/shared_set_service.rb} +9 -9
  35. data/lib/adwords_api/v201302/shared_set_service_registry.rb +47 -0
  36. data/lib/adwords_api/version.rb +1 -1
  37. data/test/adwords_api/test_report_utils.rb +0 -89
  38. data/test/examples/v201302/test_advanced_operations.rb +10 -0
  39. data/test/templates/v201209/basic_operations_get_campaigns.def +1 -1
  40. data/test/templates/v201302/basic_operations_get_campaigns.def +1 -1
  41. data/test/templates/v201302/misc_use_oauth2_jwt.def +131 -0
  42. data/test/test_utils.rb +6 -2
  43. metadata +26 -121
  44. data/examples/v201206/account_management/create_account.rb +0 -87
  45. data/examples/v201206/account_management/get_account_alerts.rb +0 -114
  46. data/examples/v201206/account_management/get_account_changes.rb +0 -137
  47. data/examples/v201206/account_management/get_account_hierarchy.rb +0 -95
  48. data/examples/v201206/account_management/get_client_customer_id.rb +0 -88
  49. data/examples/v201206/account_management/get_client_unit_usage.rb +0 -90
  50. data/examples/v201206/basic_operations/add_ad_groups.rb +0 -136
  51. data/examples/v201206/basic_operations/add_campaigns.rb +0 -151
  52. data/examples/v201206/basic_operations/add_keywords.rb +0 -108
  53. data/examples/v201206/basic_operations/add_text_ads.rb +0 -105
  54. data/examples/v201206/basic_operations/delete_ad.rb +0 -85
  55. data/examples/v201206/basic_operations/delete_campaign.rb +0 -103
  56. data/examples/v201206/basic_operations/delete_keyword.rb +0 -90
  57. data/examples/v201206/basic_operations/get_text_ads.rb +0 -106
  58. data/examples/v201206/basic_operations/update_ad_group.rb +0 -81
  59. data/examples/v201206/basic_operations/update_campaign.rb +0 -84
  60. data/examples/v201206/basic_operations/update_keyword.rb +0 -99
  61. data/examples/v201206/campaign_management/add_experiment.rb +0 -158
  62. data/examples/v201206/campaign_management/add_keywords_in_bulk.rb +0 -150
  63. data/examples/v201206/campaign_management/add_location_extension.rb +0 -117
  64. data/examples/v201206/campaign_management/add_location_extension_override.rb +0 -83
  65. data/examples/v201206/campaign_management/get_all_disapproved_ads.rb +0 -93
  66. data/examples/v201206/campaign_management/get_all_disapproved_ads_with_awql.rb +0 -84
  67. data/examples/v201206/campaign_management/promote_experiment.rb +0 -77
  68. data/examples/v201206/campaign_management/set_ad_parameters.rb +0 -114
  69. data/examples/v201206/campaign_management/validate_text_ad.rb +0 -106
  70. data/examples/v201206/error_handling/handle_captcha_challenge.rb +0 -93
  71. data/examples/v201206/error_handling/handle_partial_failures.rb +0 -126
  72. data/examples/v201206/error_handling/handle_policy_violation_error.rb +0 -137
  73. data/examples/v201206/error_handling/handle_two_factor_authorization_error.rb +0 -88
  74. data/examples/v201206/misc/get_all_images_and_videos.rb +0 -100
  75. data/examples/v201206/misc/upload_image.rb +0 -89
  76. data/examples/v201206/misc/use_oauth2.rb +0 -97
  77. data/examples/v201206/optimization/estimate_keyword_traffic.rb +0 -129
  78. data/examples/v201206/optimization/get_keyword_bid_simulations.rb +0 -92
  79. data/examples/v201206/optimization/get_keyword_ideas.rb +0 -114
  80. data/examples/v201206/optimization/get_placement_ideas.rb +0 -104
  81. data/examples/v201206/remarketing/add_audience.rb +0 -115
  82. data/examples/v201206/remarketing/add_conversion_tracker.rb +0 -97
  83. data/examples/v201206/reporting/download_criteria_report.rb +0 -79
  84. data/examples/v201206/reporting/download_criteria_report_with_awql.rb +0 -78
  85. data/examples/v201206/reporting/get_campaign_stats.rb +0 -105
  86. data/examples/v201206/reporting/get_report_fields.rb +0 -71
  87. data/examples/v201206/reporting/parallel_report_download.rb +0 -162
  88. data/examples/v201206/targeting/add_campaign_targeting_criteria.rb +0 -118
  89. data/examples/v201206/targeting/get_campaign_targeting_criteria.rb +0 -102
  90. data/examples/v201206/targeting/get_targetable_languages_and_carriers.rb +0 -86
  91. data/examples/v201206/targeting/lookup_location.rb +0 -104
  92. data/lib/adwords_api/v201206/ad_extension_override_service_registry.rb +0 -46
  93. data/lib/adwords_api/v201206/ad_group_ad_service_registry.rb +0 -46
  94. data/lib/adwords_api/v201206/ad_group_criterion_service.rb +0 -42
  95. data/lib/adwords_api/v201206/ad_group_criterion_service_registry.rb +0 -46
  96. data/lib/adwords_api/v201206/ad_group_service.rb +0 -42
  97. data/lib/adwords_api/v201206/ad_group_service_registry.rb +0 -46
  98. data/lib/adwords_api/v201206/ad_param_service_registry.rb +0 -46
  99. data/lib/adwords_api/v201206/alert_service.rb +0 -34
  100. data/lib/adwords_api/v201206/alert_service_registry.rb +0 -46
  101. data/lib/adwords_api/v201206/budget_order_service.rb +0 -42
  102. data/lib/adwords_api/v201206/budget_order_service_registry.rb +0 -46
  103. data/lib/adwords_api/v201206/bulk_mutate_job_service_registry.rb +0 -46
  104. data/lib/adwords_api/v201206/campaign_ad_extension_service_registry.rb +0 -46
  105. data/lib/adwords_api/v201206/campaign_criterion_service.rb +0 -42
  106. data/lib/adwords_api/v201206/campaign_criterion_service_registry.rb +0 -46
  107. data/lib/adwords_api/v201206/campaign_service.rb +0 -42
  108. data/lib/adwords_api/v201206/campaign_service_registry.rb +0 -46
  109. data/lib/adwords_api/v201206/constant_data_service.rb +0 -62
  110. data/lib/adwords_api/v201206/constant_data_service_registry.rb +0 -46
  111. data/lib/adwords_api/v201206/conversion_tracker_service.rb +0 -38
  112. data/lib/adwords_api/v201206/conversion_tracker_service_registry.rb +0 -46
  113. data/lib/adwords_api/v201206/customer_service.rb +0 -34
  114. data/lib/adwords_api/v201206/customer_service_registry.rb +0 -46
  115. data/lib/adwords_api/v201206/customer_sync_service.rb +0 -34
  116. data/lib/adwords_api/v201206/customer_sync_service_registry.rb +0 -47
  117. data/lib/adwords_api/v201206/data_service.rb +0 -38
  118. data/lib/adwords_api/v201206/data_service_registry.rb +0 -46
  119. data/lib/adwords_api/v201206/experiment_service.rb +0 -38
  120. data/lib/adwords_api/v201206/experiment_service_registry.rb +0 -46
  121. data/lib/adwords_api/v201206/geo_location_service.rb +0 -34
  122. data/lib/adwords_api/v201206/geo_location_service_registry.rb +0 -46
  123. data/lib/adwords_api/v201206/info_service.rb +0 -34
  124. data/lib/adwords_api/v201206/info_service_registry.rb +0 -46
  125. data/lib/adwords_api/v201206/location_criterion_service.rb +0 -34
  126. data/lib/adwords_api/v201206/location_criterion_service_registry.rb +0 -46
  127. data/lib/adwords_api/v201206/managed_customer_service.rb +0 -38
  128. data/lib/adwords_api/v201206/managed_customer_service_registry.rb +0 -46
  129. data/lib/adwords_api/v201206/media_service.rb +0 -38
  130. data/lib/adwords_api/v201206/media_service_registry.rb +0 -46
  131. data/lib/adwords_api/v201206/mutate_job_service.rb +0 -42
  132. data/lib/adwords_api/v201206/mutate_job_service_registry.rb +0 -46
  133. data/lib/adwords_api/v201206/report_definition_service.rb +0 -34
  134. data/lib/adwords_api/v201206/report_definition_service_registry.rb +0 -46
  135. data/lib/adwords_api/v201206/targeting_idea_service.rb +0 -38
  136. data/lib/adwords_api/v201206/targeting_idea_service_registry.rb +0 -46
  137. data/lib/adwords_api/v201206/traffic_estimator_service.rb +0 -34
  138. data/lib/adwords_api/v201206/traffic_estimator_service_registry.rb +0 -46
  139. data/lib/adwords_api/v201206/user_list_service_registry.rb +0 -46
  140. data/test/examples/v201206/test_account_management.rb +0 -60
  141. data/test/examples/v201206/test_basic_operations.rb +0 -177
  142. data/test/examples/v201206/test_campaign_management.rb +0 -124
  143. data/test/examples/v201206/test_error_handling.rb +0 -63
  144. data/test/examples/v201206/test_misc.rb +0 -39
  145. data/test/examples/v201206/test_optimization.rb +0 -63
  146. data/test/examples/v201206/test_remarketing.rb +0 -39
  147. data/test/examples/v201206/test_reporting.rb +0 -84
  148. data/test/examples/v201206/test_targeting.rb +0 -60
  149. data/test/examples/v201206/utils.rb +0 -244
  150. data/test/suite_exampletests_v201206.rb +0 -37
@@ -1,90 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to retrieve the number of API units usage for a
22
- # client account for the current month.
23
- #
24
- # Note: This code example uses MCC-level calls and won't work with Test
25
- # Accounts, see: https://developers.google.com/adwords/api/docs/test-accounts
26
- #
27
- # Tags: InfoService.get
28
-
29
- require 'adwords_api'
30
-
31
- def get_client_unit_usage(client_customer_id)
32
- # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
33
- # when called without parameters.
34
- adwords = AdwordsApi::Api.new
35
-
36
- # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
37
- # the configuration file or provide your own logger:
38
- # adwords.logger = Logger.new('adwords_xml.log')
39
-
40
- info_srv = adwords.service(:InfoService, API_VERSION)
41
-
42
- start_date = Time.now.strftime('%Y%m01')
43
- end_date = Time.now.strftime('%Y%m%d')
44
-
45
- selector = {
46
- :api_usage_type => 'UNIT_COUNT_FOR_CLIENTS',
47
- :client_customer_ids => [client_customer_id],
48
- # Set to true to navigate your entire accounts tree.
49
- :include_sub_accounts => 1,
50
- :date_range => {
51
- :min => start_date,
52
- :max => end_date
53
- }
54
- }
55
-
56
- # Force to use the MCC credentials.
57
- adwords.use_mcc do
58
- # Get the unit info.
59
- info_srv.get(selector) do |header, response|
60
- puts "Total number of units consumed from %s to %s is %d." %
61
- [start_date, end_date, response[:cost]]
62
- puts "Number of units consumed by this request is %d" % header[:units]
63
- end
64
- end
65
- end
66
-
67
- if __FILE__ == $0
68
- API_VERSION = :v201206
69
-
70
- begin
71
- # Specify client customer ID for the account to get usage for.
72
- client_customer_id = 'INSERT_CLIENT_CUSTOMER_ID_HERE'.to_i
73
- get_client_unit_usage(client_customer_id)
74
-
75
- # HTTP errors.
76
- rescue AdsCommon::Errors::HttpError => e
77
- puts "HTTP Error: %s" % e
78
-
79
- # API errors.
80
- rescue AdwordsApi::Errors::ApiException => e
81
- puts "Message: %s" % e.message
82
- puts 'Errors:'
83
- e.errors.each_with_index do |error, index|
84
- puts "\tError [%d]:" % (index + 1)
85
- error.each do |field, value|
86
- puts "\t\t%s: %s" % [field, value]
87
- end
88
- end
89
- end
90
- end
@@ -1,136 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to create ad groups. To get a list of existing
22
- # campaigns run get_campaigns.rb.
23
- #
24
- # Tags: AdGroupService.mutate
25
-
26
- require 'adwords_api'
27
-
28
- def add_ad_groups(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
- ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
38
-
39
- ad_groups = [
40
- {
41
- :name => "Earth to Mars Cruises #%d" % (Time.new.to_f * 1000).to_i,
42
- :status => 'ENABLED',
43
- :campaign_id => campaign_id,
44
- :bids => {
45
- # The 'xsi_type' field allows you to specify the xsi:type of the object
46
- # being created. It's only necessary when you must provide an explicit
47
- # type that the client library can't infer.
48
- :xsi_type => 'ManualCPCAdGroupBids',
49
- :keyword_max_cpc => {
50
- :amount => {
51
- :micro_amount => 10000000
52
- }
53
- },
54
- # Optional field.
55
- :keyword_content_max_cpc => {:amount => {:micro_amount => 2000000}}
56
- },
57
- :settings => [
58
- # Targetting restriction settings - these setting only affect serving
59
- # for the Display Network.
60
- {
61
- :xsi_type => 'TargetingSetting',
62
- :details => [
63
- # Restricting to serve ads that match your ad group placements.
64
- {
65
- :xsi_type => 'TargetingSettingDetail',
66
- :criterion_type_group => 'PLACEMENT',
67
- :target_all => true
68
- },
69
- # Using your ad group verticals only for bidding.
70
- {
71
- :xsi_type => 'TargetingSettingDetail',
72
- :criterion_type_group => 'VERTICAL',
73
- :target_all => false
74
- }
75
- ]
76
- }
77
- ]
78
- },
79
- {
80
- :name => 'Earth to Pluto Cruises #%d' % (Time.new.to_f * 1000).to_i,
81
- :status => 'ENABLED',
82
- :campaign_id => campaign_id,
83
- :bids => {
84
- # The 'xsi_type' field allows you to specify the xsi:type of the object
85
- # being created. It's only necessary when you must provide an explicit
86
- # type that the client library can't infer.
87
- :xsi_type => 'ManualCPCAdGroupBids',
88
- :keyword_max_cpc => {
89
- :amount => {
90
- :micro_amount => 10000000
91
- }
92
- }
93
- }
94
- }
95
- ]
96
-
97
- # Prepare operations for adding ad groups.
98
- operations = ad_groups.map do |ad_group|
99
- {:operator => 'ADD', :operand => ad_group}
100
- end
101
-
102
- # Add ad groups.
103
- response = ad_group_srv.mutate(operations)
104
- if response and response[:value]
105
- response[:value].each do |ad_group|
106
- puts "Ad group ID %d was successfully added." % ad_group[:id]
107
- end
108
- else
109
- raise StandardError, 'No ad group was added'
110
- end
111
- end
112
-
113
- if __FILE__ == $0
114
- API_VERSION = :v201206
115
-
116
- begin
117
- # Campaign ID to add ad group to.
118
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
119
- add_ad_groups(campaign_id)
120
-
121
- # HTTP errors.
122
- rescue AdsCommon::Errors::HttpError => e
123
- puts "HTTP Error: %s" % e
124
-
125
- # API errors.
126
- rescue AdwordsApi::Errors::ApiException => e
127
- puts "Message: %s" % e.message
128
- puts 'Errors:'
129
- e.errors.each_with_index do |error, index|
130
- puts "\tError [%d]:" % (index + 1)
131
- error.each do |field, value|
132
- puts "\t\t%s: %s" % [field, value]
133
- end
134
- end
135
- end
136
- end
@@ -1,151 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to create campaigns.
22
- #
23
- # Tags: CampaignService.mutate
24
-
25
- require 'adwords_api'
26
- require 'date'
27
-
28
- def add_campaigns()
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
- campaign_srv = adwords.service(:CampaignService, API_VERSION)
38
-
39
- campaigns = [
40
- {
41
- :name => "Interplanetary Cruise #%d" % (Time.new.to_f * 1000).to_i,
42
- :status => 'PAUSED',
43
- :bidding_strategy => {
44
- # The 'xsi_type' field allows you to specify the xsi:type of the object
45
- # being created. It's only necessary when you must provide an explicit
46
- # type that the client library can't infer.
47
- :xsi_type => 'ManualCPC'
48
- },
49
- :budget => {
50
- :period => 'DAILY',
51
- :amount => {:micro_amount => 50000000},
52
- :delivery_method => 'STANDARD'
53
- },
54
- # Set the campaign network options to Search and Search Network.
55
- :network_setting => {
56
- :target_google_search => true,
57
- :target_search_network => true,
58
- :target_content_network => true
59
- },
60
- # Optional fields:
61
- :start_date =>
62
- DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d'),
63
- :ad_serving_optimization_status => 'ROTATE',
64
- :settings => [
65
- # Display network targeting settings (optional).
66
- # It can only be enabled, shown only for demonstration purposes.
67
- # If not set this setting is enabled by default on ADD operations.
68
- {
69
- :xsi_type => 'TargetRestrictSetting',
70
- :use_ad_group => true
71
- },
72
- {
73
- :xsi_type => 'GeoTargetTypeSetting',
74
- :positive_geo_target_type => 'DONT_CARE',
75
- :negative_geo_target_type => 'DONT_CARE'
76
- },
77
- {
78
- :xsi_type => 'KeywordMatchSetting',
79
- :opt_in => true
80
- }
81
- ],
82
- :frequency_cap => {
83
- :impressions => '5',
84
- :time_unit => 'DAY',
85
- :level => 'ADGROUP'
86
- }
87
- },
88
- {
89
- :name => "Interplanetary Cruise banner #%d" % (Time.new.to_f * 1000).to_i,
90
- :status => 'PAUSED',
91
- :bidding_strategy => {
92
- :xsi_type => 'ManualCPM'
93
- },
94
- :budget => {
95
- :period => 'DAILY',
96
- :amount => {:micro_amount => 150000000},
97
- :delivery_method => 'STANDARD'
98
- },
99
- :settings => [
100
- {
101
- :xsi_type => 'KeywordMatchSetting',
102
- :opt_in => true
103
- }
104
- ],
105
- :network_setting => {
106
- :target_google_search => false,
107
- :target_search_network => false,
108
- :target_content_network => true
109
- }
110
- }
111
- ]
112
-
113
- # Prepare for adding campaign.
114
- operations = campaigns.map do |campaign|
115
- {:operator => 'ADD', :operand => campaign}
116
- end
117
-
118
- # Add campaign.
119
- response = campaign_srv.mutate(operations)
120
- if response and response[:value]
121
- response[:value].each do |campaign|
122
- puts "Campaign with name '%s' and ID %d was added." %
123
- [campaign[:name], campaign[:id]]
124
- end
125
- else
126
- raise new StandardError, 'No campaigns were added.'
127
- end
128
- end
129
-
130
- if __FILE__ == $0
131
- API_VERSION = :v201206
132
-
133
- begin
134
- add_campaigns()
135
-
136
- # HTTP errors.
137
- rescue AdsCommon::Errors::HttpError => e
138
- puts "HTTP Error: %s" % e
139
-
140
- # API errors.
141
- rescue AdwordsApi::Errors::ApiException => e
142
- puts "Message: %s" % e.message
143
- puts 'Errors:'
144
- e.errors.each_with_index do |error, index|
145
- puts "\tError [%d]:" % (index + 1)
146
- error.each do |field, value|
147
- puts "\t\t%s: %s" % [field, value]
148
- end
149
- end
150
- end
151
- end
@@ -1,108 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: utf-8
3
- #
4
- # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
- #
6
- # Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
7
- #
8
- # License:: Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17
- # implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
- # This example illustrates how to add multiple keywords to a given ad group. To
22
- # create an ad group, run add_ad_group.rb.
23
- #
24
- # Tags: AdGroupCriterionService.mutate
25
-
26
- require 'adwords_api'
27
-
28
- def add_keywords(ad_group_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
- ad_group_criterion_srv =
38
- adwords.service(:AdGroupCriterionService, API_VERSION)
39
-
40
- # Create keywords.
41
- # The 'xsi_type' field allows you to specify the xsi:type of the object
42
- # being created. It's only necessary when you must provide an explicit
43
- # type that the client library can't infer.
44
- keywords = [
45
- {:xsi_type => 'BiddableAdGroupCriterion',
46
- :ad_group_id => ad_group_id,
47
- :criterion => {
48
- :xsi_type => 'Keyword',
49
- :text => 'mars cruise',
50
- :match_type => 'BROAD'
51
- },
52
- # Optional fields:
53
- :user_status => 'PAUSED',
54
- :destination_url => 'http://example.com/mars'
55
- },
56
- {:xsi_type => 'BiddableAdGroupCriterion',
57
- :ad_group_id => ad_group_id,
58
- :criterion => {
59
- :xsi_type => 'Keyword',
60
- :text => 'space hotel',
61
- :match_type => 'BROAD'}}
62
- ]
63
-
64
- # Create 'ADD' operations.
65
- operations = keywords.map do |keyword|
66
- {:operator => 'ADD', :operand => keyword}
67
- end
68
-
69
- # Add keywords.
70
- response = ad_group_criterion_srv.mutate(operations)
71
- if response and response[:value]
72
- ad_group_criteria = response[:value]
73
- puts "Added %d keywords to ad group ID %d:" %
74
- [ad_group_criteria.length, ad_group_id]
75
- ad_group_criteria.each do |ad_group_criterion|
76
- puts "\tKeyword ID is %d and type is '%s'" %
77
- [ad_group_criterion[:criterion][:id],
78
- ad_group_criterion[:criterion][:type]]
79
- end
80
- else
81
- raise StandardError, 'No keywords were added.'
82
- end
83
- end
84
-
85
- if __FILE__ == $0
86
- API_VERSION = :v201206
87
-
88
- begin
89
- # Ad group ID to add keywords to.
90
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
91
- add_keywords(ad_group_id)
92
-
93
- # HTTP errors.
94
- rescue AdsCommon::Errors::HttpError => e
95
- puts "HTTP Error: %s" % e
96
-
97
- # API errors.
98
- rescue AdwordsApi::Errors::ApiException => e
99
- puts "Message: %s" % e.message
100
- puts 'Errors:'
101
- e.errors.each_with_index do |error, index|
102
- puts "\tError [%d]:" % (index + 1)
103
- error.each do |field, value|
104
- puts "\t\t%s: %s" % [field, value]
105
- end
106
- end
107
- end
108
- end