google-adwords-api 0.4.4 → 0.4.5
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 +5 -0
- data/README +13 -2
- data/Rakefile +7 -1
- data/lib/adwords_api.rb +1 -1
- data/lib/adwords_api/api_config.rb +1 -1
- data/lib/adwords_api/extensions.rb +5 -0
- data/lib/adwords_api/report_utils.rb +13 -2
- data/lib/adwords_api/utils.rb +6 -9
- data/test/adwords_api/test_report_utils.rb +11 -0
- data/test/adwords_api/test_utils.rb +61 -0
- metadata +38 -60
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -28,8 +28,7 @@ which is installed automatically as a dependency.
|
|
28
28
|
|
29
29
|
The following gem libraries are required:
|
30
30
|
- savon v0.9.7
|
31
|
-
-
|
32
|
-
- google-ads-common v0.6.0 or later.
|
31
|
+
- google-ads-common v0.6.1 or later.
|
33
32
|
|
34
33
|
|
35
34
|
== 2 - Using the client library:
|
@@ -156,6 +155,18 @@ This information can be obtained by passing a user block during method call:
|
|
156
155
|
You can also retrieve the response body as the second block parameter:
|
157
156
|
report_def_srv.get(selector) {|header, body| ... }
|
158
157
|
|
158
|
+
=== 2.5 - GZip compression
|
159
|
+
|
160
|
+
The library offers a transparent compression option which can be enabled in the
|
161
|
+
configuration file or by the following setting:
|
162
|
+
|
163
|
+
config[:connection] = {
|
164
|
+
:enable_gzip => true
|
165
|
+
}
|
166
|
+
|
167
|
+
Enabling this option will set the headers required to request the server to
|
168
|
+
respond in gzipped format. All requests are sent uncompressed regardless.
|
169
|
+
|
159
170
|
|
160
171
|
= Docs for Developers
|
161
172
|
|
data/Rakefile
CHANGED
@@ -25,6 +25,12 @@ require 'rake/testtask'
|
|
25
25
|
require './lib/adwords_api/api_config'
|
26
26
|
require './lib/adwords_api/extensions'
|
27
27
|
|
28
|
+
# Workaround for the current mess of different yamlers in Ruby world.
|
29
|
+
if RUBY_VERSION>='1.9.2'
|
30
|
+
gem 'psych'
|
31
|
+
YAML::ENGINE.yamler = 'psych'
|
32
|
+
end
|
33
|
+
|
28
34
|
# Google common ads library used for wrapper code generation.
|
29
35
|
gem 'google-ads-common'
|
30
36
|
require 'ads_common/build/savon_generator'
|
@@ -48,7 +54,7 @@ spec = Gem::Specification.new do |s|
|
|
48
54
|
s.test_files = tests
|
49
55
|
s.has_rdoc = true
|
50
56
|
s.extra_rdoc_files = docs
|
51
|
-
s.add_dependency('google-ads-common', '~> 0.6.
|
57
|
+
s.add_dependency('google-ads-common', '~> 0.6.1')
|
52
58
|
s.add_dependency('savon', '= 0.9.7')
|
53
59
|
end
|
54
60
|
|
data/lib/adwords_api.rb
CHANGED
@@ -245,6 +245,11 @@ module AdwordsApi
|
|
245
245
|
elsif credentials[:email]
|
246
246
|
headers['clientEmail'] = credentials[:email]
|
247
247
|
end
|
248
|
+
money_in_micros =
|
249
|
+
wrapper.api.config.read('library.return_money_in_micros')
|
250
|
+
unless money_in_micros.nil?
|
251
|
+
headers['returnMoneyInMicros'] = money_in_micros
|
252
|
+
end
|
248
253
|
return headers
|
249
254
|
end
|
250
255
|
|
@@ -124,12 +124,22 @@ module AdwordsApi
|
|
124
124
|
auth_string = auth_handler.auth_string(
|
125
125
|
credentials, HTTPI::Request.new(url))
|
126
126
|
customer_id = validate_cid(cid || credentials[:clientCustomerId])
|
127
|
+
app_name = credentials[:userAgent] || credentials[:useragent]
|
127
128
|
headers = {
|
128
129
|
'Authorization' => auth_string,
|
129
130
|
'ClientCustomerId' => customer_id,
|
130
131
|
'Content-Type' => 'multipart/form-data',
|
131
|
-
'developerToken' => credentials[:developerToken]
|
132
|
+
'developerToken' => credentials[:developerToken],
|
133
|
+
'User-Agent' => "HTTPI/%s (%s)" % [HTTPI::VERSION, app_name]
|
132
134
|
}
|
135
|
+
if @api.config.read('connection.enable_gzip', false)
|
136
|
+
headers['User-Agent'] += ' (gzip)'
|
137
|
+
headers['Accept-Encoding'] = 'gzip,deflate'
|
138
|
+
end
|
139
|
+
money_in_micros = @api.config.read('library.return_money_in_micros')
|
140
|
+
unless money_in_micros.nil?
|
141
|
+
headers['returnMoneyInMicros'] = money_in_micros
|
142
|
+
end
|
133
143
|
return headers
|
134
144
|
end
|
135
145
|
|
@@ -157,7 +167,8 @@ module AdwordsApi
|
|
157
167
|
def check_for_errors(response)
|
158
168
|
# Check for error in body.
|
159
169
|
report_body = response.body
|
160
|
-
if report_body
|
170
|
+
if report_body and
|
171
|
+
((RUBY_VERSION < '1.9.1') or report_body.valid_encoding?)
|
161
172
|
error_message_regex = '^!!!(-?\d+)\|\|\|(-?\d+)\|\|\|(.*)\?\?\?'
|
162
173
|
data = report_body.slice(0, 1024)
|
163
174
|
matches = data.match(error_message_regex)
|
data/lib/adwords_api/utils.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
2
|
#
|
3
|
-
# Author:: api.
|
3
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
4
4
|
#
|
5
|
-
# Copyright:: Copyright
|
5
|
+
# Copyright:: Copyright 2012, Google Inc. All Rights Reserved.
|
6
6
|
#
|
7
7
|
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
8
|
# you may not use this file except in compliance with the License.
|
@@ -46,12 +46,9 @@ module AdwordsApi
|
|
46
46
|
# - index for the source operation, nil if none
|
47
47
|
#
|
48
48
|
def self.operation_index_for_error(error)
|
49
|
-
if error and error[:field_path]
|
50
|
-
|
51
|
-
|
52
|
-
match = parts.first.match(/operations\[(\d)\]/)
|
53
|
-
return match ? match[1].to_i : nil
|
54
|
-
end
|
49
|
+
if error and error[:field_path] and error[:field_path].kind_of?(String)
|
50
|
+
match = error[:field_path].match(/operations\[(\d+)\]/)
|
51
|
+
return match ? match[1].to_i : nil
|
55
52
|
end
|
56
53
|
return nil
|
57
54
|
end
|
@@ -51,6 +51,7 @@ REPLY_TYPES = [
|
|
51
51
|
]
|
52
52
|
|
53
53
|
VALID_REPORT = '"Custom ADGROUP_PERFORMANCE_REPORT (Oct 20, 2011-Oct 26, 2011)"\nCampaign ID,Ad group ID,Impressions,Clicks,Cost\nTotal, --,0,0,0.00'
|
54
|
+
GZIPPED_REPORT = "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x00Sr.-.\xC9\xCFUptq\x0F\xF2\x0F\r\x88\x0Fp\rr\xF3\x0F\xF2u\xF4sv\x8D\x0Fr\r\xF0\x0F\nQ\xD0pIMV0\xD2Q0204\xD4\x05\xB1- lM%.\xE7\xC4\xDC\x82\xC4\xCC\xF4<\x05O\x17\x1D\xC7\x14\x85\xF4\xA2\xFC\xD2\x02\x10\xDB3\xB7\xA0(\xB5\xB883?\xAFX\xC79'39\eH\xE5\x17\x97p\x85\xE4\x97$\xE6\xE8(\xE8\xEA\xEA\x18\x80\xA0\x9E\x81\x01\x17\x00\xBE\x1D\xBE\xAD\x81\x00\x00\x00"
|
54
55
|
|
55
56
|
class TestReportUtils < Test::Unit::TestCase
|
56
57
|
# Initialize tests.
|
@@ -107,4 +108,14 @@ class TestReportUtils < Test::Unit::TestCase
|
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|
111
|
+
|
112
|
+
# Testing correct gzipped reply.
|
113
|
+
def test_gzipped_data
|
114
|
+
report = (RUBY_VERSION >= '1.9.1') ?
|
115
|
+
GZIPPED_REPORT.force_encoding('UTF-8') : GZIPPED_REPORT
|
116
|
+
response = ResponseStub.new(200, report)
|
117
|
+
assert_nothing_raised do
|
118
|
+
@report_utils.check_for_errors(response)
|
119
|
+
end
|
120
|
+
end
|
110
121
|
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
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
|
+
# Tests the AdWords API utils.
|
21
|
+
|
22
|
+
require 'rubygems'
|
23
|
+
require 'test/unit'
|
24
|
+
require 'adwords_api/utils'
|
25
|
+
|
26
|
+
class TestUtils < Test::Unit::TestCase
|
27
|
+
def test_map
|
28
|
+
param1 = [
|
29
|
+
{:key => 'foo', :value => 'bar'},
|
30
|
+
{:key => 'baz', :value => 'zar'},
|
31
|
+
]
|
32
|
+
result1 = {'foo' => 'bar', 'baz' => 'zar'}
|
33
|
+
assert_equal(result1, AdwordsApi::Utils::map(param1))
|
34
|
+
|
35
|
+
param2 = []
|
36
|
+
result2 = {}
|
37
|
+
assert_equal(result2, AdwordsApi::Utils::map(param2))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_operation_index_for_error
|
41
|
+
error1 = {:field_path => 'operations[0].operand.adGroupId'}
|
42
|
+
assert_equal(0, AdwordsApi::Utils::operation_index_for_error(error1))
|
43
|
+
|
44
|
+
error2 = {:field_path => 'operations[10].operand.adGroupId'}
|
45
|
+
assert_equal(10, AdwordsApi::Utils::operation_index_for_error(error2))
|
46
|
+
|
47
|
+
error3 = {:field_path => 'unknown'}
|
48
|
+
assert_equal(nil, AdwordsApi::Utils::operation_index_for_error(error3))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_format_id
|
52
|
+
assert_equal('123-456-7890', AdwordsApi::Utils::format_id(1234567890))
|
53
|
+
assert_equal('234-567-8901', AdwordsApi::Utils::format_id('2345678901'))
|
54
|
+
assert_equal('345-678-9012', AdwordsApi::Utils::format_id('345-678-9012'))
|
55
|
+
assert_equal('456-789-0123',
|
56
|
+
AdwordsApi::Utils::format_id('CID: 456-789-0123'))
|
57
|
+
assert_equal('012-345-6789', AdwordsApi::Utils::format_id('0123-4567-89'))
|
58
|
+
assert_equal('123', AdwordsApi::Utils::format_id('123'))
|
59
|
+
assert_equal('234', AdwordsApi::Utils::format_id(234))
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-adwords-api
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 4
|
8
|
-
- 4
|
9
|
-
version: 0.4.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Danial Klimkin
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: google-ads-common
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &82715310 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
18
|
+
requirements:
|
26
19
|
- - ~>
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
- 6
|
31
|
-
- 0
|
32
|
-
version: 0.6.0
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.1
|
33
22
|
type: :runtime
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: savon
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: *82715310
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: savon
|
27
|
+
requirement: &82714480 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
- 9
|
46
|
-
- 7
|
29
|
+
requirements:
|
30
|
+
- - =
|
31
|
+
- !ruby/object:Gem::Version
|
47
32
|
version: 0.9.7
|
48
33
|
type: :runtime
|
49
|
-
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *82714480
|
50
36
|
description: google-adwords-api is a AdWords API client library for Ruby
|
51
37
|
email: api.dklimkin@gmail.com
|
52
38
|
executables: []
|
53
|
-
|
54
39
|
extensions: []
|
55
|
-
|
56
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
57
41
|
- README
|
58
42
|
- COPYING
|
59
43
|
- ChangeLog
|
60
|
-
files:
|
44
|
+
files:
|
61
45
|
- lib/adwords_api/v13/account_service_registry.rb
|
62
46
|
- lib/adwords_api/v13/report_service_registry.rb
|
63
47
|
- lib/adwords_api/v13/account_service.rb
|
@@ -573,42 +557,36 @@ files:
|
|
573
557
|
- test/bugs/test_issue_00000031.rb
|
574
558
|
- test/adwords_api/test_api_config.rb
|
575
559
|
- test/adwords_api/test_report_utils.rb
|
560
|
+
- test/adwords_api/test_utils.rb
|
576
561
|
- README
|
577
562
|
- COPYING
|
578
563
|
- ChangeLog
|
579
|
-
has_rdoc: true
|
580
564
|
homepage: http://code.google.com/p/google-api-ads-ruby/
|
581
565
|
licenses: []
|
582
|
-
|
583
566
|
post_install_message:
|
584
567
|
rdoc_options: []
|
585
|
-
|
586
|
-
require_paths:
|
568
|
+
require_paths:
|
587
569
|
- lib
|
588
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
570
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
589
571
|
none: false
|
590
|
-
requirements:
|
591
|
-
- -
|
592
|
-
- !ruby/object:Gem::Version
|
593
|
-
|
594
|
-
|
595
|
-
version: "0"
|
596
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
572
|
+
requirements:
|
573
|
+
- - ! '>='
|
574
|
+
- !ruby/object:Gem::Version
|
575
|
+
version: '0'
|
576
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
597
577
|
none: false
|
598
|
-
requirements:
|
599
|
-
- -
|
600
|
-
- !ruby/object:Gem::Version
|
601
|
-
|
602
|
-
- 0
|
603
|
-
version: "0"
|
578
|
+
requirements:
|
579
|
+
- - ! '>='
|
580
|
+
- !ruby/object:Gem::Version
|
581
|
+
version: '0'
|
604
582
|
requirements: []
|
605
|
-
|
606
583
|
rubyforge_project:
|
607
|
-
rubygems_version: 1.
|
584
|
+
rubygems_version: 1.8.11
|
608
585
|
signing_key:
|
609
586
|
specification_version: 3
|
610
587
|
summary: Ruby Client libraries for AdWords API
|
611
|
-
test_files:
|
588
|
+
test_files:
|
612
589
|
- test/bugs/test_issue_00000031.rb
|
613
590
|
- test/adwords_api/test_api_config.rb
|
614
591
|
- test/adwords_api/test_report_utils.rb
|
592
|
+
- test/adwords_api/test_utils.rb
|