google-ads-common 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,6 @@
1
+ 0.7.1:
2
+ - Fixed issues #63, #73, #74.
3
+
1
4
  0.7.0:
2
5
  - Cleaned up unused features.
3
6
  - Now require HTTPI 0.9.7 (fixes issue #61).
@@ -150,7 +150,7 @@ module AdsCommon
150
150
  unless api_config.version_has_service(version, service)
151
151
  raise AdsCommon::Errors::Error,
152
152
  "Version '%s' does not contain service '%s'" %
153
- [version.to_s, name.to_s]
153
+ [version.to_s, service.to_s]
154
154
  end
155
155
  end
156
156
 
@@ -123,7 +123,7 @@ module AdsCommon
123
123
  #
124
124
  def endpoint(environment, version, service)
125
125
  base = get_wsdl_base(environment, version)
126
- # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.7.0.
126
+ # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.8.0.
127
127
  if !subdir_config().nil?
128
128
  base = base.to_s + subdir_config()[[version, service]].to_s
129
129
  end
@@ -141,7 +141,7 @@ module AdsCommon
141
141
  #
142
142
  def subdir(version, service)
143
143
  return nil if subdir_config().nil?
144
- # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.7.0.
144
+ # TODO(dklimkin): Unflatten subdir constants. Cross-API refactor 0.8.0.
145
145
  subdir_config()[[version, service]]
146
146
  end
147
147
 
@@ -150,6 +150,10 @@ module AdsCommon
150
150
  'sequence | complexContent/extension/sequence') do |seq_node|
151
151
  type[:fields] += get_element_fields(seq_node)
152
152
  end
153
+ REXML::XPath.each(type_element, 'choice') do |seq_node|
154
+ type[:choices] ||= []
155
+ type[:choices] += get_element_fields(seq_node)
156
+ end
153
157
  return type
154
158
  end
155
159
 
@@ -68,27 +68,30 @@ module AdsCommon
68
68
  end
69
69
 
70
70
  # Generates string for UserAgent to put into HTTP headers.
71
- def generate_http_user_agent()
72
- agent_data = []
73
- agent_data << HTTPI::Adapter.use.to_s
74
- ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
75
- agent_data << [ruby_engine, RUBY_VERSION].join('/')
76
- agent_data << (credentials[:user_agent] || $0)
77
- user_agent = "HTTPI/%s (%s)" % [HTTPI::VERSION, agent_data.join(', ')]
78
- return user_agent
71
+ def generate_http_user_agent(extra_ids = [], agent_app = nil)
72
+ return generate_user_agent(extra_ids, agent_app)
79
73
  end
80
74
 
81
75
  # Generates string for UserAgent to put into SOAP headers.
82
- def generate_soap_user_agent(extra_ids = [])
83
- agent_data = extra_ids
84
- agent_data << "Common-Ruby-%s" % AdsCommon::ApiConfig::CLIENT_LIB_VERSION
85
- agent_data << (@credentials[:user_agent] || $0)
86
- user_agent = "Savon/%s (%s)" % [Savon::Version, agent_data.join(', ')]
87
- return user_agent
76
+ def generate_soap_user_agent(extra_ids = [], agent_app = nil)
77
+ return generate_user_agent(extra_ids, agent_app)
88
78
  end
89
79
 
90
80
  private
91
81
 
82
+ # Generates user-agent.
83
+ def generate_user_agent(extra_ids, agent_app)
84
+ agent_app ||= $0
85
+ agent_data = extra_ids
86
+ agent_data << "Common-Ruby/%s" % AdsCommon::ApiConfig::CLIENT_LIB_VERSION
87
+ agent_data << "Savon/%s" % Savon::Version
88
+ ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
89
+ agent_data << [ruby_engine, RUBY_VERSION].join('/')
90
+ agent_data << "HTTPI/%s" % HTTPI::VERSION
91
+ agent_data << HTTPI::Adapter.use.to_s
92
+ return "%s (%s)" % [agent_app, agent_data.join(', ')]
93
+ end
94
+
92
95
  # Loads the credentials from the config data.
93
96
  def load_from_config(config)
94
97
  @credentials = config.read('authentication')
@@ -43,21 +43,17 @@ module AdsCommon
43
43
  return result
44
44
  end
45
45
 
46
- private
47
-
48
46
  # Extracts misc data from response header.
49
47
  def extract_header_data(response)
50
48
  header_type = get_full_type_signature(:SoapResponseHeader)
