adwords4r 13.0.1 → 15.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. data/Authors.txt +2 -1
  2. data/ChangeLog.txt +28 -0
  3. data/Copying.txt +1 -1
  4. data/{Licence.txt → License.txt} +1 -1
  5. data/Rakefile +49 -54
  6. data/Readme.txt +78 -24
  7. data/adwords.properties +1 -1
  8. data/examples/account_info.rb +20 -26
  9. data/examples/create_all.rb +51 -53
  10. data/examples/create_all_v200902.rb +204 -0
  11. data/examples/keyword_suggestions.rb +35 -38
  12. data/examples/multiple_versions.rb +167 -0
  13. data/examples/reports.rb +37 -75
  14. data/lib/adwords4r.rb +123 -123
  15. data/lib/adwords4r/adwordslogger.rb +56 -0
  16. data/lib/adwords4r/apiextensions.rb +79 -0
  17. data/lib/adwords4r/authtoken.rb +56 -0
  18. data/lib/adwords4r/credentials.rb +115 -19
  19. data/lib/adwords4r/services.rb +139 -14
  20. data/lib/adwords4r/soap4rpatches.rb +129 -0
  21. data/lib/adwords4r/v13/AccountService.rb +11 -11
  22. data/lib/adwords4r/v13/AccountServiceDriver.rb +7 -5
  23. data/lib/adwords4r/v13/AccountServiceMappingRegistry.rb +56 -56
  24. data/lib/adwords4r/v13/AdGroupService.rb +9 -9
  25. data/lib/adwords4r/v13/AdGroupServiceDriver.rb +11 -9
  26. data/lib/adwords4r/v13/AdGroupServiceMappingRegistry.rb +47 -47
  27. data/lib/adwords4r/v13/AdService.rb +37 -37
  28. data/lib/adwords4r/v13/AdServiceDriver.rb +12 -10
  29. data/lib/adwords4r/v13/AdServiceMappingRegistry.rb +148 -148
  30. data/lib/adwords4r/v13/CampaignService.rb +46 -25
  31. data/lib/adwords4r/v13/CampaignServiceDriver.rb +23 -13
  32. data/lib/adwords4r/v13/CampaignServiceMappingRegistry.rb +169 -135
  33. data/lib/adwords4r/v13/CriterionService.rb +19 -19
  34. data/lib/adwords4r/v13/CriterionServiceDriver.rb +11 -9
  35. data/lib/adwords4r/v13/CriterionServiceMappingRegistry.rb +90 -90
  36. data/lib/adwords4r/v13/InfoService.rb +3 -3
  37. data/lib/adwords4r/v13/InfoServiceDriver.rb +10 -8
  38. data/lib/adwords4r/v13/InfoServiceMappingRegistry.rb +29 -29
  39. data/lib/adwords4r/v13/KeywordToolService.rb +10 -10
  40. data/lib/adwords4r/v13/KeywordToolServiceDriver.rb +4 -2
  41. data/lib/adwords4r/v13/KeywordToolServiceMappingRegistry.rb +37 -37
  42. data/lib/adwords4r/v13/ReportService.rb +13 -13
  43. data/lib/adwords4r/v13/ReportServiceDriver.rb +9 -7
  44. data/lib/adwords4r/v13/ReportServiceMappingRegistry.rb +54 -54
  45. data/lib/adwords4r/v13/SiteSuggestionService.rb +15 -15
  46. data/lib/adwords4r/v13/SiteSuggestionServiceDriver.rb +6 -4
  47. data/lib/adwords4r/v13/SiteSuggestionServiceMappingRegistry.rb +57 -57
  48. data/lib/adwords4r/v13/TrafficEstimatorService.rb +17 -17
  49. data/lib/adwords4r/v13/TrafficEstimatorServiceDriver.rb +6 -4
  50. data/lib/adwords4r/v13/TrafficEstimatorServiceMappingRegistry.rb +96 -96
  51. data/lib/adwords4r/v200902/AdGroupAdService.rb +2021 -0
  52. data/lib/adwords4r/v200902/AdGroupAdServiceDriver.rb +63 -0
  53. data/lib/adwords4r/v200902/AdGroupAdServiceMappingRegistry.rb +2234 -0
  54. data/lib/adwords4r/v200902/AdGroupCriterionService.rb +1209 -0
  55. data/lib/adwords4r/v200902/AdGroupCriterionServiceDriver.rb +63 -0
  56. data/lib/adwords4r/v200902/AdGroupCriterionServiceMappingRegistry.rb +1434 -0
  57. data/lib/adwords4r/v200902/AdGroupService.rb +968 -0
  58. data/lib/adwords4r/{v12/KeywordToolServiceDriver.rb → v200902/AdGroupServiceDriver.rb} +15 -13
  59. data/lib/adwords4r/v200902/AdGroupServiceMappingRegistry.rb +1114 -0
  60. data/lib/adwords4r/v200902/CampaignCriterionService.rb +741 -0
  61. data/lib/adwords4r/v200902/CampaignCriterionServiceDriver.rb +63 -0
  62. data/lib/adwords4r/v200902/CampaignCriterionServiceMappingRegistry.rb +904 -0
  63. data/lib/adwords4r/v200902/CampaignService.rb +1249 -0
  64. data/lib/adwords4r/v200902/CampaignServiceDriver.rb +63 -0
  65. data/lib/adwords4r/v200902/CampaignServiceMappingRegistry.rb +1466 -0
  66. data/lib/adwords4r/v200902/CampaignTargetService.rb +1156 -0
  67. data/lib/adwords4r/v200902/CampaignTargetServiceDriver.rb +63 -0
  68. data/lib/adwords4r/v200902/CampaignTargetServiceMappingRegistry.rb +1304 -0
  69. data/setup.rb +0 -0
  70. metadata +57 -65
  71. data/lib/adwords4r/v12/AccountService.rb +0 -215
  72. data/lib/adwords4r/v12/AccountServiceDriver.rb +0 -69
  73. data/lib/adwords4r/v12/AccountServiceMappingRegistry.rb +0 -243
  74. data/lib/adwords4r/v12/AdGroupService.rb +0 -263
  75. data/lib/adwords4r/v12/AdGroupServiceDriver.rb +0 -109
  76. data/lib/adwords4r/v12/AdGroupServiceMappingRegistry.rb +0 -280
  77. data/lib/adwords4r/v12/AdService.rb +0 -769
  78. data/lib/adwords4r/v12/AdServiceDriver.rb +0 -125
  79. data/lib/adwords4r/v12/AdServiceMappingRegistry.rb +0 -813
  80. data/lib/adwords4r/v12/CampaignService.rb +0 -498
  81. data/lib/adwords4r/v12/CampaignServiceDriver.rb +0 -133
  82. data/lib/adwords4r/v12/CampaignServiceMappingRegistry.rb +0 -642
  83. data/lib/adwords4r/v12/CriterionService.rb +0 -445
  84. data/lib/adwords4r/v12/CriterionServiceDriver.rb +0 -117
  85. data/lib/adwords4r/v12/CriterionServiceMappingRegistry.rb +0 -509
  86. data/lib/adwords4r/v12/InfoService.rb +0 -242
  87. data/lib/adwords4r/v12/InfoServiceDriver.rb +0 -109
  88. data/lib/adwords4r/v12/InfoServiceMappingRegistry.rb +0 -228
  89. data/lib/adwords4r/v12/KeywordToolService.rb +0 -205
  90. data/lib/adwords4r/v12/KeywordToolServiceMappingRegistry.rb +0 -227
  91. data/lib/adwords4r/v12/ReportService.rb +0 -322
  92. data/lib/adwords4r/v12/ReportServiceDriver.rb +0 -101
  93. data/lib/adwords4r/v12/ReportServiceMappingRegistry.rb +0 -298
  94. data/lib/adwords4r/v12/SiteSuggestionService.rb +0 -242
  95. data/lib/adwords4r/v12/SiteSuggestionServiceDriver.rb +0 -77
  96. data/lib/adwords4r/v12/SiteSuggestionServiceMappingRegistry.rb +0 -271
  97. data/lib/adwords4r/v12/TrafficEstimatorService.rb +0 -312
  98. data/lib/adwords4r/v12/TrafficEstimatorServiceDriver.rb +0 -77
  99. data/lib/adwords4r/v12/TrafficEstimatorServiceMappingRegistry.rb +0 -483
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # Copyright 2008, Google Inc. All Rights Reserved.
3
+ # Copyright 2009, Google Inc. All Rights Reserved.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
18
18
  # keywords, and website criteria, all in one fell swoop.
