google-adx-buyer-api 0.4.3 → 0.4.4

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 (40) hide show
  1. data/ChangeLog +4 -0
  2. data/README +3 -3
  3. data/examples/v201209/account_management/get_account_changes.rb +137 -0
  4. data/examples/v201209/basic_operations/add_ad_group.rb +88 -0
  5. data/examples/v201209/basic_operations/add_campaign.rb +105 -0
  6. data/examples/v201209/basic_operations/add_placements.rb +99 -0
  7. data/examples/v201209/basic_operations/add_thirdparty_redirect_ad.rb +126 -0
  8. data/examples/v201209/basic_operations/delete_ad.rb +80 -0
  9. data/examples/{v201206/reporting/download_defined_report.rb → v201209/basic_operations/delete_ad_group.rb} +21 -12
  10. data/examples/v201209/basic_operations/delete_campaign.rb +77 -0
  11. data/examples/v201209/basic_operations/delete_placement.rb +86 -0
  12. data/examples/v201209/basic_operations/get_ad_groups.rb +80 -0
  13. data/examples/v201209/basic_operations/get_campaigns.rb +77 -0
  14. data/examples/v201209/basic_operations/get_placements.rb +92 -0
  15. data/examples/v201209/basic_operations/get_thirdparty_redirect_ads.rb +100 -0
  16. data/examples/v201209/basic_operations/pause_ad.rb +81 -0
  17. data/examples/v201209/basic_operations/update_ad_group.rb +76 -0
  18. data/examples/v201209/basic_operations/update_campaign.rb +79 -0
  19. data/examples/v201209/basic_operations/update_placement.rb +94 -0
  20. data/examples/v201209/campaign_management/add_placements_in_bulk.rb +151 -0
  21. data/examples/v201209/campaign_management/get_all_disapproved_ads.rb +92 -0
  22. data/examples/v201209/error_handling/handle_captcha_challenge.rb +93 -0
  23. data/examples/v201209/error_handling/handle_partial_failures.rb +117 -0
  24. data/examples/v201209/error_handling/handle_policy_violation_error.rb +138 -0
  25. data/examples/v201209/error_handling/handle_two_factor_authorization_error.rb +87 -0
  26. data/examples/v201209/misc/get_all_images_and_videos.rb +101 -0
  27. data/examples/v201209/misc/upload_image.rb +87 -0
  28. data/examples/v201209/misc/use_oauth.rb +97 -0
  29. data/examples/v201209/optimization/get_placement_ideas.rb +106 -0
  30. data/examples/v201209/remarketing/add_audience.rb +111 -0
  31. data/examples/v201209/remarketing/add_conversion_tracker.rb +93 -0
  32. data/examples/v201209/reporting/download_criteria_report.rb +79 -0
  33. data/examples/v201209/reporting/get_campaign_stats.rb +105 -0
  34. data/examples/{v201206/reporting/get_defined_reports.rb → v201209/reporting/get_report_fields.rb} +13 -17
  35. data/examples/v201209/reporting/parallel_report_download.rb +159 -0
  36. data/examples/v201209/targeting/add_campaign_targeting_criteria.rb +110 -0
  37. data/examples/v201209/targeting/get_campaign_targeting_criteria.rb +104 -0
  38. data/examples/v201209/targeting/get_targetable_languages_and_carriers.rb +82 -0
  39. data/examples/v201209/targeting/lookup_location.rb +104 -0
  40. metadata +89 -34
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ 0.4.4.
2
+ - Now require google-adwords-api-0.7.1 or later.
3
+ - Added examples for v201209.
4
+
1
5
  0.4.3:
2
6
  - Now require google-adwords-api-0.6.3 or later.
3
7
  - Added examples for v201206.
data/README CHANGED
@@ -3,8 +3,8 @@
3
3
  Welcome to the next generation Google-developed Ruby client library for the
4
4
  AdWords and DoubleClick Ad Exchange Buyer API!
5
5
 
6
- It contains full support for v201109, v201109_1 and v201206, with full stubs,
7
- and a simplified programming interface that lets you handle everything in
6
+ It contains full support for v201109, v201109_1, v201206 and v201209, with full
7
+ stubs, and a simplified programming interface that lets you handle everything in
8
8
  native Ruby collections.
