google-adx-buyer-api 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/ChangeLog +4 -0
  2. data/README +4 -4
  3. data/examples/v201302/account_management/get_account_changes.rb +137 -0
  4. data/examples/v201302/basic_operations/add_ad_group.rb +88 -0
  5. data/examples/v201302/basic_operations/add_campaign.rb +102 -0
  6. data/examples/v201302/basic_operations/add_placements.rb +99 -0
  7. data/examples/v201302/basic_operations/add_thirdparty_redirect_ad.rb +126 -0
  8. data/examples/v201302/basic_operations/delete_ad.rb +80 -0
  9. data/examples/v201302/basic_operations/delete_ad_group.rb +76 -0
  10. data/examples/v201302/basic_operations/delete_campaign.rb +77 -0
  11. data/examples/v201302/basic_operations/delete_placement.rb +86 -0
  12. data/examples/v201302/basic_operations/get_ad_groups.rb +80 -0
  13. data/examples/v201302/basic_operations/get_campaigns.rb +77 -0
  14. data/examples/v201302/basic_operations/get_placements.rb +92 -0
  15. data/examples/v201302/basic_operations/get_thirdparty_redirect_ads.rb +100 -0
  16. data/examples/v201302/basic_operations/pause_ad.rb +81 -0
  17. data/examples/v201302/basic_operations/update_ad_group.rb +76 -0
  18. data/examples/v201302/basic_operations/update_campaign.rb +79 -0
  19. data/examples/v201302/basic_operations/update_placement.rb +94 -0
  20. data/examples/v201302/campaign_management/add_placements_in_bulk.rb +151 -0
  21. data/examples/v201302/campaign_management/get_all_disapproved_ads.rb +92 -0
  22. data/examples/v201302/error_handling/handle_captcha_challenge.rb +93 -0
  23. data/examples/v201302/error_handling/handle_partial_failures.rb +117 -0
  24. data/examples/v201302/error_handling/handle_policy_violation_error.rb +138 -0
  25. data/examples/v201302/error_handling/handle_two_factor_authorization_error.rb +88 -0
  26. data/examples/v201302/misc/get_all_images_and_videos.rb +100 -0
  27. data/examples/v201302/misc/upload_image.rb +89 -0
  28. data/examples/v201302/misc/use_oauth2.rb +97 -0
  29. data/examples/v201302/misc/use_oauth2_jwt.rb +93 -0
  30. data/examples/v201302/optimization/get_placement_ideas.rb +104 -0
  31. data/examples/v201302/remarketing/add_audience.rb +115 -0
  32. data/examples/v201302/remarketing/add_conversion_tracker.rb +96 -0
  33. data/examples/v201302/reporting/download_criteria_report.rb +79 -0
  34. data/examples/v201302/reporting/get_campaign_stats.rb +105 -0
  35. data/examples/v201302/reporting/get_report_fields.rb +71 -0
  36. data/examples/v201302/targeting/add_campaign_targeting_criteria.rb +107 -0
  37. data/examples/v201302/targeting/get_campaign_targeting_criteria.rb +104 -0
  38. data/examples/v201302/targeting/get_targetable_languages_and_carriers.rb +86 -0
  39. data/examples/v201302/targeting/lookup_location.rb +104 -0
  40. metadata +41 -4
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ # Encoding: utf-8
3
+ #
4
+ # Author:: api.dklimkin@gmail.com (Danial Klimkin)
5
+ #
6
+ # Copyright:: Copyright 2012, 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 code example adds a third party redirect ad to an ad group. To create an
22
+ # ad group, run add_ad_group.rb.
23
+ #
24
+ # Tags: AdGroupAdService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def add_thirdparty_redirect_ad(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_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
38
+
39
+ # Create third party redirect ad.
40
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
41
+ # being created. It's only necessary when you must provide an explicit
42
+ # type that the client library can't infer.
43
+ redirect_ad = {
44
+ :xsi_type => 'ThirdPartyRedirectAd',
45
+ :name => 'Example third party ad %d' % (Time.new.to_f * 1000).to_i,
46
+ :url => 'http://www.example.com',
47
+ :dimensions => {
48
+ :height => 250,
49
+ :width => 300
50
+ },
51
+ # This field normally contains the javascript ad tag.
52
+ :snippet =>
53
+ '<img src="https://sandbox.google.com/sandboximages/image.jpg"/>',
54
+ :certified_vendor_format_id => 119,
55
+ :is_cookie_targeted => false,
56
+ :is_user_interest_targeted => false,
57
+ :is_tagged => false
58
+ }
59
+
60
+ # Create in-stream third party redirect ad.
61
+ in_stream_ad = {
62
+ :xsi_type => 'ThirdPartyRedirectAd',
63
+ :name => 'Example in stream ad %d' % (Time.new.to_f * 1000).to_i,
64
+ :url => 'http://www.example.com',
65
+ # 15 secs.
66
+ :ad_duration => 15000,
67
+ :source_url => 'http://ad.doubleclick.net/pfadx/N270.126913.6102203221521' +
68
+ '/B3876671.21;dcadv=2215309;sz=0x0;ord=%5btimestamp%5d;dcmt=text/xml',
69
+ :certified_vendor_format_id => 303,
70
+ :rich_media_ad_type => 'IN_STREAM_VIDEO'
71
+ }
72
+
73
+ # Create operations to add the ads.
74
+ operations = [
75
+ {
76
+ :operator => 'ADD',
77
+ :operand => {
78
+ :ad_group_id => ad_group_id,
79
+ :ad => redirect_ad
80
+ }
81
+ },
82
+ {
83
+ :operator => 'ADD',
84
+ :operand => {
85
+ :ad_group_id => ad_group_id,
86
+ :ad => in_stream_ad
87
+ }
88
+ }
89
+ ]
90
+
91
+ # Add the ads.
92
+ response = ad_group_ad_srv.mutate(operations)
93
+
94
+ ads = response[:value]
95
+ puts "Added %d third party redirect ads to ad group ID %d:" %
96
+ [ads.length, ad_group_id]
97
+ ads.each do |ad|
98
+ puts "\tAd ID %d, type '%s' and status '%s'" %
99
+ [ad[:ad][:id], ad[:ad][:ad_type], ad[:status]]
100
+ end
101
+ end
102
+
103
+ if __FILE__ == $0
104
+ API_VERSION = :v201302
105
+
106
+ begin
107
+ # Ad group ID to add text ads to.
108
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
109
+ add_thirdparty_redirect_ad(ad_group_id)
110
+
111
+ # HTTP errors.
112
+ rescue AdsCommon::Errors::HttpError => e
113
+ puts "HTTP Error: %s" % e
114
+
115
+ # API errors.
116
+ rescue AdwordsApi::Errors::ApiException => e
117
+ puts "Message: %s" % e.message
118
+ puts 'Errors:'
119
+ e.errors.each_with_index do |error, index|
120
+ puts "\tError [%d]:" % (index + 1)
121
+ error.each do |field, value|
122
+ puts "\t\t%s: %s" % [field, value]
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,80 @@
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 deletes an ad using the 'REMOVE' operator. To get ads,
22
+ # run get_thirdparty_redirect_ads.rb.
23
+ #
24
+ # Tags: AdGroupAdService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def delete_ad(ad_group_id, ad_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_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
38
+
39
+ # Prepare for deleting ad.
40
+ operation = {
41
+ :operator => 'REMOVE',
42
+ :operand => {
43
+ :ad_group_id => ad_group_id,
44
+ :ad => {
45
+ :xsi_type => 'Ad',
46
+ :id => ad_id
47
+ }
48
+ }
49
+ }
50
+
51
+ # Delete ad.
52
+ response = ad_group_ad_srv.mutate([operation])
53
+ ad = response[:value].first
54
+ puts "Ad ID %d was successfully deleted." % ad[:ad][:id]
55
+ end
56
+
57
+ if __FILE__ == $0
58
+ API_VERSION = :v201302
59
+
60
+ begin
61
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
62
+ ad_id = 'INSERT_AD_ID_HERE'.to_i
63
+ delete_ad(ad_group_id, ad_id)
64
+
65
+ # HTTP errors.
66
+ rescue AdsCommon::Errors::HttpError => e
67
+ puts "HTTP Error: %s" % e
68
+
69
+ # API errors.
70
+ rescue AdwordsApi::Errors::ApiException => e
71
+ puts "Message: %s" % e.message
72
+ puts 'Errors:'
73
+ e.errors.each_with_index do |error, index|
74
+ puts "\tError [%d]:" % (index + 1)
75
+ error.each do |field, value|
76
+ puts "\t\t%s: %s" % [field, value]
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,76 @@
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 deletes an ad group by setting the status to 'DELETED'.
22
+ # To get ad groups, run get_ad_groups.rb.
23
+ #
24
+ # Tags: AdGroupService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def delete_ad_group(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_srv = adwords.service(:AdGroupService, API_VERSION)
38
+
39
+ # Prepare for deleting ad group.
40
+ operation = {
41
+ :operator => 'SET',
42
+ :operand => {
43
+ :status => 'DELETED',
44
+ :id => ad_group_id
45
+ }
46
+ }
47
+
48
+ # Delete ad group.
49
+ response = ad_group_srv.mutate([operation])
50
+ ad_group = response[:value].first
51
+ puts "Ad group ID %d was successfully deleted." % ad_group[:id]
52
+ end
53
+
54
+ if __FILE__ == $0
55
+ API_VERSION = :v201302
56
+
57
+ begin
58
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
59
+ delete_ad_group(ad_group_id)
60
+
61
+ # HTTP errors.
62
+ rescue AdsCommon::Errors::HttpError => e
63
+ puts "HTTP Error: %s" % e
64
+
65
+ # API errors.
66
+ rescue AdwordsApi::Errors::ApiException => e
67
+ puts "Message: %s" % e.message
68
+ puts 'Errors:'
69
+ e.errors.each_with_index do |error, index|
70
+ puts "\tError [%d]:" % (index + 1)
71
+ error.each do |field, value|
72
+ puts "\t\t%s: %s" % [field, value]
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,77 @@
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 deletes a campaign by setting the status to 'DELETED'. To get
22
+ # campaigns, run get_campaigns.rb.
23
+ #
24
+ # Tags: CampaignService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def delete_campaign(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
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
38
+
39
+ # Prepare for deleting campaign.
40
+ operation = {
41
+ :operator => 'SET',
42
+ :operand => {
43
+ :id => campaign_id,
44
+ :status => 'DELETED',
45
+ }
46
+ }
47
+
48
+ # Delete campaign.
49
+ response = campaign_srv.mutate([operation])
50
+ campaign = response[:value].first
51
+ puts "Campaign with name '%s' and ID %d was deleted." %
52
+ [campaign[:name], campaign[:id]]
53
+ end
54
+
55
+ if __FILE__ == $0
56
+ API_VERSION = :v201302
57
+
58
+ begin
59
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
60
+ delete_campaign(campaign_id)
61
+
62
+ # HTTP errors.
63
+ rescue AdsCommon::Errors::HttpError => e
64
+ puts "HTTP Error: %s" % e
65
+
66
+ # API errors.
67
+ rescue AdwordsApi::Errors::ApiException => e
68
+ puts "Message: %s" % e.message
69
+ puts 'Errors:'
70
+ e.errors.each_with_index do |error, index|
71
+ puts "\tError [%d]:" % (index + 1)
72
+ error.each do |field, value|
73
+ puts "\t\t%s: %s" % [field, value]
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,86 @@
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 deletes a placement using the 'REMOVE' operator. To get list of
22
+ # placements, run get_placements.rb.
23
+ #
24
+ # Tags: AdGroupCriterionService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def delete_placement(ad_group_id, criterion_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
+ # Prepare for deleting placement.
41
+ operation = {
42
+ :operator => 'REMOVE',
43
+ :operand => {
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 => 'BiddableAdGroupCriterion',
48
+ :ad_group_id => ad_group_id,
49
+ :criterion => {
50
+ :id => criterion_id
51
+ }
52
+ }
53
+ }
54
+
55
+ # Delete placement.
56
+ response = ad_group_criterion_srv.mutate([operation])
57
+ ad_group_criterion = response[:value].first
58
+ puts "Placement ID %d was successfully deleted." %
59
+ ad_group_criterion[:criterion][:id]
60
+ end
61
+
62
+ if __FILE__ == $0
63
+ API_VERSION = :v201302
64
+
65
+ begin
66
+ # IDs of criterion to delete and its ad group.
67
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
68
+ criterion_id = 'INSERT_CRITERION_ID_HERE'.to_i
69
+ delete_placement(ad_group_id, criterion_id)
70
+
71
+ # HTTP errors.
72
+ rescue AdsCommon::Errors::HttpError => e
73
+ puts "HTTP Error: %s" % e
74
+
75
+ # API errors.
76
+ rescue AdwordsApi::Errors::ApiException => e
77
+ puts "Message: %s" % e.message
78
+ puts 'Errors:'
79
+ e.errors.each_with_index do |error, index|
80
+ puts "\tError [%d]:" % (index + 1)
81
+ error.each do |field, value|
82
+ puts "\t\t%s: %s" % [field, value]
83
+ end
84
+ end
85
+ end
86
+ end