19
19
 
20
20
  require 'rubygems'
21
- gem 'soap4r', '>= 1.5.8'
21
+ gem 'soap4r', '= 1.5.8'
22
22
  require 'adwords4r'
23
23
 
24
24
 
@@ -38,72 +38,76 @@ def main()
38
38
  # specified inline as a hash:
39
39
  #
40
40
  # creds = {
41
- # 'developerToken' => 'user@domain.com++USD',
42
- # 'useragent' => 'Sample User Agent',
43
- # 'password' => 'password',
44
- # 'email' => 'user@domain.com',
45
- # 'clientEmail' => 'client_1+user@domain.com',
46
- # 'applicationToken' => 'IGNORED',
47
- # 'alternateUrl' => 'https://sandbox.google.com/api/adwords/v13/',
41
+ # 'developerToken' => 'user@domain.com++USD',
42
+ # 'useragent' => 'Sample User Agent',
43
+ # 'password' => 'password',
44
+ # 'email' => 'user@domain.com',
45
+ # 'clientEmail' => 'client_1+user@domain.com',
46
+ # 'applicationToken' => 'IGNORED',
47
+ # 'alternateUrl' => 'https://sandbox.google.com/api/adwords/v13/',
48
48
  # }
49
- # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds), 13)
50
-
49
+ # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds))
51
50
  adwords = AdWords::API.new