9
9
 
10
10
 
@@ -58,7 +58,7 @@ You can also pass API a manually constructed config hash like:
58
58
  })
59
59
 
60
60
  Then, just specify which service you're looking to use, and which version:
61
- campaign_srv = adwords.service(:CampaignService, :v201206)
61
+ campaign_srv = adwords.service(:CampaignService, :v201209)
62
62
 
63
63
  and you should now be able to just use the API methods in the object you were
64
64
  returned:
@@ -0,0 +1,137 @@
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 gets all account changes that happened within the last 24 hours,
22
+ # for all your campaigns.
23
+ #
24
+ # Tags: CustomerSyncService.get
25
+
26
+ require 'adwords_api'
27
+ require 'date'
28
+ require 'pp'
29
+
30
+ def get_account_changes()
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
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
40
+ customer_sync_srv = adwords.service(:CustomerSyncService, API_VERSION)
41
+
42
+ today_at_midnight = DateTime.parse(Date.today.to_s)
43
+ yesterday_at_midnight = DateTime.parse((Date.today - 1).to_s)
44
+ min_date_time = yesterday_at_midnight.strftime("%Y%m%d %H%M%S")
45
+ max_date_time = today_at_midnight.strftime("%Y%m%d %H%M%S")
46
+
47
+ # Get all the campaigns for this account.
48
+ selector = {
49
+ :fields => ['Id']
50
+ }
51
+ response = campaign_srv.get(selector)
52
+
53
+ campaign_ids = []
54
+
55
+ if response and response[:entries]
56
+ campaign_ids = response[:entries].map { |campaign| campaign[:id] }
57
+ else
58
+ raise StandardError, 'No campaigns were found.'
59
+ end
60
+
61
+ # Create a selector for CustomerSyncService.
62
+ selector = {
63
+ :campaign_ids => campaign_ids,
64
+ :date_time_range => {
65
+ :min => min_date_time,
66
+ :max => max_date_time
67
+ }
68
+ }
69
+
70
+ # Get all account changes for the campaigns.
71
+ campaign_changes = customer_sync_srv.get(selector)
72
+
73
+ # Display changes.
74
+ if campaign_changes
75
+ puts "Most recent change: %s" % campaign_changes[:last_change_timestamp]
76
+ campaign_changes[:changed_campaigns].each do |campaign|
77
+ puts "Campaign with ID %d was changed:" % campaign[:campaign_id]
78
+ puts "\tCampaign change status: '%s'" % campaign[:campaign_change_status]
79
+ unless ['NEW', 'FIELDS_UNCHANGED'].include?(
80
+ campaign[:campaign_change_status])
81
+ puts "\tAdded ad extensions: '%s'" %
82
+ campaign[:added_ad_extensions].pretty_inspect.chomp
83
+ puts "\tAdded campaign criteria: '%s'" %
84
+ campaign[:added_campaign_criteria].pretty_inspect.chomp
85
+ puts "\tAdded campaign targeting: '%s'" %
86
+ campaign[:campaign_targeting_changed].pretty_inspect.chomp
87
+ puts "\tDeleted ad extensions: '%s'" %
88
+ campaign[:deleted_ad_extensions].pretty_inspect.chomp
89
+ puts "\tDeleted campaign criteria: '%s'" %
90
+ campaign[:deleted_campaign_criteria].pretty_inspect.chomp
91
+
92
+ if campaign[:changed_ad_groups]
93
+ campaign[:changed_ad_groups].each do |ad_group|
94
+ puts "\tAd group with ID %d was changed:" % ad_group[:ad_group_id]
95
+ puts "\t\tAd group changed status: '%s'" %
96
+ ad_group[:ad_group_change_status]
97
+ unless ['NEW', 'FIELDS_UNCHANGED'].include?(
98
+ ad_group[:ad_group_change_status])
99
+ puts "\t\tAds changed: '%s'" %
100
+ ad_group[:changed_ads].pretty_inspect.chomp
101
+ puts "\t\tCriteria changed: '%s'" %
102
+ ad_group[:changed_criteria].pretty_inspect.chomp
103
+ puts "\t\tCriteria deleted: '%s'" %
104
+ ad_group[:deleted_criteria].pretty_inspect.chomp
105
+ end
106
+ end
107
+ end
108
+ end
109
+ puts
110
+ end
111
+ else
112
+ puts 'No account changes were found.'
113
+ end
114
+ end
115
+
116
+ if __FILE__ == $0
117
+ API_VERSION = :v201209
118
+
119
+ begin
120
+ get_account_changes()
121
+
122
+ # HTTP errors.
123
+ rescue AdsCommon::Errors::HttpError => e
124
+ puts "HTTP Error: %s" % e
125
+
126
+ # API errors.
127
+ rescue AdwordsApi::Errors::ApiException => e
128
+ puts "Message: %s" % e.message
129
+ puts 'Errors:'
130
+ e.errors.each_with_index do |error, index|
131
+ puts "\tError [%d]:" % (index + 1)
132
+ error.each do |field, value|
133
+ puts "\t\t%s: %s" % [field, value]
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,88 @@
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 an ad group. To create a campaign, run
22
+ # add_campaign.rb.
23
+ #
24
+ # Tags: AdGroupService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def add_ad_group(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
+ # Prepare for adding ad group.
40
+ operation = {
41
+ :operator => 'ADD',
42
+ :operand => {
43
+ :name => 'Earth to Mars Cruises #%s' % (Time.new.to_f * 1000).to_i,
44
+ :status => 'ENABLED',
45
+ :campaign_id => campaign_id,
46
+ :bids => {
47
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
48
+ # being created. It's only necessary when you must provide an explicit
49
+ # type that the client library can't infer.
50
+ :xsi_type => 'ManualCPMAdGroupBids',
51
+ :max_cpc => {
52
+ :amount => {
53
+ :micro_amount => 10000000
54
+ }
55
+ }
56
+ },
57
+ }
58
+ }
59
+
60
+ # Add ad group.
61
+ response = ad_group_srv.mutate([operation])
62
+ ad_group = response[:value].first
63
+ puts "Ad group ID %d was successfully added." % ad_group[:id]
64
+ end
65
+
66
+ if __FILE__ == $0
67
+ API_VERSION = :v201209
68
+
69
+ begin
70
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
71
+ add_ad_group(campaign_id)
72
+
73
+ # HTTP errors.
74
+ rescue AdsCommon::Errors::HttpError => e
75
+ puts "HTTP Error: %s" % e
76
+
77
+ # API errors.
78
+ rescue AdwordsApi::Errors::ApiException => e
79
+ puts "Message: %s" % e.message
80
+ puts 'Errors:'
81
+ e.errors.each_with_index do |error, index|
82
+ puts "\tError [%d]:" % (index + 1)
83
+ error.each do |field, value|
84
+ puts "\t\t%s: %s" % [field, value]
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,105 @@
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 a campaign.
22
+ #
23
+ # Tags: CampaignService.mutate, BudgetService.mutate
24
+
25
+ require 'adwords_api'
26
+
27
+ def add_campaign()
28
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
29
+ # when called without parameters.
30
+ adwords = AdwordsApi::Api.new
31
+
32
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
33
+ # the configuration file or provide your own logger:
34
+ # adwords.logger = Logger.new('adwords_xml.log')
35
+
36
+ budget_srv = adwords.service(:BudgetService, API_VERSION)
37
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
38
+
39
+ # Create a budget, which can be shared by multiple campaigns.
40
+ budget = {
41
+ :name => 'Interplanetary budget #%d' % (Time.new.to_f * 1000).to_i,
42
+ :amount => {:micro_amount => 50000000},
43
+ :delivery_method => 'STANDARD',
44
+ :period => 'DAILY'
45
+ }
46
+ budget_operation = {:operator => 'ADD', :operand => budget}
47
+
48
+ # Add budget.
49
+ return_budget = budget_srv.mutate([budget_operation])
50
+ budget_id = return_budget[:value].first[:budget_id]
51
+
52
+ # Prepare for adding campaign.
53
+ operation = {
54
+ :operator => 'ADD',
55
+ :operand => {
56
+ :name => 'Interplanetary Cruise #%s' % (Time.new.to_f * 1000).to_i,
57
+ :status => 'PAUSED',
58
+ :bidding_strategy => {
59
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
60
+ # being created. It's only necessary when you must provide an explicit
61
+ # type that the client library can't infer.
62
+ :xsi_type => 'ManualCPM'
63
+ },
64
+ :budget => {:budget_id => budget_id},
65
+ # Set the campaign network options to Search and Search Network.
66
+ :network_setting => {
67
+ :target_google_search => false,
68
+ :target_search_network => false,
69
+ :target_content_network => true
70
+ },
71
+ :settings => [
72
+ {:xsi_type => 'RealTimeBiddingSetting', :opt_in => 'true'}
73
+ ]
74
+ }
75
+ }
76
+
77
+ # Add campaign.
78
+ response = campaign_srv.mutate([operation])
79
+ campaign = response[:value].first
80
+ puts "Campaign with name '%s' and ID %d was added." %
81
+ [campaign[:name], campaign[:id]]
82
+ end
83
+
84
+ if __FILE__ == $0
85
+ API_VERSION = :v201209
86
+
87
+ begin
88
+ add_campaign()
89
+
90
+ # HTTP errors.
91
+ rescue AdsCommon::Errors::HttpError => e
92
+ puts "HTTP Error: %s" % e
93
+
94
+ # API errors.
95
+ rescue AdwordsApi::Errors::ApiException => e
96
+ puts "Message: %s" % e.message
97
+ puts 'Errors:'
98
+ e.errors.each_with_index do |error, index|
99
+ puts "\tError [%d]:" % (index + 1)
100
+ error.each do |field, value|
101
+ puts "\t\t%s: %s" % [field, value]
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,99 @@
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 a placement to a given ad group. To create
22
+ # an ad group, run add_ad_group.rb.
23
+ #
24
+ # Tags: AdGroupCriterionService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def add_placements(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 placements.
41
+ placements = [
42
+ {
43
+ :xsi_type => 'BiddableAdGroupCriterion',
44
+ :ad_group_id => ad_group_id,
45
+ :criterion => {
46
+ :xsi_type => 'Placement',
47
+ :url => 'http://mars.google.com'
48
+ }
49
+ },
50
+ {
51
+ :xsi_type => 'BiddableAdGroupCriterion',
52
+ :ad_group_id => ad_group_id,
53
+ :criterion => {
54
+ :xsi_type => 'Placement',
55
+ :url => 'http://pluto.google.com'
56
+ }
57
+ },
58
+ ]
59
+
60
+ # Create operations to add placements.
61
+ plc_operations = placements.map do |placement|
62
+ {:operator => 'ADD', :operand => placement}
63
+ end
64
+
65
+ # Add placements.
66
+ response = ad_group_criterion_srv.mutate(plc_operations)
67
+ ad_group_criteria = response[:value]
68
+ puts "Added %d placements to ad group ID %d." %
69
+ [ad_group_criteria.length, ad_group_id]
70
+ ad_group_criteria.each do |ad_group_criterion|
71
+ puts "\tPlacement ID is %d and type is '%s'." %
72
+ [ad_group_criterion[:criterion][:id],
73
+ ad_group_criterion[:criterion][:xsi_type]]
74
+ end
75
+ end
76
+
77
+ if __FILE__ == $0
78
+ API_VERSION = :v201209
79
+
80
+ begin
81
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
82
+ add_placements(ad_group_id)
83
+
84
+ # HTTP errors.
85
+ rescue AdsCommon::Errors::HttpError => e
86
+ puts "HTTP Error: %s" % e
87
+
88
+ # API errors.
89
+ rescue AdwordsApi::Errors::ApiException => e
90
+ puts "Message: %s" % e.message
91
+ puts 'Errors:'
92
+ e.errors.each_with_index do |error, index|
93
+ puts "\tError [%d]:" % (index + 1)
94
+ error.each do |field, value|
95
+ puts "\t\t%s: %s" % [field, value]
96
+ end
97
+ end
98
+ end
99
+ end