google-ads-common 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.6.1:
2
+ - Support for GZip compression.
3
+ - Added logging of the response HTTP headers.
4
+ - Updated minimal requirement for httpclient (~>2.2.3) and httpi (~>0.9.3).
5
+
1
6
  0.6.0:
2
7
  - Better namespace handling in complex cases.
3
8
  - Large refactoring on parameter processing code.
data/README CHANGED
@@ -18,8 +18,9 @@ Install it using the gem install command.
18
18
 
19
19
  The following gem libraries are required:
20
20
  - savon v0.9.7;
21
- - httpi v0.9.2 or greater;
22
- - httpclient v2.1.6 or greater.
21
+ - httpi v0.9.3 or greater;
22
+ - httpclient v2.2.3 or greater.
23
+ - psych-1.2.2 or greater (for ruby-1.9.2 and later only).
23
24
 
24
25
  = Docs for Developers
25
26
 
data/Rakefile CHANGED
@@ -48,8 +48,8 @@ spec = Gem::Specification.new do |s|
48
48
  s.has_rdoc = true
49
49
  s.extra_rdoc_files = docs
50
50
  s.add_dependency('savon', '= 0.9.7')
51
- s.add_dependency('httpclient', '>= 2.1.6')
52
- s.add_dependency('httpi', '~> 0.9.2')
51
+ s.add_dependency('httpclient', '~> 2.2.3')
52
+ s.add_dependency('httpi', '~> 0.9.3')
53
53
  s.add_dependency('oauth', '~> 0.4.5')
54
54
  end
55
55
 
@@ -26,7 +26,7 @@ module AdsCommon
26
26
  # Contains helper methods for loading and managing the available services.
27
27
  # This module is meant to be imported into API-specific modules.
28
28
  module ApiConfig
29
- ADS_COMMON_VERSION = '0.6.0'
29
+ ADS_COMMON_VERSION = '0.6.1'
30
30
 
31
31
  # Get the available API versions.
32
32
  #
@@ -117,8 +117,11 @@ module AdsCommon
117
117
  # - Authentication string
118
118
  #
119
119
  def generate_oauth_parameters_string(credentials, request)
120
- oauth_params = {:consumer => @consumer,
121
- :token => get_token(credentials)}
120
+ oauth_params = {
121
+ # get_token() ensures @consumer is initialized.
122
+ :token => get_token(credentials),
123
+ :consumer => @consumer
124
+ }
122
125
  oauth_helper = OAuth::Client::Helper.new(request, oauth_params)
123
126
  return oauth_helper.header
124
127
  end
@@ -21,6 +21,7 @@
21
21
  # rewrite it in memory.
22
22
 
23
23
  require 'rubygems'
24
+ require 'psych' if RUBY_VERSION >= "1.9.2"
24
25
  require 'yaml'
25
26
 
26
27
  module AdsCommon
@@ -58,6 +58,13 @@ module AdsCommon
58
58
  @auth_handler.property_changed(credential, value) if @auth_handler
59
59
  end
60
60
 
61
+ # Returns current configuration.
62
+ # TODO: we need better way to access config widely,
63
+ # remove after refactoring.
64
+ def get_config()
65
+ return @config
66
+ end
67
+
61
68
  private
62
69
 
63
70
  # Loads the credentials from the config data.
@@ -103,7 +103,7 @@ module AdsCommon
103
103
  # An array passed when an object is expected.
104
104
  if (field[:max_occurs] == 1) and arg.kind_of?(Array)
105
105
  raise AdsCommon::Errors::TypeMismatchError.new(
106
- field[:type], Array)
106
+ field[:type], Array, field[:name])
107
107
  end
108
108
  end
109
109
 
@@ -43,6 +43,7 @@ module AdsCommon
43
43
  @element_name = element_name
44
44
  @namespace = namespace
45
45
  @version = version
46
+ @config = credential_handler.get_config
46
47
  Savon.configure {|config| config.raise_errors = false}
47
48
  end
48
49
 
@@ -88,9 +89,11 @@ module AdsCommon
88
89
  app_name = credentials[:userAgent] || credentials[:useragent]
89
90
  # We don't know the library version here. A breaking change needs to be
90
91
  # introduced. This is scheduled for 0.7.0, using Common version for now.
91
- lib_version = '0.6.0'
92
+ lib_version = '0.6.1'
92
93
  soap_user_agent = "Common-Ruby-%s; %s" % [lib_version, app_name]
93
- return "Savon/%s (%s)" % [Savon::Version, soap_user_agent]
94
+ user_agent = "Savon/%s (%s)" % [Savon::Version, soap_user_agent]
95
+ user_agent += ' (gzip)' if @config.read('connection.enable_gzip', false)
96
+ return user_agent
94
97
  end
95
98
  end
96
99
  end
@@ -69,11 +69,13 @@ module AdsCommon
69
69
  # Creates and sets up Savon client.
70
70
  def create_savon_client(endpoint, namespace)
71
71
  proxy = @api.config.read('connection.proxy')
72
+ enable_gzip = @api.config.read('connection.enable_gzip', false)
72
73
  client = Savon::Client.new do |wsdl, http|
73
74
  wsdl.endpoint = endpoint
74
75
  wsdl.namespace = namespace