52
51
 
53
52
  # Alternatively, you can create new AdWords::Campaign, AdWords::AdGroup,
54
53
  # etc. objects and set their properties instead of working with hashes.
55
54
  campaign_data = {
56
- :name => 'Sample Campaign %s' % Time.new.to_s, # Ensure name is unique.
57
- :budgetAmount => 1000000, # 1000000 micros = 1 unit of currency.
58
- :budgetPeriod => 'Daily',
59
- :languageTargeting => ['en'], # If the default all-language targeting is
60
- # used then website placements criteria
61
- # would not be supported.
62
- :status => 'Paused', # Pause the campaign so that it doesn't actually run.
63
- # Default geo and network targeting will be used.
55
+ :name => 'Sample Campaign %s' % Time.new.to_s, # Ensure name is unique.
56
+ :budgetAmount => 1000000, # 1000000 micros = 1 unit of currency.
57
+ :budgetPeriod => 'Daily',
58
+ :languageTargeting => ['en'], # If the default all-language targeting is
59
+ # used then website placements criteria
60
+ # would not be supported.
61
+ :status => 'Paused', # Pause campaign so that it doesn't actually run.
62
+ # Default geo and network targeting will be used.
64
63
  }
65
64
 
66
- campaign = adwords.addCampaign(campaign_data).addCampaignReturn
65
+ campaign_srv = adwords.get_service(13, 'Campaign')
66
+ campaign = campaign_srv.addCampaign(campaign_data).addCampaignReturn
67
67
  puts 'Campaign id %d was successfully added.' % campaign.id
68
68
 
69
69
  ad_group_data = {
70
- :name => 'Sample Ad Group %s' % Time.new.to_s, # Ensure name is unique.
71
- :keywordMaxCpc => 100000, # 100000 micros = 0.1 unit of currency.
72
- :siteMaxCpc => 100000, # 100000 micros = 0.1 unit of currency.
70
+ :name => 'Sample Ad Group %s' % Time.new.to_s, # Ensure name is unique.
71
+ :keywordMaxCpc => 100000, # 100000 micros = 0.1 unit of currency.
72
+ :siteMaxCpc => 100000, # 100000 micros = 0.1 unit of currency.
73
73
  }
74
74
 
75
- ad_group = adwords.addAdGroup(campaign.id, ad_group_data).addAdGroupReturn
75
+ ad_group_srv = adwords.get_service(13, 'AdGroup')
76
+ ad_group =
77
+ ad_group_srv.addAdGroup(campaign.id, ad_group_data).addAdGroupReturn
76
78
  puts 'Ad group id %d was successfully added.' % ad_group.id
77
79
 
78
80
  ad_data = {
79
- :adGroupId => ad_group.id,
80
- :adType => 'TextAd',
81
- :headline => 'AdWords API Ruby Library',
82
- :description1 => 'Write AdWords API apps in Ruby.',
83
- :description2 => 'Use adwords4r!',
84
- :destinationUrl => 'http://code.google.com/p/google-api-adwords-ruby/',
85
- :displayUrl => 'http://code.google.com/',
81
+ :adGroupId => ad_group.id,
82
+ :adType => 'TextAd',
83
+ :headline => 'AdWords API Ruby Library',
84
+ :description1 => 'Write AdWords API apps in Ruby.',
85
+ :description2 => 'Use adwords4r!',
86
+ :destinationUrl => 'http://code.google.com/p/google-api-adwords-ruby/',
87
+ :displayUrl => 'http://code.google.com/',
86
88
  }
