google-adwords-api 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/ChangeLog +4 -0
  2. data/README +2 -1
  3. data/examples/v201109/account_management/create_account.rb +2 -2
  4. data/examples/v201109/account_management/get_account_alerts.rb +3 -3
  5. data/examples/v201109/account_management/get_account_changes.rb +2 -2
  6. data/examples/v201109/account_management/get_account_hierarchy.rb +2 -2
  7. data/examples/v201109/account_management/get_client_customer_id.rb +6 -8
  8. data/examples/v201109/account_management/get_client_unit_usage.rb +6 -7
  9. data/examples/v201109/basic_operations/add_ad_groups.rb +111 -0
  10. data/examples/v201109/basic_operations/add_campaigns.rb +125 -0
  11. data/examples/v201109/basic_operations/add_keywords.rb +16 -11
  12. data/examples/v201109/basic_operations/add_text_ads.rb +23 -19
  13. data/examples/v201109/basic_operations/delete_ad.rb +7 -7
  14. data/examples/v201109/basic_operations/delete_ad_group.rb +7 -7
  15. data/examples/v201109/basic_operations/delete_campaign.rb +7 -7
  16. data/examples/v201109/basic_operations/delete_keyword.rb +7 -7
  17. data/examples/v201109/basic_operations/get_ad_groups.rb +7 -7
  18. data/examples/v201109/basic_operations/get_campaigns.rb +3 -3
  19. data/examples/v201109/basic_operations/get_keywords.rb +7 -7
  20. data/examples/v201109/basic_operations/get_text_ads.rb +7 -7
  21. data/examples/v201109/basic_operations/pause_ad.rb +7 -7
  22. data/examples/v201109/basic_operations/update_ad_group.rb +6 -6
  23. data/examples/v201109/basic_operations/update_campaign.rb +6 -6
  24. data/examples/v201109/basic_operations/update_keyword.rb +7 -7
  25. data/examples/v201109/campaign_management/add_experiment.rb +14 -9
  26. data/examples/v201109/campaign_management/add_keywords_in_bulk.rb +5 -5
  27. data/examples/v201109/campaign_management/add_location_extension.rb +13 -7
  28. data/examples/v201109/campaign_management/add_location_extension_override.rb +7 -7
  29. data/examples/v201109/campaign_management/get_all_disapproved_ads.rb +6 -6
  30. data/examples/v201109/campaign_management/promote_experiment.rb +5 -6
  31. data/examples/v201109/campaign_management/set_ad_parameters.rb +8 -8
  32. data/examples/v201109/campaign_management/validate_text_ad.rb +7 -9
  33. data/examples/v201109/error_handling/handle_captcha_challenge.rb +3 -4
  34. data/examples/v201109/error_handling/handle_partial_failures.rb +5 -6
  35. data/examples/v201109/error_handling/handle_policy_violation_error.rb +5 -6
  36. data/examples/v201109/error_handling/handle_two_factor_authorization_error.rb +2 -2
  37. data/examples/v201109/misc/get_all_images_and_videos.rb +3 -3
  38. data/examples/v201109/misc/upload_image.rb +2 -2
  39. data/examples/v201109/misc/use_oauth.rb +3 -3
  40. data/examples/v201109/optimization/estimate_keyword_traffic.rb +2 -2
  41. data/examples/v201109/optimization/get_keyword_bid_simulations.rb +6 -7
  42. data/examples/v201109/optimization/get_keyword_ideas.rb +6 -7
  43. data/examples/v201109/optimization/get_placement_ideas.rb +6 -7
  44. data/examples/v201109/remarketing/add_audience.rb +5 -3
  45. data/examples/v201109/remarketing/add_conversion_tracker.rb +12 -3
  46. data/examples/v201109/reporting/download_criteria_report.rb +7 -8
  47. data/examples/v201109/reporting/download_defined_report.rb +6 -7
  48. data/examples/v201109/reporting/get_campaign_stats.rb +105 -0
  49. data/examples/v201109/reporting/get_defined_reports.rb +2 -2
  50. data/examples/v201109/reporting/get_report_fields.rb +6 -7
  51. data/examples/v201109/reporting/parallel_report_download.rb +8 -8
  52. data/examples/v201109/targeting/add_campaign_targeting_criteria.rb +5 -6
  53. data/examples/v201109/targeting/get_campaign_targeting_criteria.rb +7 -8
  54. data/examples/v201109/targeting/get_targetable_languages_and_carriers.rb +2 -2
  55. data/examples/v201109/targeting/lookup_location.rb +2 -2
  56. data/lib/adwords_api/version.rb +1 -1
  57. data/test/examples/v201109/test_account_management.rb +60 -0
  58. data/test/examples/v201109/test_basic_operations.rb +172 -0
  59. data/test/examples/v201109/test_campaign_management.rb +116 -0
  60. data/test/examples/v201109/test_error_handling.rb +63 -0
  61. data/test/examples/v201109/test_misc.rb +45 -0
  62. data/test/examples/v201109/test_optimization.rb +63 -0
  63. data/test/examples/v201109/test_remarketing.rb +39 -0
  64. data/test/examples/v201109/test_reporting.rb +89 -0
  65. data/test/examples/v201109/test_targeting.rb +60 -0
  66. data/test/examples/v201109/utils.rb +239 -0
  67. data/test/suite_exampletests.rb +31 -0
  68. metadata +18 -6
  69. data/examples/v201109/basic_operations/add_ad_group.rb +0 -89
  70. data/examples/v201109/basic_operations/add_campaign.rb +0 -99
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def add_text_ads()
28
+ def add_text_ads(ad_group_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,25 +36,27 @@ def add_text_ads()
38
36
 
39
37
  ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
40
38
 
41
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
42
-
43
39
  # Create text ads.
44
40
  # The 'xsi_type' field allows you to specify the xsi:type of the object
45
41
  # being created. It's only necessary when you must provide an explicit
46
42
  # type that the client library can't infer.
47
43
  text_ads = [
48
- {:xsi_type => 'TextAd',
49
- :headline => 'Luxury Cruise to Mars',
50
- :description1 => 'Visit the Red Planet in style.',
51
- :description2 => 'Low-gravity fun for everyone!',
52
- :url => 'http://www.example.com',
53
- :display_url => 'www.example.com'},
54
- {:xsi_type => 'TextAd',
55
- :headline => 'Luxury Cruise to Mars',
56
- :description1 => 'Enjoy your stay at Red Planet.',
57
- :description2 => 'Buy your tickets now!',
58
- :url => 'http://www.example.com',
59
- :display_url => 'www.example.com'}
44
+ {
45
+ :xsi_type => 'TextAd',
46
+ :headline => 'Luxury Cruise to Mars',
47
+ :description1 => 'Visit the Red Planet in style.',
48
+ :description2 => 'Low-gravity fun for everyone!',
49
+ :url => 'http://www.example.com',
50
+ :display_url => 'www.example.com'
51
+ },
52
+ {
53
+ :xsi_type => 'TextAd',
54
+ :headline => 'Luxury Cruise to Mars',
55
+ :description1 => 'Enjoy your stay at Red Planet.',
56
+ :description2 => 'Buy your tickets now!',
57
+ :url => 'http://www.example.com',
58
+ :display_url => 'www.example.com'
59
+ }
60
60
  ]
61
61
 
62
62
  # Create ad 'ADD' operations.
@@ -75,13 +75,17 @@ def add_text_ads()
75
75
  [ad[:ad][:id], ad[:ad][:ad_type], ad[:status]]
76
76
  end
77
77
  else
78
- puts 'No ads were added.'
78
+ raise StandardError, 'No ads were added.'
79
79
  end
80
80
  end
81
81
 
82
82
  if __FILE__ == $0
83
+ API_VERSION = :v201109
84
+
83
85
  begin
84
- add_text_ads()
86
+ # Ad group ID to add text ads to.
87
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
88
+ add_text_ads(ad_group_id)
85
89
 
86
90
  # HTTP errors.
87
91
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def delete_ad()
28
+ def delete_ad(ad_group_id, ad_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,9 +36,6 @@ def delete_ad()
38
36
 
39
37
  ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
40
38
 
41
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
42
- ad_id = 'INSERT_AD_ID_HERE'.to_i
43
-
44
39
  # Prepare for deleting ad.
45
40
  operation = {
46
41
  :operator => 'REMOVE',
@@ -64,8 +59,13 @@ def delete_ad()
64
59
  end
65
60
 
66
61
  if __FILE__ == $0
62
+ API_VERSION = :v201109
63
+
67
64
  begin
68
- delete_ad()
65
+ # IDs of an ad to delete and its ad group.
66
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
67
+ ad_id = 'INSERT_AD_ID_HERE'.to_i
68
+ delete_ad(ad_group_id, ad_id)
69
69
 
70
70
  # HTTP errors.
71
71
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def delete_ad_group()
28
+ def delete_ad_group(ad_group_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,9 +36,7 @@ def delete_ad_group()
38
36
 
39
37
  ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
40
38
 
41
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
42
-
43
- # Retrieve the ad group to obtain it's name. This is optional but recommended
39
+ # Retrieve the ad group to obtain its name. This is optional but recommended
44
40
  # to keep deleted objects searchable. In production the name is already known
45
41
  # in most cases.
46
42
  selector = {
@@ -81,8 +77,12 @@ def delete_ad_group()
81
77
  end
82
78
 
83
79
  if __FILE__ == $0
80
+ API_VERSION = :v201109
81
+
84
82
  begin
85
- delete_ad_group()
83
+ # ID of an ad group to delete.
84
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
85
+ delete_ad_group(ad_group_id)
86
86
 
87
87
  # HTTP errors.
88
88
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def delete_campaign()
28
+ def delete_campaign(campaign_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,9 +36,7 @@ def delete_campaign()
38
36
 
39
37
  campaign_srv = adwords.service(:CampaignService, API_VERSION)
40
38
 
41
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
42
-
43
- # Retrieve the campaign to obtain it's name. This is optional but recommended
39
+ # Retrieve the campaign to obtain its name. This is optional but recommended
44
40
  # to keep deleted objects searchable. In production the name is already known
45
41
  # in most cases.
46
42
  selector = {
@@ -82,8 +78,12 @@ def delete_campaign()
82
78
  end
83
79
 
84
80
  if __FILE__ == $0
81
+ API_VERSION = :v201109
82
+
85
83
  begin
86
- delete_campaign()
84
+ # ID of a campaign to delete.
85
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
86
+ delete_campaign(campaign_id)
87
87
 
88
88
  # HTTP errors.
89
89
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def delete_keyword()
28
+ def delete_keyword(ad_group_id, criterion_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -39,9 +37,6 @@ def delete_keyword()
39
37
  ad_group_criterion_srv =
40
38
  adwords.service(:AdGroupCriterionService, API_VERSION)
41
39
 
42
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
43
- criterion_id = 'INSERT_CRITERION_ID_HERE'.to_i
44
-
45
40
  # Prepare for deleting keyword.
46
41
  operation = {
47
42
  :operator => 'REMOVE',
@@ -69,8 +64,13 @@ def delete_keyword()
69
64
  end
70
65
 
71
66
  if __FILE__ == $0
67
+ API_VERSION = :v201109
68
+
72
69
  begin
73
- delete_keyword()
70
+ # IDs of criterion to delete and its ad group.
71
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
72
+ criterion_id = 'INSERT_CRITERION_ID_HERE'.to_i
73
+ delete_keyword(ad_group_id, criterion_id)
74
74
 
75
75
  # HTTP errors.
76
76
  rescue AdsCommon::Errors::HttpError => e
@@ -25,10 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
- PAGE_SIZE = 500
30
-
31
- def get_ad_groups()
28
+ def get_ad_groups(campaign_id)
32
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
33
30
  # when called without parameters.
34
31
  adwords = AdwordsApi::Api.new
@@ -39,8 +36,6 @@ def get_ad_groups()
39
36
 
40
37
  ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
41
38
 
42
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
43
-
44
39
  # Get all the ad groups for this campaign.
45
40
  selector = {
46
41
  :fields => ['Id', 'Name'],
@@ -77,8 +72,13 @@ def get_ad_groups()
77
72
  end
78
73
 
79
74
  if __FILE__ == $0
75
+ API_VERSION = :v201109
76
+ PAGE_SIZE = 500
77
+
80
78
  begin
81
- get_ad_groups()
79
+ # Campaign ID to get ad groups for.
80
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
81
+ get_ad_groups(campaign_id)
82
82
 
83
83
  # HTTP errors.
84
84
  rescue AdsCommon::Errors::HttpError => e
@@ -24,9 +24,6 @@
24
24
 
25
25
  require 'adwords_api'
26
26
 
27
- API_VERSION = :v201109
28
- PAGE_SIZE = 500
29
-
30
27
  def get_campaigns()
31
28
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
29
  # when called without parameters.
@@ -72,6 +69,9 @@ def get_campaigns()
72
69
  end
73
70
 
74
71
  if __FILE__ == $0
72
+ API_VERSION = :v201109
73
+ PAGE_SIZE = 500
74
+
75
75
  begin
76
76
  get_campaigns()
77
77
 
@@ -25,10 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
- PAGE_SIZE = 500
30
-
31
- def get_keywords()
28
+ def get_keywords(ad_group_id)
32
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
33
30
  # when called without parameters.
34
31
  adwords = AdwordsApi::Api.new
@@ -40,8 +37,6 @@ def get_keywords()
40
37
  ad_group_criterion_srv =
41
38
  adwords.service(:AdGroupCriterionService, API_VERSION)
42
39
 
43
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
44
-
45
40
  # Get all keywords for this ad group.
46
41
  selector = {
47
42
  :fields => ['Id', 'CriteriaType', 'KeywordText'],
@@ -83,8 +78,13 @@ def get_keywords()
83
78
  end
84
79
 
85
80
  if __FILE__ == $0
81
+ API_VERSION = :v201109
82
+ PAGE_SIZE = 500
83
+
86
84
  begin
87
- get_keywords()
85
+ # Ad group ID to get keywords for.
86
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
87
+ get_keywords(ad_group_id)
88
88
 
89
89
  # HTTP errors.
90
90
  rescue AdsCommon::Errors::HttpError => e
@@ -25,10 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
- PAGE_SIZE = 500
30
-
31
- def get_text_ads()
28
+ def get_text_ads(ad_group_id)
32
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
33
30
  # when called without parameters.
34
31
  adwords = AdwordsApi::Api.new
@@ -39,8 +36,6 @@ def get_text_ads()
39
36
 
40
37
  ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
41
38
 
42
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
43
-
44
39
  # Get all the ads for this ad group.
45
40
  selector = {
46
41
  :fields => ['Id', 'Status', 'AdType'],
@@ -85,8 +80,13 @@ def get_text_ads()
85
80
  end
86
81
 
87
82
  if __FILE__ == $0
83
+ API_VERSION = :v201109
84
+ PAGE_SIZE = 500
85
+
88
86
  begin
89
- get_text_ads()
87
+ # Ad group ID to get text ads for.
88
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
89
+ get_text_ads(ad_group_id)
90
90
 
91
91
  # HTTP errors.
92
92
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def pause_ad()
28
+ def pause_ad(ad_group_id, ad_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,9 +36,6 @@ def pause_ad()
38
36
 
39
37
  ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
40
38
 
41
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
42
- ad_id = 'INSERT_AD_ID_HERE'.to_i
43
-
44
39
  # Prepare operation for updating ad.
45
40
  operation = {
46
41
  :operator => 'SET',
@@ -63,8 +58,13 @@ def pause_ad()
63
58
  end
64
59
 
65
60
  if __FILE__ == $0
61
+ API_VERSION = :v201109
62
+
66
63
  begin
67
- pause_ad()
64
+ # IDs of ad to pause and its ad group.
65
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
66
+ ad_id = 'INSERT_AD_ID_HERE'.to_i
67
+ pause_ad(ad_group_id, ad_id)
68
68
 
69
69
  # HTTP errors.
70
70
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def update_ad_group()
28
+ def update_ad_group(ad_group_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,8 +36,6 @@ def update_ad_group()
38
36
 
39
37
  ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
40
38
 
41
- ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
42
-
43
39
  # Prepare for updating ad group.
44
40
  operation = {
45
41
  :operator => 'SET',
@@ -60,8 +56,12 @@ def update_ad_group()
60
56
  end
61
57
 
62
58
  if __FILE__ == $0
59
+ API_VERSION = :v201109
60
+
63
61
  begin
64
- update_ad_group()
62
+ # ID of an ad group to update.
63
+ ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
64
+ update_ad_group(ad_group_id)
65
65
 
66
66
  # HTTP errors.
67
67
  rescue AdsCommon::Errors::HttpError => e
@@ -25,9 +25,7 @@
25
25
 
26
26
  require 'adwords_api'
27
27
 
28
- API_VERSION = :v201109
29
-
30
- def update_campaign()
28
+ def update_campaign(campaign_id)
31
29
  # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
32
30
  # when called without parameters.
33
31
  adwords = AdwordsApi::Api.new
@@ -38,8 +36,6 @@ def update_campaign()
38
36
 
39
37
  campaign_srv = adwords.service(:CampaignService, API_VERSION)
40
38
 
41
- campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
42
-
43
39
  # Prepare for updating campaign.
44
40
  operation = {
45
41
  :operator => 'SET',
@@ -63,8 +59,12 @@ def update_campaign()
63
59
  end
64
60
 
65
61
  if __FILE__ == $0
62
+ API_VERSION = :v201109
63
+
66
64
  begin
67
- update_campaign()
65
+ # ID of a campaign to update.
66
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
67
+ update_campaign(campaign_id)
68
68
 
69
69
  # HTTP errors.
70
70
  rescue AdsCommon::Errors::HttpError => e