google-adwords-api 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4 -0
- data/README +2 -1
- data/examples/v201109/account_management/create_account.rb +2 -2
- data/examples/v201109/account_management/get_account_alerts.rb +3 -3
- data/examples/v201109/account_management/get_account_changes.rb +2 -2
- data/examples/v201109/account_management/get_account_hierarchy.rb +2 -2
- data/examples/v201109/account_management/get_client_customer_id.rb +6 -8
- data/examples/v201109/account_management/get_client_unit_usage.rb +6 -7
- data/examples/v201109/basic_operations/add_ad_groups.rb +111 -0
- data/examples/v201109/basic_operations/add_campaigns.rb +125 -0
- data/examples/v201109/basic_operations/add_keywords.rb +16 -11
- data/examples/v201109/basic_operations/add_text_ads.rb +23 -19
- data/examples/v201109/basic_operations/delete_ad.rb +7 -7
- data/examples/v201109/basic_operations/delete_ad_group.rb +7 -7
- data/examples/v201109/basic_operations/delete_campaign.rb +7 -7
- data/examples/v201109/basic_operations/delete_keyword.rb +7 -7
- data/examples/v201109/basic_operations/get_ad_groups.rb +7 -7
- data/examples/v201109/basic_operations/get_campaigns.rb +3 -3
- data/examples/v201109/basic_operations/get_keywords.rb +7 -7
- data/examples/v201109/basic_operations/get_text_ads.rb +7 -7
- data/examples/v201109/basic_operations/pause_ad.rb +7 -7
- data/examples/v201109/basic_operations/update_ad_group.rb +6 -6
- data/examples/v201109/basic_operations/update_campaign.rb +6 -6
- data/examples/v201109/basic_operations/update_keyword.rb +7 -7
- data/examples/v201109/campaign_management/add_experiment.rb +14 -9
- data/examples/v201109/campaign_management/add_keywords_in_bulk.rb +5 -5
- data/examples/v201109/campaign_management/add_location_extension.rb +13 -7
- data/examples/v201109/campaign_management/add_location_extension_override.rb +7 -7
- data/examples/v201109/campaign_management/get_all_disapproved_ads.rb +6 -6
- data/examples/v201109/campaign_management/promote_experiment.rb +5 -6
- data/examples/v201109/campaign_management/set_ad_parameters.rb +8 -8
- data/examples/v201109/campaign_management/validate_text_ad.rb +7 -9
- data/examples/v201109/error_handling/handle_captcha_challenge.rb +3 -4
- data/examples/v201109/error_handling/handle_partial_failures.rb +5 -6
- data/examples/v201109/error_handling/handle_policy_violation_error.rb +5 -6
- data/examples/v201109/error_handling/handle_two_factor_authorization_error.rb +2 -2
- data/examples/v201109/misc/get_all_images_and_videos.rb +3 -3
- data/examples/v201109/misc/upload_image.rb +2 -2
- data/examples/v201109/misc/use_oauth.rb +3 -3
- data/examples/v201109/optimization/estimate_keyword_traffic.rb +2 -2
- data/examples/v201109/optimization/get_keyword_bid_simulations.rb +6 -7
- data/examples/v201109/optimization/get_keyword_ideas.rb +6 -7
- data/examples/v201109/optimization/get_placement_ideas.rb +6 -7
- data/examples/v201109/remarketing/add_audience.rb +5 -3
- data/examples/v201109/remarketing/add_conversion_tracker.rb +12 -3
- data/examples/v201109/reporting/download_criteria_report.rb +7 -8
- data/examples/v201109/reporting/download_defined_report.rb +6 -7
- data/examples/v201109/reporting/get_campaign_stats.rb +105 -0
- data/examples/v201109/reporting/get_defined_reports.rb +2 -2
- data/examples/v201109/reporting/get_report_fields.rb +6 -7
- data/examples/v201109/reporting/parallel_report_download.rb +8 -8
- data/examples/v201109/targeting/add_campaign_targeting_criteria.rb +5 -6
- data/examples/v201109/targeting/get_campaign_targeting_criteria.rb +7 -8
- data/examples/v201109/targeting/get_targetable_languages_and_carriers.rb +2 -2
- data/examples/v201109/targeting/lookup_location.rb +2 -2
- data/lib/adwords_api/version.rb +1 -1
- data/test/examples/v201109/test_account_management.rb +60 -0
- data/test/examples/v201109/test_basic_operations.rb +172 -0
- data/test/examples/v201109/test_campaign_management.rb +116 -0
- data/test/examples/v201109/test_error_handling.rb +63 -0
- data/test/examples/v201109/test_misc.rb +45 -0
- data/test/examples/v201109/test_optimization.rb +63 -0
- data/test/examples/v201109/test_remarketing.rb +39 -0
- data/test/examples/v201109/test_reporting.rb +89 -0
- data/test/examples/v201109/test_targeting.rb +60 -0
- data/test/examples/v201109/utils.rb +239 -0
- data/test/suite_exampletests.rb +31 -0
- metadata +18 -6
- data/examples/v201109/basic_operations/add_ad_group.rb +0 -89
- data/examples/v201109/basic_operations/add_campaign.rb +0 -99
@@ -0,0 +1,63 @@
|
|
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
|
+
# Tests the error handling examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
|
25
|
+
require 'error_handling/handle_captcha_challenge'
|
26
|
+
require 'error_handling/handle_partial_failures'
|
27
|
+
require 'error_handling/handle_policy_violation_error'
|
28
|
+
require 'error_handling/handle_two_factor_authorization_error'
|
29
|
+
|
30
|
+
MAX_RETRIES = 50
|
31
|
+
|
32
|
+
class TestErrorHandlingV201109 < Test::Unit::TestCase
|
33
|
+
def setup
|
34
|
+
@logger = Logger.new(STDOUT)
|
35
|
+
@logger.level = Logger::ERROR
|
36
|
+
@adwords = AdwordsApi::Api.new
|
37
|
+
@adwords.logger = @logger
|
38
|
+
@utils = UtilsV201109.new(@adwords)
|
39
|
+
end
|
40
|
+
|
41
|
+
# This test is disabled as it requires user input.
|
42
|
+
def disabled_test_handle_captcha_challenge
|
43
|
+
handle_captcha_challenge()
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_handle_partial_failures
|
47
|
+
ad_group = @utils.get_ad_group()
|
48
|
+
assert_not_nil(ad_group)
|
49
|
+
assert_not_nil(ad_group[:id])
|
50
|
+
handle_partial_failures(ad_group[:id])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_handle_policy_violation_error
|
54
|
+
ad_group = @utils.get_ad_group()
|
55
|
+
assert_not_nil(ad_group)
|
56
|
+
assert_not_nil(ad_group[:id])
|
57
|
+
handle_policy_violation_error(ad_group[:id])
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_handle_two_factor_authorization_error
|
61
|
+
handle_two_factor_authorization_error()
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
# Tests the misc examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
|
25
|
+
require 'misc/get_all_images_and_videos'
|
26
|
+
require 'misc/upload_image'
|
27
|
+
require 'misc/use_oauth'
|
28
|
+
|
29
|
+
class TestMiscV201109 < Test::Unit::TestCase
|
30
|
+
def setup
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_all_images_and_videos
|
34
|
+
get_all_images_and_videos()
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_upload_image
|
38
|
+
upload_image()
|
39
|
+
end
|
40
|
+
|
41
|
+
# This test is disabled as it requires user input.
|
42
|
+
def disabled_test_use_oauth
|
43
|
+
use_oauth()
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,63 @@
|
|
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
|
+
# Tests the optimization examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
|
25
|
+
require 'optimization/estimate_keyword_traffic'
|
26
|
+
require 'optimization/get_keyword_bid_simulations'
|
27
|
+
require 'optimization/get_keyword_ideas'
|
28
|
+
require 'optimization/get_placement_ideas'
|
29
|
+
|
30
|
+
class TestOptimizationV201109 < Test::Unit::TestCase
|
31
|
+
def setup
|
32
|
+
@logger = Logger.new(STDOUT)
|
33
|
+
@logger.level = Logger::ERROR
|
34
|
+
@adwords = AdwordsApi::Api.new
|
35
|
+
@adwords.logger = @logger
|
36
|
+
@utils = UtilsV201109.new(@adwords)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_estimate_keyword_traffic
|
40
|
+
estimate_keyword_traffic()
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_get_keyword_bid_simulations
|
44
|
+
ad_group = @utils.get_ad_group()
|
45
|
+
assert_not_nil(ad_group)
|
46
|
+
assert_not_nil(ad_group[:id])
|
47
|
+
keyword = @utils.get_keyword()
|
48
|
+
assert_not_nil(keyword)
|
49
|
+
assert_not_nil(keyword[:criterion])
|
50
|
+
assert_not_nil(keyword[:criterion][:id])
|
51
|
+
get_criterion_bid_landscapes(ad_group[:id], keyword[:criterion][:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_get_keyword_ideas
|
55
|
+
keyword_text = 'orion tours'
|
56
|
+
get_keyword_ideas(keyword_text)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_get_placement_ideas
|
60
|
+
url = 'http://example.google.com'
|
61
|
+
get_placement_ideas(url)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
# Tests the remarketing examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
|
25
|
+
require 'remarketing/add_audience'
|
26
|
+
require 'remarketing/add_conversion_tracker'
|
27
|
+
|
28
|
+
class TestRemarketingV201109 < Test::Unit::TestCase
|
29
|
+
def setup
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_add_audience
|
33
|
+
add_audience()
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_add_conversion_tracker
|
37
|
+
add_conversion_tracker()
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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
|
+
# Tests the reporting examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
require 'tempfile'
|
25
|
+
|
26
|
+
require 'reporting/download_criteria_report'
|
27
|
+
require 'reporting/download_defined_report'
|
28
|
+
require 'reporting/get_campaign_stats'
|
29
|
+
require 'reporting/get_defined_reports'
|
30
|
+
require 'reporting/get_report_fields'
|
31
|
+
require 'reporting/parallel_report_download'
|
32
|
+
|
33
|
+
THREADS = 3
|
34
|
+
MAX_RETRIES = 3
|
35
|
+
BACKOFF_FACTOR = 3
|
36
|
+
|
37
|
+
class TestReportingV201109 < Test::Unit::TestCase
|
38
|
+
def setup
|
39
|
+
@logger = Logger.new(STDOUT)
|
40
|
+
@logger.level = Logger::ERROR
|
41
|
+
@adwords = AdwordsApi::Api.new
|
42
|
+
@adwords.logger = @logger
|
43
|
+
@utils = UtilsV201109.new(@adwords)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_download_criteria_report
|
47
|
+
file = Tempfile.new('ruby-examples')
|
48
|
+
begin
|
49
|
+
file.close()
|
50
|
+
download_criteria_report(file.path)
|
51
|
+
ensure
|
52
|
+
file.unlink()
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_download_defined_report
|
57
|
+
report_definition_id = '1234567890'
|
58
|
+
file = Tempfile.new('ruby-examples')
|
59
|
+
begin
|
60
|
+
file.close()
|
61
|
+
download_defined_report(report_definition_id, file.path)
|
62
|
+
ensure
|
63
|
+
file.unlink()
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_get_campaign_stats
|
68
|
+
get_campaign_stats()
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_get_defined_reports
|
72
|
+
get_defined_reports()
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_get_report_fields
|
76
|
+
report_type = 'ACCOUNT_PERFORMANCE_REPORT'
|
77
|
+
get_report_fields(report_type)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_parallel_report_download
|
81
|
+
old_dir = Dir.pwd
|
82
|
+
Dir.chdir('/tmp')
|
83
|
+
begin
|
84
|
+
parallel_report_download()
|
85
|
+
ensure
|
86
|
+
Dir.chdir(old_dir)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
# Tests the targeting examples.
|
22
|
+
|
23
|
+
require 'test/unit'
|
24
|
+
|
25
|
+
require 'targeting/add_campaign_targeting_criteria'
|
26
|
+
require 'targeting/get_campaign_targeting_criteria'
|
27
|
+
require 'targeting/get_targetable_languages_and_carriers'
|
28
|
+
require 'targeting/lookup_location'
|
29
|
+
|
30
|
+
class TestTargetingV201109 < Test::Unit::TestCase
|
31
|
+
def setup
|
32
|
+
@logger = Logger.new(STDOUT)
|
33
|
+
@logger.level = Logger::ERROR
|
34
|
+
@adwords = AdwordsApi::Api.new
|
35
|
+
@adwords.logger = @logger
|
36
|
+
@utils = UtilsV201109.new(@adwords)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_add_campaign_targeting_criteria
|
40
|
+
campaign = @utils.get_campaign()
|
41
|
+
assert_not_nil(campaign)
|
42
|
+
assert_not_nil(campaign[:id])
|
43
|
+
add_campaign_targeting_criteria(campaign[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_get_campaign_targeting_criteria
|
47
|
+
campaign = @utils.get_campaign()
|
48
|
+
assert_not_nil(campaign)
|
49
|
+
assert_not_nil(campaign[:id])
|
50
|
+
get_campaign_targeting_criteria(campaign[:id])
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_get_targetable_languages_and_carriers
|
54
|
+
get_targetable_languages_and_carriers()
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_lookup_location
|
58
|
+
lookup_location()
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
# Encoding: utf-8
|
2
|
+
#
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
|
+
#
|
5
|
+
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
# Utilities and constants for example tests.
|
21
|
+
|
22
|
+
API_VERSION = :v201109
|
23
|
+
PAGE_SIZE = 500
|
24
|
+
|
25
|
+
class UtilsV201109
|
26
|
+
def initialize(adwords)
|
27
|
+
@adwords = adwords
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_campaign
|
31
|
+
@campaign ||= create_campaign()
|
32
|
+
return @campaign
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_ad_group
|
36
|
+
@ad_group ||= create_ad_group()
|
37
|
+
return @ad_group
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_ad
|
41
|
+
@ad ||= create_ad(get_ad_group()[:id])
|
42
|
+
return @ad
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_keyword
|
46
|
+
@keyword ||= create_keyword(get_ad_group()[:id])
|
47
|
+
return @keyword
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_location_extension
|
51
|
+
@location_extension ||= create_location_extension(get_campaign()[:id])
|
52
|
+
return @location_extension
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_experiment
|
56
|
+
@experiment ||= create_experiment(
|
57
|
+
get_campaign()[:id], get_ad_group()[:id], get_keyword[:criterion][:id])
|
58
|
+
return @experiment
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def create_campaign
|
64
|
+
campaign_srv = @adwords.service(:CampaignService, API_VERSION)
|
65
|
+
campaign = {
|
66
|
+
:name => "Example tests campaign #%d" % (Time.new.to_f * 1000).to_i,
|
67
|
+
:status => 'PAUSED',
|
68
|
+
:bidding_strategy => {:xsi_type => 'ManualCPC'},
|
69
|
+
:budget => {
|
70
|
+
:period => 'DAILY',
|
71
|
+
:amount => {:micro_amount => 50000000},
|
72
|
+
:delivery_method => 'STANDARD'
|
73
|
+
},
|
74
|
+
:network_setting => {
|
75
|
+
:target_google_search => true,
|
76
|
+
:target_search_network => true,
|
77
|
+
:target_content_network => false,
|
78
|
+
:target_content_contextual => false
|
79
|
+
}
|
80
|
+
}
|
81
|
+
operation = {:operator => 'ADD', :operand => campaign}
|
82
|
+
response = campaign_srv.mutate([operation])
|
83
|
+
return response[:value].first
|
84
|
+
end
|
85
|
+
|
86
|
+
def create_ad_group
|
87
|
+
campaign = get_campaign()
|
88
|
+
ad_group_srv = @adwords.service(:AdGroupService, API_VERSION)
|
89
|
+
ad_group = {
|
90
|
+
:name => "Example tests ad group #%d" % (Time.new.to_f * 1000).to_i,
|
91
|
+
:status => 'ENABLED',
|
92
|
+
:campaign_id => campaign[:id],
|
93
|
+
:bids => {
|
94
|
+
:xsi_type => 'ManualCPCAdGroupBids',
|
95
|
+
:keyword_max_cpc => {:amount => {:micro_amount => 10000000}},
|
96
|
+
}
|
97
|
+
}
|
98
|
+
operation = {:operator => 'ADD', :operand => ad_group}
|
99
|
+
response = ad_group_srv.mutate([operation])
|
100
|
+
return response[:value].first
|
101
|
+
end
|
102
|
+
|
103
|
+
def create_ad(ad_group_id)
|
104
|
+
ad_group_ad_srv = @adwords.service(:AdGroupAdService, API_VERSION)
|
105
|
+
text_ad = {
|
106
|
+
:xsi_type => 'TextAd',
|
107
|
+
:headline => 'Examples test ad %d' % (Time.new.to_f * 1000).to_i,
|
108
|
+
:description1 => 'testing ruby examples',
|
109
|
+
:description2 => 'all your base are belong to us',
|
110
|
+
:url => 'http://www.example.com',
|
111
|
+
:display_url => 'www.example.com'
|
112
|
+
}
|
113
|
+
operation = {:operator => 'ADD',
|
114
|
+
:operand => {:ad_group_id => ad_group_id, :ad => text_ad}}
|
115
|
+
response = ad_group_ad_srv.mutate([operation])
|
116
|
+
return response[:value].first
|
117
|
+
end
|
118
|
+
|
119
|
+
def create_keyword(ad_group_id)
|
120
|
+
ad_group_criterion_srv =
|
121
|
+
@adwords.service(:AdGroupCriterionService, API_VERSION)
|
122
|
+
keyword = {
|
123
|
+
:xsi_type => 'BiddableAdGroupCriterion',
|
124
|
+
:ad_group_id => ad_group_id,
|
125
|
+
:criterion => {
|
126
|
+
:xsi_type => 'Keyword',
|
127
|
+
:text => 'mars cruise',
|
128
|
+
:match_type => 'BROAD'
|
129
|
+
}
|
130
|
+
}
|
131
|
+
operation = {:operator => 'ADD', :operand => keyword}
|
132
|
+
response = ad_group_criterion_srv.mutate([operation])
|
133
|
+
return response[:value].first
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_location_extension(campaign_id)
|
137
|
+
campaign_ad_ext_srv =
|
138
|
+
@adwords.service(:CampaignAdExtensionService, API_VERSION)
|
139
|
+
geo_location_srv = @adwords.service(:GeoLocationService, API_VERSION)
|
140
|
+
|
141
|
+
selector = {
|
142
|
+
:addresses => [
|
143
|
+
{
|
144
|
+
:street_address => '1600 Amphitheatre Parkway',
|
145
|
+
:city_name => 'Mountain View',
|
146
|
+
:province_code => 'CA',
|
147
|
+
:postal_code => '94043',
|
148
|
+
:country_code => 'US'
|
149
|
+
}
|
150
|
+
]
|
151
|
+
}
|
152
|
+
|
153
|
+
locations = geo_location_srv.get(selector)
|
154
|
+
raise StandardError, 'Unable to retrieve geo locations.' if locations.nil?
|
155
|
+
|
156
|
+
operations = locations.map do |location|
|
157
|
+
{
|
158
|
+
:operator => 'ADD',
|
159
|
+
:operand => {
|
160
|
+
:campaign_id => campaign_id,
|
161
|
+
:status => 'ACTIVE',
|
162
|
+
:ad_extension => {
|
163
|
+
:xsi_type => 'LocationExtension',
|
164
|
+
:address => location[:address],
|
165
|
+
:geo_point => location[:geo_point],
|
166
|
+
:encoded_location => location[:encoded_location],
|
167
|
+
:source => 'ADWORDS_FRONTEND'
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
response = campaign_ad_ext_srv.mutate(operations)
|
174
|
+
extension = response[:value].first
|
175
|
+
return extension
|
176
|
+
end
|
177
|
+
|
178
|
+
def create_experiment(campaign_id, ad_group_id, criterion_id)
|
179
|
+
experiment_srv = @adwords.service(:ExperimentService, API_VERSION)
|
180
|
+
ad_group_srv = @adwords.service(:AdGroupService, API_VERSION)
|
181
|
+
ad_group_criterion_srv =
|
182
|
+
@adwords.service(:AdGroupCriterionService, API_VERSION)
|
183
|
+
|
184
|
+
operation = {
|
185
|
+
:operator => 'ADD',
|
186
|
+
:operand => {
|
187
|
+
:campaign_id => campaign_id,
|
188
|
+
:name => "Examples test experiment #%d" % (Time.new.to_f * 1000).to_i,
|
189
|
+
:query_percentage => 10,
|
190
|
+
:start_date_time => Time.now.strftime('%Y%m%d %H%M%S'),
|
191
|
+
}
|
192
|
+
}
|
193
|
+
response = experiment_srv.mutate([operation])
|
194
|
+
experiment = response[:value].first
|
195
|
+
|
196
|
+
raise StandardError, 'Failed to create experiment' if experiment.nil?
|
197
|
+
|
198
|
+
ad_group = {
|
199
|
+
:id => ad_group_id,
|
200
|
+
:experiment_data => {
|
201
|
+
:experiment_id => experiment[:id],
|
202
|
+
:experiment_delta_status => 'MODIFIED',
|
203
|
+
:experiment_bid_multipliers => {
|
204
|
+
:xsi_type => 'ManualCPCAdGroupExperimentBidMultipliers',
|
205
|
+
:max_cpc_multiplier => {:multiplier => 1.5}
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
|
210
|
+
operation = {:operator => 'SET', :operand => ad_group}
|
211
|
+
response = ad_group_srv.mutate([operation])
|
212
|
+
ad_group = response[:value].first
|
213
|
+
|
214
|
+
raise StandardError, 'Failed to assign experiment' if ad_group.nil?
|
215
|
+
|
216
|
+
ad_group_criterion = {
|
217
|
+
:xsi_type => 'BiddableAdGroupCriterion',
|
218
|
+
:ad_group_id => ad_group_id,
|
219
|
+
:criterion => {:id => criterion_id},
|
220
|
+
:experiment_data => {
|
221
|
+
:xsi_type => 'BiddableAdGroupCriterionExperimentData',
|
222
|
+
:experiment_id => experiment[:id],
|
223
|
+
:experiment_delta_status => 'MODIFIED',
|
224
|
+
:experiment_bid_multiplier => {
|
225
|
+
:xsi_type => 'ManualCPCAdGroupCriterionExperimentBidMultiplier',
|
226
|
+
:max_cpc_multiplier => {:multiplier => 1.5}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
operation = {:operator => 'SET', :operand => ad_group_criterion}
|
232
|
+
response = ad_group_criterion_srv.mutate([operation])
|
233
|
+
criterion = response[:value].first
|
234
|
+
|
235
|
+
raise StandardError, 'Failed to assign criterion' if criterion.nil?
|
236
|
+
|
237
|
+
return experiment
|
238
|
+
end
|
239
|
+
end
|