87
89
 
88
- ad = adwords.addAds([ad_data])[0]
90
+ ad_srv = adwords.get_service(13, 'Ad')
91
+ ad = ad_srv.addAds([ad_data])[0]
89
92
  puts 'Text ad id %d was successfully added.' % ad.id
90
93
 
91
94
  keyword_data = {
92
- :adGroupId => ad_group.id,
93
- :criterionType => 'Keyword',
94
- :text => 'adwords4r',
95
- :type => 'Broad', # Or 'Phrase' or 'Exact' if desired.
96
- # Default ad destination URL and ad group CPC values will be used.
95
+ :adGroupId => ad_group.id,
96
+ :criterionType => 'Keyword',
97
+ :text => 'adwords4r',
98
+ :type => 'Broad', # Or 'Phrase' or 'Exact' if desired.
99
+ # Default ad destination URL and ad group CPC values will be used.
97
100
  }
98
101
 
99
102
  website_data = {
100
- :adGroupId => ad_group.id,
101
- :criterionType => 'Website',
102
- :url => 'http://www.ruby-forum.com/', # Target this site for ads.
103
- # Default ad destination URL and ad group CPC values will be used.
103
+ :adGroupId => ad_group.id,
104
+ :criterionType => 'Website',
105
+ :url => 'http://www.ruby-forum.com/', # Target this site for ads.
106
+ # Default ad destination URL and ad group CPC values will be used.
104
107
  }
105
108
 
106
- criteria = adwords.addCriteria([keyword_data, website_data])
109
+ criterion_srv = adwords.get_service(13, 'Criterion')
110
+ criteria = criterion_srv.addCriteria([keyword_data, website_data])
107
111
  criteria.each do |criterion|
108
112
  puts 'Criterion id %d was successfully added.' % criterion.id
109
113
  end
@@ -111,16 +115,14 @@ def main()
111
115
  rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
112
116
  # This exception indicates a connection-level error.
113
117
  # In general, it is likely to be transitory.
114
-
115
118
  puts 'Connection Error: %s' % e
116
119
  puts 'Source: %s' % e.backtrace.first
117
-
120
+
118
121
  rescue AdWords::Error::UnknownAPICall => e
119
122
  # This exception is thrown when an unknown SOAP method is invoked.
120
-
121
123
  puts e
122
124
  puts 'Source: %s' % e.backtrace.first
123
-
125
+
124
126
  rescue AdWords::Error::ApiError => e
125
127
  # This exception maps to receiving a SOAP Fault back from the service.
126
128
  # The e.soap_faultstring_ex, e.code_ex, and potentially e.trigger_ex
@@ -133,7 +135,6 @@ def main()
133
135
  # puts '%s => %s' % [var, value]
134
136
  # end
135
137
  # end
136
-
137
138
  puts 'SOAP Error: %s (code: %d)' % [e.soap_faultstring_ex, e.code_ex]
138
139
  puts 'Trigger: %s' % e.trigger_ex unless e.trigger_ex.nil?
139
140
  puts 'Source: %s' % e.backtrace.first
@@ -141,13 +142,11 @@ def main()
141
142
  ensure
142
143
  # Display API unit usage info. This data is stored as a class variable
143
144
  # in the AdWords::API class and accessed via static methods.
144
- # AdWords::API.get_total_units() returns a running total of units used in
145
- # the scope of the current program.
146
- # AdWords::API.get_last_units() returns the number used in the last call.
147
-
145
+ # total_units() returns a running total of units used in the scope of the
146
+ # current program. last_units() returns the number used in the last call.
148
147
  puts
149
148
  puts '%d API units consumed total (%d in last call).' %
150
- [AdWords::API.get_total_units(), AdWords::API.get_last_units()]
149
+ [adwords.total_units, adwords.last_units]
151
150
  end
152
151
  end
153
152
 
@@ -158,7 +157,6 @@ if __FILE__ == $0
158
157
  # To enable this, set the ADWORDS4R_DEBUG environement varaible to 'true'.
159
158
  # This can be done either from your operating system environment or via
160
159
  # code, as done below.
161
-
162
160
  ENV['ADWORDS4R_DEBUG'] = 'false'
163
161
 