75
- http.proxy = proxy if !proxy.nil?
76
76
  http.read_timeout = HTTP_READ_TIMEOUT
77
+ http.proxy = proxy if proxy
78
+ http.gzip if enable_gzip
77
79
  end
78
80
  return client
79
81
  end
@@ -84,10 +86,16 @@ module AdsCommon
84
86
  args = validator.validate_args(action_name, args)
85
87
  response = execute_soap_request(
86
88
  action_name.to_sym, args, validator.extra_namespaces)
89
+ log_headers(response.http.headers)
87
90
  handle_errors(response)
88
91
  return extract_result(response, action_name, &block)
89
92
  end
90
93
 
94
+ # Logs response headers.
95
+ def log_headers(headers)
96
+ @api.logger.debug(headers.map {|k, v| [k, v].join(': ')}.join(', '))
97
+ end
98
+
91
99
  # Executes the SOAP request with original SOAP name.
92
100
  def execute_soap_request(action, args, extra_namespaces)
93
101
  original_action_name =
@@ -22,11 +22,13 @@
22
22
  require 'rubygems'
23
23
  require 'test/unit'
24
24
 
25
+ require 'ads_common/errors'
25
26
  require 'ads_common/parameters_validator'
26
27
 
27
28
  module AdsCommon
28
29
  class ParametersValidator
29
30
  public :deep_copy, :add_attribute, :array_from_named_list
31
+ public :check_required_argument_present
30
32
  end
31
33
  end
32
34
 
@@ -100,4 +102,31 @@ class TestParametersValidator < Test::Unit::TestCase
100
102
  result = @validator.array_from_named_list(src)
101
103
  assert_equal(['foo', 'bar', 'ipsum'], result)
102
104
  end
105
+
106
+ def test_check_required_argument_present
107
+ field1 = {:min_occurs => 1, :max_occurs => 1,
108
+ :name => 'field1', :type => 'type1'}
109
+ assert_raises(AdsCommon::Errors::MissingPropertyError) do
110
+ @validator.check_required_argument_present(nil, field1)
111
+ end
112
+ assert_raises(AdsCommon::Errors::TypeMismatchError) do
113
+ @validator.check_required_argument_present([], field1)
114
+ end
115
+ assert_nothing_raised do
116
+ @validator.check_required_argument_present({}, field1)
117
+ @validator.check_required_argument_present('foobar', field1)
118
+ @validator.check_required_argument_present(42, field1)
119
+ end
120
+
121
+ field2 = {:min_occurs => 0, :max_occurs => :unbounded,
122
+ :name => 'field2', :type => 'type2'}
123
+ assert_raises(AdsCommon::Errors::TypeMismatchError) do
124
+ @validator.check_required_argument_present({}, field2)
125
+ end
126
+ assert_nothing_raised do
127
+ @validator.check_required_argument_present(nil, field2)
128
+ @validator.check_required_argument_present([], field2)
129
+ @validator.check_required_argument_present([field1, field2], field2)
130
+ end
131
+ end
103
132
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-ads-common
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 5
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 6
8
- - 0
9
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Sergio Gomes
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-12-02 00:00:00 +04:00
19
+ date: 2011-12-23 00:00:00 +04:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -26,6 +27,7 @@ dependencies:
26
27
  requirements:
27
28
  - - "="
28
29
  - !ruby/object:Gem::Version
30
+ hash: 53
29
31
  segments:
30
32
  - 0
31
33
  - 9
@@ -39,13 +41,14 @@ dependencies:
39
41
  requirement: &id002 !ruby/object:Gem::Requirement
40
42
  none: false
41
43
  requirements:
42
- - - ">="
44
+ - - ~>
43
45
  - !ruby/object:Gem::Version
46
+ hash: 1
44
47
  segments:
45
48
  - 2
46
- - 1
47
- - 6
48
- version: 2.1.6
49
+ - 2
50
+ - 3
51
+ version: 2.2.3
49
52
  type: :runtime
50
53
  version_requirements: *id002
51
54
  - !ruby/object:Gem::Dependency
@@ -56,11 +59,12 @@ dependencies:
56
59
  requirements:
57
60
  - - ~>
58
61
  - !ruby/object:Gem::Version
62
+ hash: 61
59
63
  segments:
60
64
  - 0
61
65
  - 9
62
- - 2
63
- version: 0.9.2
66
+ - 3
67
+ version: 0.9.3
64
68
  type: :runtime
65
69
  version_requirements: *id003
66
70
  - !ruby/object:Gem::Dependency
@@ -71,6 +75,7 @@ dependencies:
71
75
  requirements:
72
76
  - - ~>
73
77
  - !ruby/object:Gem::Version
78
+ hash: 5
74
79
  segments:
75
80
  - 0
76
81
  - 4
@@ -130,6 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
135
  requirements:
131
136
  - - ">="
132
137
  - !ruby/object:Gem::Version
138
+ hash: 3
133
139
  segments:
134
140
  - 0
135
141
  version: "0"
@@ -138,6 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
144
  requirements:
139
145
  - - ">="
140
146
  - !ruby/object:Gem::Version
147
+ hash: 3
141
148
  segments:
142
149
  - 0
143
150
  version: "0"