51
49
  headers = response.header[:response_header].dup
52
50
  process_attributes(headers, false)
53
- result = headers.inject({}) do |result, (key, v)|
54
- normalize_output_field(headers, header_type[:fields], key)
55
- result[key] = headers[key]
56
- result
57
- end
58
- return result
51
+ headers = normalize_fields(headers, header_type[:fields])
52
+ return headers
59
53
  end
60
54
 
55
+ private
56
+
61
57
  # Normalizes output starting with root output node.
62
58
  def normalize_output(output_data, method_definition)
63
59
  fields = method_definition[:output][:fields]
@@ -104,20 +100,72 @@ module AdsCommon
104
100
  # Normalizes every item of a Hash.
105
101
  def normalize_hash_field(field, field_def)
106
102
  process_attributes(field, true)
107
- field_type = determine_type(field, field_def[:type])
108
- type_signature = get_full_type_signature(field_type)
109
- # If we don't know the type, pass as-is.
110
- return (type_signature.nil?) ?
111
- field : normalize_fields(field, type_signature[:fields])
103
+ field_type = field_def[:type]
104
+ field_def = get_full_type_signature(field_type)
105
+
106
+ # First checking for xsi:type provided.
107
+ xsi_type_override = determine_xsi_type_override(field, field_def)
108
+ unless xsi_type_override.nil?
109
+ field_def = get_full_type_signature(xsi_type_override)
110
+ return (field_def.nil?) ? field :
111
+ normalize_fields(field, field_def[:fields])
112
+ end
113
+
114
+ # Now checking for choice options from wsdl.
115
+ choice_type_override = determine_choice_type_override(field, field_def)
116
+ unless choice_type_override.nil?
117
+ # For overrides we need to process sub-field and than return it
118
+ # in the original structure.
119
+ field_key = field.keys.first
120
+ field_data = field[field_key]
121
+ field_def = get_full_type_signature(choice_type_override)
122
+ if !field_def.nil? and field_data.kind_of?(Hash)
123
+ field_data = normalize_fields(field_data, field_def[:fields])
124
+ end
125
+ return {field_key => field_data}
126
+ end
127
+
128
+ # Otherwise using the best we have.
129
+ field = normalize_fields(field, field_def[:fields]) unless field_def.nil?
130
+
131
+ return field
112
132
  end
113
133
 
114
- # Returns field type based on the field structure. Allows to override the
115
- # type with custom xsi:type.
116
- def determine_type(field_data, field_type)
134
+ # Determines an xsi:type override for for the field. Returns nil if no
135
+ # override found.
136
+ def determine_xsi_type_override(field_data, field_def)
137
+ result = nil
117
138
  if field_data.kind_of?(Hash) and field_data.include?(:xsi_type)
118
- field_type = field_data[:xsi_type]
139
+ result = field_data[:xsi_type]
119
140
  end
120
- return field_type
141
+ return result
142
+ end
143
+
144
+ # Determines a choice type override for for the field. Returns nil if no
145
+ # override found.
146
+ def determine_choice_type_override(field_data, field_def)
147
+ result = nil
148
+ if field_data.kind_of?(Hash) and field_def.include?(:choices)
149
+ result = determine_choice(field_data, field_def[:choices])
150
+ end
151
+ return result
152
+ end
153
+
154
+ # Finds the choice option matching data provided.
155
+ def determine_choice(field_data, field_choices)
156
+ result = nil
157
+ key_name = field_data.keys.first
158
+ unless key_name.nil?
159
+ choice = find_named_entry(field_choices, key_name)
160
+ result = choice[:type] unless choice.nil?
161
+ end
162
+ return result
163
+ end
164
+
165
+ # Finds an item in an Array based on its ':name' field.
166
+ def find_named_entry(data_array, name)
167
+ index = data_array.index {|item| name.eql?(item[:name])}
168
+ return index.nil? ? nil : data_array[index]
121
169
  end
122
170
 
123
171
  # Converts one leaf item to a built-in type.
@@ -154,7 +202,7 @@ module AdsCommon
154
202
  result = []
155
203
  if data_type[:base]
156
204
  parent_type = @registry.get_type_signature(data_type[:base])
157
- result += implode_parent(parent_type)
205
+ result += implode_parent(parent_type) unless parent_type.nil?
158
206
  end
159
207
  data_type[:fields].each do |field|
160
208
  # If the parent type includes a field with the same name, overwrite it.
@@ -21,6 +21,6 @@
21
21
 
22
22
  module AdsCommon