164
162
  main()
@@ -0,0 +1,204 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # Copyright 2009, Google Inc. All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ # This code sample illustrates how to create a new campaign, ad group, text ad,
18
+ # keywords, and website criteria, all in one fell swoop, in the v200902 sandbox.
19
+
20
+ require 'rubygems'
21
+ gem 'soap4r', '= 1.5.8'
22
+ require 'adwords4r'
23
+
24
+
25
+ def main()
26
+ begin
27
+ # AdWords::AdWordsCredentials.new will read a credentials file from
28
+ # ENV['HOME']/adwords.properties when called without parameters.
29
+ # The latest versioned release of the API will be assumed.
30
+ #
31
+ # In this case, we'll assume v200902 sandbox credentials, so only the
32
+ # email, password and clientEmail fields are used.
33
+ # v2009 Sandbox environment credentials overview:
34
+ # http://code.google.com/apis/adwords/v2009/docs/headers.html
35
+ #
36
+ # Instead of reading them from a file, the credentials can be
37
+ # specified inline as a hash:
38
+ #
39
+ # creds = {
40
+ # 'email' => 'user@domain.com',
41
+ # 'password' => 'password',
42
+ # 'clientEmail' => 'client_1+user@domain.com'
43
+ # }
44
+ # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds))
45
+ adwords = AdWords::API.new
46
+
47
+ campaign_srv = adwords.get_service(200902, 'Campaign')
48
+ ad_group_srv = adwords.get_service(200902, 'AdGroup')
49
+ ad_group_ad_srv = adwords.get_service(200902, 'AdGroupAd')
50
+ ad_group_criterion_srv = adwords.get_service(200902, 'AdGroupCriterion')
51
+
52
+ # You can create the required items either via hashes or as new Campaign,
53
+ # AdGroup, etc. objects and set their properties. You can even mix both
54
+ # approaches, as is done below.
55
+
56
+ # Prepare for adding campaign.
57
+ operation = {
58
+ :operand => {
59
+ :name => 'Sample Campaign - %s' % Time.new,
60
+ :status => 'ACTIVE',
61
+ :biddingStrategy => AdWords::V200902::CampaignService::ManualCPC.new,
62
+ :budget => {
63
+ :period => 'DAILY',
64
+ :amount => {
65
+ :currencyCode => 'EUR',
66
+ :microAmount => 50000000
67
+ },
68
+ :deliveryMethod => 'STANDARD'
69
+ }
70
+ },
71
+ :operator => 'ADD'
72
+ }
73
+ # Add campaign.
74
+ response = campaign_srv.mutate([operation])
75
+ campaign = response.rval.value.first
76
+ puts 'Campaign id %d was successfully added.' % campaign.id.id
77
+
78
+ # Prepare for adding ad group.
79
+ bids = AdWords::V200902::AdGroupService::ManualCPCAdGroupBids.new
80
+ keyword_max_cpc = {
81
+ :amount => {
82
+ :currencyCode => 'USD',
83
+ :microAmount => 10000000
84
+ }
85
+ }
86
+ bids.keywordMaxCpc = keyword_max_cpc
87
+ operation = {
88
+ :operand => {
89
+ :name => 'Sample Ad Group - %s' % Time.new,
90
+ :status => 'ENABLED',
91
+ :campaignId => {
92
+ :id => campaign.id.id
93
+ },
94
+ :bids => bids,
95
+ },
96
+ :operator => 'ADD'
97
+ }
98
+ # Add ad group.
99
+ response = ad_group_srv.mutate([operation])
100
+ ad_group = response.rval.value.first
101
+ puts 'Ad group id %d was successfully added.' % ad_group.id.id
102
+
103
+ # Prepare for adding ad.
104
+ text_ad = AdWords::V200902::AdGroupAdService::TextAd.new
105
+ text_ad.url = 'http://www.example.com'
106
+ text_ad.displayUrl = 'www.example.com'
107
+ text_ad.headline = 'Luxury Cruise to Mars'
108
+ text_ad.description1 = 'Visit the Red Planet in style.'
109
+ text_ad.description2 = 'Low-gravity fun for everyone!'
110
+ operation = {
111
+ :operand => {
112
+ :adGroupId => {
113
+ :id => ad_group.id.id
114
+ },
115
+ :ad => text_ad
116
+ },
117
+ :operator => 'ADD'
118
+ }
119
+ # Add ad.
120
+ response = ad_group_ad_srv.mutate([operation])
121
+ ad = response.rval.value.first.ad
122
+ puts 'Text ad id %d was successfully added.' % ad.id.id
123
+
124
+ # Prepare for adding keyword.
125
+ kwd_operation =
126
+ AdWords::V200902::AdGroupCriterionService::AdGroupCriterionOperation.new
127
+ kwd_operand =
128
+ AdWords::V200902::AdGroupCriterionService::BiddableAdGroupCriterion.new
129
+ kwd_operand.adGroupId = { :id => ad_group.id.id }
130
+ keyword = AdWords::V200902::AdGroupCriterionService::Keyword.new
131
+ keyword.matchType = 'BROAD'
132
+ keyword.text = 'mars cruise'
133
+ kwd_operand.criterion = keyword
134
+ kwd_operation.operand = kwd_operand
135
+ kwd_operation.operator = 'ADD'
136
+ kwd_operation.exemptionRequests = []
137
+ # Prepare for adding placement.
138
+ plc_operation =
139
+ AdWords::V200902::AdGroupCriterionService::AdGroupCriterionOperation.new
140
+ plc_operand =
141
+ AdWords::V200902::AdGroupCriterionService::BiddableAdGroupCriterion.new
142
+ plc_operand.adGroupId = { :id => ad_group.id.id }
143
+ placement = AdWords::V200902::AdGroupCriterionService::Placement.new
144
+ placement.url = 'http://www.ruby-forum.com/'
145
+ plc_operand.criterion = placement
146
+ plc_operation.operand = plc_operand
147
+ plc_operation.operator = 'ADD'
148
+ plc_operation.exemptionRequests = []
149
+ # Add both criteria.
150
+ response = ad_group_criterion_srv.mutate([kwd_operation, plc_operation])
151
+ criteria = response.rval.value
152
+ criteria.each do |criterion|
153
+ puts 'Criterion id %d was successfully added.' % criterion.criterion.id.id
154
+ end
155
+
156
+ rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
157
+ # This exception indicates a connection-level error.
158
+ # In general, it is likely to be transitory.
159
+ puts 'Connection Error: %s' % e
160
+ puts 'Source: %s' % e.backtrace.first
161
+
162
+ rescue AdWords::Error::UnknownAPICall => e
163
+ # This exception is thrown when an unknown SOAP method is invoked.
164
+ puts e
165
+ puts 'Source: %s' % e.backtrace.first
166
+
167
+ rescue AdWords::Error::ApiError => e
168
+ # This exception maps to receiving a SOAP Fault back from the service.
169
+ # The e.soap_faultstring_ex, e.code_ex, and potentially e.trigger_ex
170
+ # attributes are the most useful, but other attributes may be populated
171
+ # as well. To display all attributes, the following can be used:
172
+ #
173
+ # e.instance_variables.each do |var|
174
+ # value = e.instance_variable_get(var)
175
+ # if ! value.nil?
176
+ # puts '%s => %s' % [var, value]
177
+ # end
178
+ # end
179
+ puts 'SOAP Error: %s (code: %d)' % [e.soap_faultstring_ex, e.code_ex]
180
+ puts 'Trigger: %s' % e.trigger_ex unless e.trigger_ex.nil?
181
+ puts 'Source: %s' % e.backtrace.first
182
+
183
+ ensure
184
+ # Display API unit usage info. This data is stored as a class variable
185
+ # in the AdWords::API class and accessed via static methods.
186
+ # total_units() returns a running total of units used in the scope of the
187
+ # current program. last_units() returns the number used in the last call.
188
+ puts
189
+ puts '%d API units consumed total (%d in last call).' %
190
+ [adwords.total_units, adwords.last_units]
191
+ end
192
+ end
193
+
194
+
195
+ if __FILE__ == $0
196
+ # The adwords4r library can log all SOAP requests and responses to files.
197
+ # This is often useful for debugging purposes.
198
+ # To enable this, set the ADWORDS4R_DEBUG environement varaible to 'true'.
199
+ # This can be done either from your operating system environment or via
200
+ # code, as done below.
201
+ ENV['ADWORDS4R_DEBUG'] = 'false'
202
+
203
+ main()
204
+ end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/ruby
2
2
  #
