google-adwords-api 0.7.1 → 0.7.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 CHANGED
@@ -1,3 +1,6 @@
1
+ 0.7.2:
2
+ - Fixed issue #87 specific to ruby1.8.
3
+
1
4
  0.7.1:
2
5
  - Support and examples for v201209.
3
6
 
@@ -33,6 +33,24 @@ def use_oauth2()
33
33
  # the configuration file or provide your own logger:
34
34
  # adwords.logger = Logger.new('adwords_xml.log')
35
35
 
36
+ # You can call authorize explicitely to obtain the access token. Otherwise, it
37
+ # will be invoked automatically on the first API call.
38
+ # There are two ways to provide verification code, first one is via the block:
39
+ token = adwords.authorize() do |auth_url|
40
+ puts "Hit Auth error, please navigate to URL:\n\t%s" % auth_url
41
+ print 'log in and type the verification code: '
42
+ verification_code = gets.chomp
43
+ verification_code
44
+ end
45
+ # Alternatively, you can provide one within the parameters:
46
+ #token = adwords.authorize({:oauth2_verification_code => verification_code})
47
+
48
+ # Note, 'token' is a Hash. Its value is not used in this example. If you need
49
+ # to be able to access the API in offline mode, with no user present, you
50
+ # should persist it to be used in subsequent invocations like this:
51
+ #adwords.authorize({:oauth2_token => token})
52
+
53
+ # No exception thrown - we are good to make the request.
36
54
  campaign_srv = adwords.service(:CampaignService, API_VERSION)
37
55
 
38
56
  # Get all the campaigns for this account; empty selector.
@@ -43,24 +61,7 @@ def use_oauth2()
43
61
  ]
44
62
  }
45
63
 
46
- retry_count = 0
47
-
48
- begin
49
- response = campaign_srv.get(selector)
50
- rescue AdsCommon::Errors::OAuth2VerificationRequired => e
51
- if retry_count < MAX_RETRIES
52
- puts "Hit Auth error, please navigate to URL:\n\t%s" % e.oauth_url
53
- print 'log in and type the verification code: '
54
- verification_code = gets.chomp
55
- adwords.credential_handler.set_credential(
56
- :oauth2_verification_code, verification_code)
57
- retry_count += 1
58
- retry
59
- else
60
- raise AdsCommon::Errors::AuthError, 'Failed to authenticate.'
61
- end
62
- end
63
-
64
+ response = campaign_srv.get(selector)
64
65
  if response and response[:entries]
65
66
  campaigns = response[:entries]
66
67
  campaigns.each do |campaign|
@@ -74,7 +75,6 @@ end
74
75
 
75
76
  if __FILE__ == $0
76
77
  API_VERSION = :v201209
77
- MAX_RETRIES = 3
78
78
 
79
79
  begin
80
80
  use_oauth2()
@@ -196,7 +196,7 @@ module AdwordsApi
196
196
  def check_for_errors(response)
197
197
  # Check for error in body.
198
198
  report_body = response.body
199
- if report_body and (@version <= :v201206) and
199
+ if report_body and is_legacy_reporting(@version) and
200
200
  ((RUBY_VERSION < '1.9.1') or report_body.valid_encoding?)
201
201
  check_for_legacy_error(report_body, response.code)
202
202
  end
@@ -210,6 +210,13 @@ module AdwordsApi
210
210
  return nil
211
211
  end
212
212
 
213
+ # Returns true is the provided API version has legacy reporting.
214
+ def is_legacy_reporting(version)
215
+ return (version == :v201206 or
216
+ version == :v201109_1 or
217
+ version == :v201109)
218
+ end
219
+
213
220
  # Checks for a legacy error in the response body and raises an exception if
214
221
  # it was found.
215
222
  def check_for_legacy_error(report_body, response_code)
@@ -21,6 +21,6 @@
21
21
 
22
22
  module AdwordsApi
23
23
  module ApiConfig
24
- CLIENT_LIB_VERSION = '0.7.1'
24
+ CLIENT_LIB_VERSION = '0.7.2'
25
25
  end
26
26
  end
@@ -27,6 +27,11 @@ class UtilsV201209
27
27
  @adwords = adwords
28
28
  end
29
29
 
30
+ def get_budget
31
+ @budget ||= create_budget()
32
+ return @budget
33
+ end
34
+
30
35
  def get_campaign
31
36
  @campaign ||= create_campaign()
32
37
  return @campaign
@@ -60,29 +65,47 @@ class UtilsV201209
60
65
 
61
66
  private
62
67
 
63
- def create_campaign
68
+ def create_campaign()
69
+ budget = get_budget()
70
+ budget_id = budget[:budget_id]
71
+
64
72
  campaign_srv = @adwords.service(:CampaignService, API_VERSION)
65
73
  campaign = {
66
74
  :name => "Example tests campaign #%d" % (Time.new.to_f * 1000).to_i,
67
75
  :status => 'PAUSED',
68
76
  :bidding_strategy => {:xsi_type => 'ManualCPC'},
69
- :budget => {
70
- :period => 'DAILY',
71
- :amount => {:micro_amount => 50000000},
72
- :delivery_method => 'STANDARD'
73
- },
77
+ :budget => {:budget_id => budget_id},
74
78
  :network_setting => {
75
79
  :target_google_search => true,
76
80
  :target_search_network => true,
77
81
  :target_content_network => true
78
- }
82
+ },
83
+ :settings => [
84
+ {
85
+ :xsi_type => 'KeywordMatchSetting',
86
+ :opt_in => true
87
+ }
88
+ ]
79
89
  }
80
90
  operation = {:operator => 'ADD', :operand => campaign}
81
91
  response = campaign_srv.mutate([operation])
82
92
  return response[:value].first
83
93
  end
84
94
 
85
- def create_ad_group
95
+ def create_budget()
96
+ budget_srv = @adwords.service(:BudgetService, API_VERSION)
97
+ budget = {
98
+ :name => 'Example tests budget #%d' % (Time.new.to_f * 1000).to_i,
99
+ :amount => {:micro_amount => 50000000},
100
+ :delivery_method => 'STANDARD',
101
+ :period => 'DAILY'
102
+ }
103
+ operation = {:operator => 'ADD', :operand => budget}
104
+ response = budget_srv.mutate([operation])
105
+ return response[:value].first
106
+ end
107
+
108
+ def create_ad_group()
86
109
  campaign = get_campaign()
87
110
  ad_group_srv = @adwords.service(:AdGroupService, API_VERSION)
88
111
  ad_group = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-adwords-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-05 00:00:00.000000000 Z
12
+ date: 2012-10-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: google-ads-common