23
23
  module ApiConfig
24
- CLIENT_LIB_VERSION = '0.7.0'
24
+ CLIENT_LIB_VERSION = '0.7.1'
25
25
  end
26
26
  end
@@ -33,6 +33,17 @@ module AdsCommon
33
33
  end
34
34
 
35
35
  class StubRegistry
36
+ def get_type_signature(type_name)
37
+ if type_name == :SoapResponseHeader
38
+ return {:fields => []}
39
+ else
40
+ return nil
41
+ end
42
+ end
43
+ end
44
+
45
+ class StubResponse
46
+ attr_accessor :header
36
47
  end
37
48
 
38
49
  class TestResultsExtractor < Test::Unit::TestCase
@@ -162,4 +173,31 @@ class TestResultsExtractor < Test::Unit::TestCase
162
173
  {}, {:min_occurs => '0', :max_occurs => :unbounded})
163
174
  assert_equal([{}], result7)
164
175
  end
176
+
177
+ def test_extract_headers_empty()
178
+ headers = {}
179
+ response = StubResponse.new()
180
+ response.header = {:response_header => headers}
181
+ result = @extractor.extract_header_data(response)
182
+ assert_equal(headers, result)
183
+ assert_not_same(headers, result)
184
+ end
185
+
186
+ def test_extract_headers_passthrough()
187
+ headers = {:a => 'aa', :b => '42'}
188
+ response = StubResponse.new()
189
+ response.header = {:response_header => headers}
190
+ result = @extractor.extract_header_data(response)
191
+ assert_equal(headers, result)
192
+ assert_not_same(headers, result)
193
+ end
194
+
195
+ def test_extract_headers_attrs_removed()
196
+ headers = {:a => 'aa', :@xmlns => '42'}
197
+ expected = {:a => 'aa'}
198
+ response = StubResponse.new()
199
+ response.header = {:response_header => headers}
200
+ result = @extractor.extract_header_data(response)
201
+ assert_equal(expected, result)
202
+ end
165
203
  end
metadata CHANGED
@@ -1,171 +1,149 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: google-ads-common
3
- version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 7
9
- - 0
10
- version: 0.7.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Sergio Gomes
14
9
  - Danial Klimkin
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2012-05-15 00:00:00 +04:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-06-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: savon
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
19
+ requirements:
28
20
  - - ~>
29
- - !ruby/object:Gem::Version
30
- hash: 41
31
- segments:
32
- - 0
33
- - 9
34
- - 9
21
+ - !ruby/object:Gem::Version
35
22
  version: 0.9.9
36
23
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: httpclient
40
24
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: !ruby/object:Gem::Requirement
42
26
  none: false
43
- requirements:
27
+ requirements:
44
28
  - - ~>
45
- - !ruby/object:Gem::Version
46
- hash: 1
47
- segments:
48
- - 2
49
- - 2
50
- - 3
29
+ - !ruby/object:Gem::Version
30
+ version: 0.9.9
31
+ - !ruby/object:Gem::Dependency
32
+ name: httpclient
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
51
38
  version: 2.2.3
52
39
  type: :runtime
53
- version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
55
- name: httpi
56
40
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 2.2.3
47
+ - !ruby/object:Gem::Dependency
48
+ name: httpi
49
+ requirement: !ruby/object:Gem::Requirement
58
50
  none: false
59
- requirements:
51
+ requirements:
60
52
  - - ~>
61
- - !ruby/object:Gem::Version
62
- hash: 53
63
- segments:
64
- - 0
65
- - 9
66
- - 7
53
+ - !ruby/object:Gem::Version
67
54
  version: 0.9.7
68
55
  type: :runtime
69
- version_requirements: *id003
70
- - !ruby/object:Gem::Dependency
71
- name: oauth
72
56
  prerelease: false
73
- requirement: &id004 !ruby/object:Gem::Requirement
57
+ version_requirements: !ruby/object:Gem::Requirement
74
58
  none: false
75
- requirements:
59
+ requirements:
76
60
  - - ~>
77
- - !ruby/object:Gem::Version
78
- hash: 5
79
- segments:
80
- - 0
81
- - 4
82
- - 5
61
+ - !ruby/object:Gem::Version
62
+ version: 0.9.7
63
+ - !ruby/object:Gem::Dependency
64
+ name: oauth
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
83
70
  version: 0.4.5
84
71
  type: :runtime
85
- version_requirements: *id004
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 0.4.5
86
79
  description: Essential utilities shared by all Ads Ruby client libraries