3
- # Copyright 2008, Google Inc. All Rights Reserved.
3
+ # Copyright 2009, Google Inc. All Rights Reserved.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@
18
18
  # and then estimate the traffic that the "top" variations might receive.
19
19
 
20
20
  require 'rubygems'
21
- gem 'soap4r', '>= 1.5.8'
21
+ gem 'soap4r', '= 1.5.8'
22
22
  require 'adwords4r'
23
23
 
24
24
 
@@ -38,21 +38,19 @@ def main()
38
38
  # specified inline as a hash:
39
39
  #
40
40
  # creds = {
41
- # 'developerToken' => 'user@domain.com++USD',
42
- # 'useragent' => 'Sample User Agent',
43
- # 'password' => 'password',
44
- # 'email' => 'user@domain.com',
45
- # 'clientEmail' => 'client_1+user@domain.com',
46
- # 'applicationToken' => 'IGNORED',
47
- # 'alternateUrl' => 'https://sandbox.google.com/api/adwords/v13/',
41
+ # 'developerToken' => 'user@domain.com++USD',
42
+ # 'useragent' => 'Sample User Agent',
43
+ # 'password' => 'password',
44
+ # 'email' => 'user@domain.com',
45
+ # 'clientEmail' => 'client_1+user@domain.com',
46
+ # 'applicationToken' => 'IGNORED',
47
+ # 'alternateUrl' => 'https://sandbox.google.com/api/adwords/v13/',
48
48
  # }
49
- # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds), 13)
50
-
49
+ # adwords = AdWords::API.new(AdWords::AdWordsCredentials.new(creds))
51
50
  adwords = AdWords::API.new
52
51
 
53
52
  # Modify the following values to set the seed keywords, language,
54
53
  # country targeting, and synonyms options.
55
-
56
54
  keywords = ['new york']
57
55
  languages = %w{en}
58
56
  countries = %w{US}
@@ -60,15 +58,16 @@ def main()
60
58
 
61
59
  seed_keywords = []
62
60
  keywords.each do |keyword|
63
- seed_keyword = AdWords::KeywordToolService::SeedKeyword.new
61
+ seed_keyword = AdWords::V13::KeywordToolService::SeedKeyword.new
64
62
  seed_keyword.text = keyword
65
63
  seed_keyword.type = 'Broad' # Or 'Phrase' or 'Exact' if desired.
66
64
  seed_keywords << seed_keyword
67
65
  end
68
66
 
69
- variations = adwords.getKeywordVariations(seed_keywords, use_synonyms,
70
- languages, countries
71
- ).getKeywordVariationsReturn
67
+ kwdtool_srv = adwords.get_service(13, 'KeywordTool')
68
+ variations =
69
+ kwdtool_srv.getKeywordVariations(seed_keywords, use_synonyms, languages,
70
+ countries).getKeywordVariationsReturn
72
71
 
73
72
  # Sort the list of variations using the following criteria:
74
73
  # - treat moreSpecific and additionalToConsider results identically
@@ -83,9 +82,9 @@ def main()
83
82
  end
84
83
  variation_objects.sort! do |a, b|
85
84
  if b.avgSearchVolume == a.avgSearchVolume
86
- a.lastMonthSearchVolume <=> b.lastMonthSearchVolume
85
+ a.lastMonthSearchVolume <=> b.lastMonthSearchVolume
87
86
  else
88
- b.avgSearchVolume <=> a.avgSearchVolume
87
+ b.avgSearchVolume <=> a.avgSearchVolume
89
88
  end
90
89
  end
91
90
 
@@ -95,27 +94,31 @@ def main()
95
94
  keywords_to_estimate << variation_object.text
96
95
  end
97
96
 
98
- ad_group_request = AdWords::TrafficEstimatorService::AdGroupRequest.new
97
+ ad_group_request = AdWords::V13::TrafficEstimatorService::AdGroupRequest.new
99
98
  ad_group_request.maxCpc = 1000000
100
99
  keywords_to_estimate.each do |keyword_to_estimate|
101
- keyword_request = AdWords::TrafficEstimatorService::KeywordRequest.new
100
+ keyword_request =
101
+ AdWords::V13::TrafficEstimatorService::KeywordRequest.new
102
102
  keyword_request.text = keyword_to_estimate
103
103
  keyword_request.type = 'Broad' # Or 'Phrase' or 'Exact' if desired.
104
104
  ad_group_request.keywordRequests << keyword_request
105
105
  end
106
106
 
107
- geo_targeting = AdWords::TrafficEstimatorService::GeoTarget.new
108
- countryTargets = AdWords::TrafficEstimatorService::CountryTargets.new
107
+ geo_targeting = AdWords::V13::TrafficEstimatorService::GeoTarget.new
108
+ countryTargets = AdWords::V13::TrafficEstimatorService::CountryTargets.new
109
109
  countryTargets.countries = countries