87
- email:
80
+ email:
88
81
  - api.dklimkin@gmail.com
89
82
  executables: []
90
-
91
83
  extensions: []
92
-
93
84
  extra_rdoc_files: []
94
-
95
- files:
96
- - lib/ads_common/auth/base_handler.rb
85
+ files:
86
+ - lib/ads_common/api.rb
87
+ - lib/ads_common/version.rb
88
+ - lib/ads_common/credential_handler.rb
89
+ - lib/ads_common/savon_service.rb
90
+ - lib/ads_common/api_config.rb
97
91
  - lib/ads_common/auth/client_login_handler.rb
98
92
  - lib/ads_common/auth/oauth_handler.rb
93
+ - lib/ads_common/auth/base_handler.rb
94
+ - lib/ads_common/http.rb
95
+ - lib/ads_common/errors.rb
96
+ - lib/ads_common/parameters_validator.rb
97
+ - lib/ads_common/savon_headers/oauth_header_handler.rb
98
+ - lib/ads_common/savon_headers/base_header_handler.rb
99
+ - lib/ads_common/savon_headers/httpi_request_proxy.rb
100
+ - lib/ads_common/results_extractor.rb
99
101
  - lib/ads_common/build/savon_abstract_generator.rb
100
- - lib/ads_common/build/savon_generator.rb
102
+ - lib/ads_common/build/savon_service_generator.rb
101
103
  - lib/ads_common/build/savon_registry.rb
102
104
  - lib/ads_common/build/savon_registry_generator.rb
103
- - lib/ads_common/build/savon_service_generator.rb
104
- - lib/ads_common/savon_headers/base_header_handler.rb
105
- - lib/ads_common/savon_headers/httpi_request_proxy.rb
106
- - lib/ads_common/savon_headers/oauth_header_handler.rb
107
- - lib/ads_common/api_config.rb
108
- - lib/ads_common/api.rb
105
+ - lib/ads_common/build/savon_generator.rb
109
106
  - lib/ads_common/config.rb
110
- - lib/ads_common/credential_handler.rb
111
- - lib/ads_common/errors.rb
112
- - lib/ads_common/http.rb
113
- - lib/ads_common/parameters_validator.rb
114
- - lib/ads_common/savon_service.rb
115
- - lib/ads_common/version.rb
116
- - lib/ads_common/results_extractor.rb
117
- - test/test_client_login_handler.rb
118
- - test/test_config.rb
119
- - test/test_config.yml
120
- - test/test_parameters_validator.rb
121
107
  - test/test_savon_service.rb
122
108
  - test/coverage.rb
109
+ - test/test_results_extractor.rb
123
110
  - test/suite_unittests.rb
124
111
  - test/test_credential_handler.rb
125
- - test/test_results_extractor.rb
112
+ - test/test_client_login_handler.rb
113
+ - test/test_parameters_validator.rb
114
+ - test/test_config.rb
115
+ - test/test_config.yml
126
116
  - COPYING
127
117
  - README
128
118
  - ChangeLog
129
- has_rdoc: true
130
119
  homepage: http://code.google.com/p/google-api-ads-ruby/
131
120
  licenses: []
132
-
133
121
  post_install_message:
134
122
  rdoc_options: []
135
-
136
- require_paths:
123
+ require_paths:
137
124
  - lib
138
- required_ruby_version: !ruby/object:Gem::Requirement
125
+ required_ruby_version: !ruby/object:Gem::Requirement
139
126
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 3
144
- segments:
145
- - 0
146
- version: "0"
147
- required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
132
  none: false
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- hash: 23
153
- segments:
154
- - 1
155
- - 3
156
- - 6
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
157
136
  version: 1.3.6
158
137
  requirements: []
159
-
160
138
  rubyforge_project: google-ads-common
161
- rubygems_version: 1.3.7
139
+ rubygems_version: 1.8.24
162
140
  signing_key:
163
141
  specification_version: 3
164
142
  summary: Common code for Google Ads APIs
165
- test_files:
166
- - test/test_client_login_handler.rb
167
- - test/test_config.rb
168
- - test/test_parameters_validator.rb
143
+ test_files:
169
144
  - test/test_savon_service.rb
170
- - test/test_credential_handler.rb
171
145
  - test/test_results_extractor.rb
146
+ - test/test_credential_handler.rb
147
+ - test/test_client_login_handler.rb
148
+ - test/test_parameters_validator.rb
149
+ - test/test_config.rb