110
110
  geo_targeting.countryTargets = countryTargets
111
111
 
112
- campaign_request = AdWords::TrafficEstimatorService::CampaignRequest.new
112
+ campaign_request =
113
+ AdWords::V13::TrafficEstimatorService::CampaignRequest.new
113
114
  campaign_request.adGroupRequests = ad_group_request
114
115
  campaign_request.geoTargeting = geo_targeting
115
116
  campaign_request.languageTargeting = languages
116
117
  campaign_request.networkTargeting = %w{SearchNetwork ContentNetwork}
117
118
 
118
- campaign_estimate = adwords.estimateCampaignList([campaign_request]).first
119
+ traffic_est_srv = adwords.get_service(13, 'TrafficEstimator')
120
+ campaign_estimate =
121
+ traffic_est_srv.estimateCampaignList([campaign_request]).first
119
122
  ad_group_estimate = campaign_estimate.adGroupEstimates.first
120
123
  keyword_estimates = ad_group_estimate.keywordEstimates
121
124
  for i in 0..keyword_estimates.length - 1
@@ -123,24 +126,22 @@ def main()
123
126
  text = keywords_to_estimate[i]
124
127
 
125
128
  puts "Keyword: %s\tClicks: %f - %f\tCPC: %d - %d\tPosition: %f - %f" %
126
- [text, estimate.lowerClicksPerDay, estimate.upperClicksPerDay,
127
- estimate.lowerCpc, estimate.upperCpc, estimate.lowerAvgPosition,
128
- estimate.upperAvgPosition]
129
+ [text, estimate.lowerClicksPerDay, estimate.upperClicksPerDay,
130
+ estimate.lowerCpc, estimate.upperCpc, estimate.lowerAvgPosition,
131
+ estimate.upperAvgPosition]
129
132
  end
130
133
 
131
134
  rescue Errno::ECONNRESET, SOAP::HTTPStreamError, SocketError => e
132
135
  # This exception indicates a connection-level error.
133
136
  # In general, it is likely to be transitory.
134
-
135
137
  puts 'Connection Error: %s' % e
136
138
  puts 'Source: %s' % e.backtrace.first
137
-
139
+
138
140
  rescue AdWords::Error::UnknownAPICall => e
139
141
  # This exception is thrown when an unknown SOAP method is invoked.
140
-
141
142
  puts e
142
143
  puts 'Source: %s' % e.backtrace.first
143
-
144
+
144
145
  rescue AdWords::Error::ApiError => e
145
146
  # This exception maps to receiving a SOAP Fault back from the service.
146
147
  # The e.soap_faultstring_ex, e.code_ex, and potentially e.trigger_ex
@@ -153,7 +154,6 @@ def main()
153
154
  # puts '%s => %s' % [var, value]
154
155
  # end
155
156
  # end
156
-
157
157
  puts 'SOAP Error: %s (code: %d)' % [e.soap_faultstring_ex, e.code_ex]
158
158
  puts 'Trigger: %s' % e.trigger_ex unless e.trigger_ex.nil?
159
159
  puts 'Source: %s' % e.backtrace.first
@@ -161,13 +161,11 @@ def main()
161
161
  ensure
162
162
  # Display API unit usage info. This data is stored as a class variable
163
163
  # in the AdWords::API class and accessed via static methods.
164
- # AdWords::API.get_total_units() returns a running total of units used in
165
- # the scope of the current program.
166
- # AdWords::API.get_last_units() returns the number used in the last call.
167
-
164
+ # total_units() returns a running total of units used in the scope of the
165
+ # current program. last_units() returns the number used in the last call.
168
166
  puts
169
167
  puts '%d API units consumed total (%d in last call).' %
170
- [AdWords::API.get_total_units(), AdWords::API.get_last_units()]
168
+ [adwords.total_units, adwords.last_units]
171
169
  end
172
170
  end
173
171
 
@@ -178,7 +176,6 @@ if __FILE__ == $0
178
176
  # To enable this, set the ADWORDS4R_DEBUG environement varaible to 'true'.
179
177
  # This can be done either from your operating system environment or via
180
178
  # code, as done below.
181
-
182
179
  ENV['ADWORDS4R_DEBUG'] = 'false'
183
180
 
184
181
  main()