nne_client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/.gitignore +19 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +92 -0
  5. data/Rakefile +2 -0
  6. data/lib/nne_client/fetch.rb +22 -0
  7. data/lib/nne_client/query.rb +35 -0
  8. data/lib/nne_client/question.rb +36 -0
  9. data/lib/nne_client/record_types/finance.rb +43 -0
  10. data/lib/nne_client/record_types/ownership.rb +25 -0
  11. data/lib/nne_client/record_types/subsidiary.rb +25 -0
  12. data/lib/nne_client/record_types/trade.rb +21 -0
  13. data/lib/nne_client/request.rb +56 -0
  14. data/lib/nne_client/result.rb +171 -0
  15. data/lib/nne_client/result_attributes.rb +37 -0
  16. data/lib/nne_client/result_set.rb +43 -0
  17. data/lib/nne_client/search.rb +15 -0
  18. data/lib/nne_client/version.rb +3 -0
  19. data/lib/nne_client.rb +43 -0
  20. data/nne_client.gemspec +24 -0
  21. data/spec/finance_spec.rb +79 -0
  22. data/spec/ownership_spec.rb +34 -0
  23. data/spec/result_spec.rb +284 -0
  24. data/spec/search_spec.rb +78 -0
  25. data/spec/spec_helper.rb +29 -0
  26. data/spec/subsidiary_spec.rb +36 -0
  27. data/spec/trade_spec.rb +21 -0
  28. data/spec/vcr_cassettes/result_additional_names_single.yml +706 -0
  29. data/spec/vcr_cassettes/result_extended_info.yml +705 -0
  30. data/spec/vcr_cassettes/result_extended_info_with_access_key.yml +705 -0
  31. data/spec/vcr_cassettes/result_fetching_basic_attributes.yml +705 -0
  32. data/spec/vcr_cassettes/result_fetching_ext_attributes_email_hash.yml +1407 -0
  33. data/spec/vcr_cassettes/result_fetching_missing_company.yml +706 -0
  34. data/spec/vcr_cassettes/result_multiple_finances.yml +1408 -0
  35. data/spec/vcr_cassettes/result_multiple_ownerships.yml +1409 -0
  36. data/spec/vcr_cassettes/result_multiple_trades.yml +1407 -0
  37. data/spec/vcr_cassettes/result_names.yml +705 -0
  38. data/spec/vcr_cassettes/result_names_empty.yml +706 -0
  39. data/spec/vcr_cassettes/result_no_finance.yml +1408 -0
  40. data/spec/vcr_cassettes/result_no_ownerships.yml +706 -0
  41. data/spec/vcr_cassettes/result_no_subsidiaries.yml +1409 -0
  42. data/spec/vcr_cassettes/result_single_finance.yml +1409 -0
  43. data/spec/vcr_cassettes/result_single_ownership.yml +1408 -0
  44. data/spec/vcr_cassettes/result_single_subsidiary.yml +1408 -0
  45. data/spec/vcr_cassettes/result_trades.yml +705 -0
  46. data/spec/vcr_cassettes/search_for_noise.yml +706 -0
  47. data/spec/vcr_cassettes/search_lokale.yml +705 -0
  48. data/spec/vcr_cassettes/search_lokale_100.yml +705 -0
  49. data/spec/vcr_cassettes/search_lokalebasen.yml +706 -0
  50. data/spec/vcr_cassettes/search_lokalebasen_with_access_key.yml +706 -0
  51. metadata +234 -0
data/lib/nne_client.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'config_newton'
2
+ require 'savon'
3
+ require "nne_client/version"
4
+ require "nne_client/result_attributes"
5
+ require "nne_client/fetch"
6
+ require "nne_client/request"
7
+ require "nne_client/search"
8
+ require "nne_client/query"
9
+ require "nne_client/question"
10
+ require "nne_client/result"
11
+ require "nne_client/result_set"
12
+ require "nne_client/record_types/finance"
13
+ require "nne_client/record_types/ownership"
14
+ require "nne_client/record_types/subsidiary"
15
+ require "nne_client/record_types/trade"
16
+
17
+ HTTPI.adapter = :net_http
18
+
19
+ # Namespace for the library
20
+ module NNEClient
21
+ extend self
22
+ include ConfigNewton
23
+
24
+ class CompanyMissing < RuntimeError; end
25
+
26
+ config :access_key
27
+
28
+ # Where users start the interaction with the library.
29
+ #
30
+ # The query is hash with one or more of these keys:
31
+ #
32
+ # * :houseNo (string)
33
+ # * :name (string)
34
+ # * :nameStartsWith (boolean)
35
+ # * :street (string)
36
+ # * :zipCode (number)
37
+ # * :tdcId (number)
38
+ #
39
+ # @return [ResultSet] containing the results from the SOAP API
40
+ def search(query)
41
+ NNEClient::Search.new(query).result_set
42
+ end
43
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
+ require 'nne_client/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.authors = ["Jacob Atzen"]
7
+ gem.email = ["jacob@incremental.dk"]
8
+ gem.description = %q{Client library for the Navne & Numre Erhverv SOAP service}
9
+ gem.summary = %q{A small library easing integration with NNE}
10
+ gem.homepage = ""
11
+
12
+ gem.files = `git ls-files`.split($\)
13
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "nne_client"
16
+ gem.require_paths = ["lib"]
17
+ gem.version = NNEClient::VERSION
18
+ gem.add_dependency('savon', '~> 0.9.5')
19
+ gem.add_dependency('config_newton', '~> 0.1.1')
20
+ gem.add_development_dependency('vcr')
21
+ gem.add_development_dependency('fakeweb')
22
+ gem.add_development_dependency('rspec')
23
+ gem.add_development_dependency("equivalent-xml", "~> 0.2.9")
24
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe NNEClient::Finance do
4
+ let(:hash) do
5
+ {
6
+ :contribution_ratio => "26.02",
7
+ :net_outcome => "132718.0",
8
+ :stock => "136101.0",
9
+ :assets => "1729700.0",
10
+ :gross_profit => "789841.0",
11
+ :return_on_assets => "13.13",
12
+ :"@xsi:type" => "ns0:Finance",
13
+ :credit_rating => {:"@xsi:type" => "xsd:string"},
14
+ :placings => "38837.0",
15
+ :trade_debitors => "23232.0",
16
+ :available_funds => "183991.0",
17
+ :income_before_income_tax => "188944.0",
18
+ :share_holders_funds_of_interest => "78.96",
19
+ :current_assets => "770605.0",
20
+ :profit => "130000.0",
21
+ :turnover => "3034952.0",
22
+ :available_funds_ratio => "74.48",
23
+ :link_pdf => Date.parse('2012-03-30'),
24
+ :shareholders_funds => "168073.0",
25
+ :depreciations => "-37525.0",
26
+ :profit_for_the_year => "132718.0",
27
+ :@id => "ID2",
28
+ :balance => "1729700.0",
29
+ :long_termed_liability => "488133.0",
30
+ :short_termed_liability => "1034657.0",
31
+ :fixed_assets => "959095.0",
32
+ :number_of_employees => "1222",
33
+ :profit_ratio => "7.48",
34
+ :capacity_ratio => "1.4",
35
+ :lots_and_sites => "162650.0",
36
+ :solvency_ratio => "9.72",
37
+ :accounting_date => Date.parse('2012-03-30'),
38
+ :fixed_cost => "562808.0",
39
+ :published_date => Date.parse('2012-03-30'),
40
+ :year => "2011"
41
+ }
42
+ end
43
+
44
+ subject { NNEClient::Finance.new(hash) }
45
+
46
+ its(:accounting_date) { should == hash[:accounting_date] }
47
+ its(:assets) { should == hash[:assets] }
48
+ its(:available_funds) { should == hash[:available_funds] }
49
+ its(:available_funds_ratio) { should == hash[:available_funds_ratio] }
50
+ its(:balance) { should == hash[:balance] }
51
+ its(:capacity_ratio) { should == hash[:capacity_ratio] }
52
+ its(:contribution_ratio) { should == hash[:contribution_ratio] }
53
+ its(:credit_rating) { should be_nil }
54
+ its(:current_assets) { should == hash[:current_assets] }
55
+ its(:depreciations) { should == hash[:depreciations] }
56
+ its(:fixed_assets) { should == hash[:fixed_assets] }
57
+ its(:fixed_cost) { should == hash[:fixed_cost] }
58
+ its(:gross_profit) { should == hash[:gross_profit] }
59
+ its(:income_before_income_tax) { should == hash[:income_before_income_tax] }
60
+ its(:link_pdf) { should == hash[:link_pdf] }
61
+ its(:long_termed_liability) { should == hash[:long_termed_liability] }
62
+ its(:lots_and_sites) { should == hash[:lots_and_sites] }
63
+ its(:net_outcome) { should == hash[:net_outcome] }
64
+ its(:number_of_employees) { should == hash[:number_of_employees] }
65
+ its(:placings) { should == hash[:placings] }
66
+ its(:profit) { should == hash[:profit] }
67
+ its(:profit_for_the_year) { should == hash[:profit_for_the_year] }
68
+ its(:profit_ratio) { should == hash[:profit_ratio] }
69
+ its(:published_date) { should == hash[:published_date] }
70
+ its(:return_on_assets) { should == hash[:return_on_assets] }
71
+ its(:share_holders_funds_of_interest) { should == hash[:share_holders_funds_of_interest] }
72
+ its(:shareholders_funds) { should == hash[:shareholders_funds] }
73
+ its(:short_termed_liability) { should == hash[:short_termed_liability] }
74
+ its(:solvency_ratio) { should == hash[:solvency_ratio] }
75
+ its(:stock) { should == hash[:stock] }
76
+ its(:trade_debitors) { should == hash[:trade_debitors] }
77
+ its(:turnover) { should == hash[:turnover] }
78
+ its(:year) { should == hash[:year] }
79
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe NNEClient::Ownership do
4
+ let(:ownership_hash) do
5
+ {
6
+ :country => "Holland",
7
+ :"@xsi:type" => "ns0:Ownership",
8
+ :share => "100 ",
9
+ :tdc_id => "123",
10
+ :@id => "ID2",
11
+ :name => "Ingka Holding Scandinavia Bv"
12
+ }
13
+ end
14
+
15
+ subject { NNEClient::Ownership.new(ownership_hash) }
16
+
17
+ it { should eq NNEClient::Ownership.new(ownership_hash) }
18
+ its(:share) { should == '100' }
19
+ its(:name) { should == ownership_hash[:name] }
20
+ its(:country) { should == ownership_hash[:country] }
21
+
22
+ describe "#company" do
23
+ let(:result) { double(:result) }
24
+
25
+ it "knows how to fetch company information" do
26
+ NNEClient::Result.should_receive(:new).with(:tdc_id => '123') { result }
27
+ subject.company
28
+ end
29
+ it "knows how to fetch company information" do
30
+ NNEClient::Result.stub(:new) { result }
31
+ subject.company.should == result
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,284 @@
1
+ require 'spec_helper'
2
+
3
+ describe NNEClient::Result do
4
+
5
+ let(:result_hash) do
6
+ {
7
+ :p_no => "1015150161",
8
+ :fax => {:"@xsi:type" => "xsd:string"},
9
+ :ad_protection => "0",
10
+ :tdc_id => "202541543",
11
+ :"@xsi:type" => "ns0:CompanyBasic",
12
+ :phone => "26256502",
13
+ :company_id => "4218680",
14
+ :official_name => "Incremental V/ Jacob Atzen",
15
+ :street => "Bygmestervej 47 3 tv",
16
+ :zip_code => "2400",
17
+ :company_type => "PL",
18
+ :@id => "ID4",
19
+ :cvr_no => "31999529",
20
+ :district => "København NV"
21
+ }
22
+ end
23
+
24
+ subject { NNEClient::Result.new(result_hash) }
25
+
26
+ its(:cvr_no) { should == result_hash[:cvr_no] }
27
+ its(:p_no) { should == result_hash[:p_no] }
28
+ its(:district) { should == result_hash[:district] }
29
+ its(:official_name) { should == result_hash[:official_name] }
30
+ its(:phone) { should == result_hash[:phone] }
31
+ its(:street) { should == result_hash[:street] }
32
+ its(:zip_code) { should == result_hash[:zip_code] }
33
+ its(:ad_protection) { should == result_hash[:ad_protection] }
34
+ it { should == NNEClient::Result.new(:tdc_id => '202541543') }
35
+
36
+ it "is unique based on tdc_id" do
37
+ [
38
+ NNEClient::Result.new(:tdc_id => '202541543'),
39
+ subject
40
+ ].uniq.size.should == 1
41
+ end
42
+
43
+ it "returns nil for a basic attribute that's a hash" do
44
+ result = NNEClient::Result.new(
45
+ result_hash.merge(:phone => {"@xsi:type" => 'xsd:string'})
46
+ )
47
+ result.phone.should be_nil
48
+ end
49
+
50
+ it "returns nil for an extended attribute that's a hash" do
51
+ soap_vcr('result_fetching_ext_attributes_email_hash') do
52
+ NNEClient.search(:tdcId => '101953776').first.email.should be_nil
53
+ end
54
+ end
55
+
56
+ it "raises CompanyMissing if tdc_id is unknown" do
57
+ soap_vcr('result_fetching_missing_company') do
58
+ expect {
59
+ NNEClient::Result.new(:tdc_id => '202177618').official_name
60
+ }.to raise_error(NNEClient::CompanyMissing)
61
+ end
62
+ end
63
+
64
+ context 'with only tdc_id' do
65
+ around(:each) do |example|
66
+ soap_vcr('result_fetching_basic_attributes') do
67
+ example.run
68
+ end
69
+ end
70
+
71
+ subject { NNEClient::Result.new(:tdc_id => '202541543') }
72
+
73
+ its(:cvr_no) { should == result_hash[:cvr_no] }
74
+ its(:p_no) { should == result_hash[:p_no] }
75
+ its(:district) { should == result_hash[:district] }
76
+ its(:official_name) { should == result_hash[:official_name] }
77
+ its(:phone) { should == result_hash[:phone] }
78
+ its(:street) { should == result_hash[:street] }
79
+ its(:zip_code) { should == result_hash[:zip_code] }
80
+ its(:ad_protection) { should == result_hash[:ad_protection] }
81
+ end
82
+
83
+ context "with extended info" do
84
+ context "with an access key" do
85
+ around(:each) do |example|
86
+ NNEClient.configure { |config| config.access_key = 'some key' }
87
+ soap_vcr('result_extended_info_with_access_key') do
88
+ example.run
89
+ end
90
+ NNEClient.configure { |config| config.access_key = nil }
91
+ end
92
+
93
+ its(:email) { should == 'jacob@incremental.dk' }
94
+ its(:homepage) { should be_nil }
95
+ its(:founded_year) { should == '2009' }
96
+ its(:number_of_employees) { should == '0' }
97
+ its(:tdf_name) { should == 'Incremental' }
98
+ its(:status_text) { should == 'Selskabet er i normal drift.' }
99
+ end
100
+
101
+ context "without an access key" do
102
+ around(:each) do |example|
103
+ soap_vcr('result_extended_info') do
104
+ example.run
105
+ end
106
+ end
107
+
108
+ its(:email) { should == 'jacob@incremental.dk' }
109
+ its(:homepage) { should be_nil }
110
+ its(:founded_year) { should == '2009' }
111
+ its(:number_of_employees) { should == '0' }
112
+ its(:tdf_name) { should == 'Incremental' }
113
+ its(:status_text) { should == 'Selskabet er i normal drift.' }
114
+ end
115
+ end
116
+
117
+ context "with a single trade" do
118
+ around(:each) do |example|
119
+ soap_vcr('result_trades') do
120
+ example.run
121
+ end
122
+ end
123
+
124
+ its(:trades) {
125
+ should eq [
126
+ NNEClient::Trade.new(
127
+ :primary => true,
128
+ :trade => 'Konsulentbistand vedrørende informationsteknologi',
129
+ :trade_code => '620200'
130
+ )
131
+ ]
132
+ }
133
+ end
134
+
135
+ context "with multiple trades" do
136
+ around(:each) do |example|
137
+ soap_vcr('result_multiple_trades') do
138
+ example.run
139
+ end
140
+ end
141
+
142
+ subject do NNEClient.search(:name => 'Dansk Supermarked').to_a[5] end
143
+
144
+ its(:trades) {
145
+ should include NNEClient::Trade.new(
146
+ :primary => true,
147
+ :trade => "Anden detailhandel fra ikke-specialiserede forretninger",
148
+ :trade_code => "471900"
149
+ )
150
+ }
151
+
152
+ its(:trades) {
153
+ should include NNEClient::Trade.new(
154
+ :primary => false,
155
+ :trade => "Discountforretninger",
156
+ :trade_code => "471130"
157
+ )
158
+ }
159
+ end
160
+
161
+ context "with no ownership information" do
162
+ around(:each) do |example|
163
+ soap_vcr('result_no_ownerships') do
164
+ example.run
165
+ end
166
+ end
167
+
168
+ subject { NNEClient::Result.new(result_hash) }
169
+
170
+ its(:ownerships) { should be_empty }
171
+ end
172
+
173
+ context "with single ownership" do
174
+ around(:each) do |example|
175
+ soap_vcr('result_single_ownership') do
176
+ example.run
177
+ end
178
+ end
179
+
180
+ subject { NNEClient.search(:name => 'Ikea').first }
181
+
182
+ its(:ownerships) {
183
+ should include NNEClient::Ownership.new(
184
+ :share => '100 ',
185
+ :name => 'Ingka Holding Scandinavia Bv',
186
+ :country => 'Holland'
187
+ )
188
+ }
189
+ end
190
+
191
+ context "with multiple ownership" do
192
+ around(:each) do |example|
193
+ soap_vcr('result_multiple_ownerships') do
194
+ example.run
195
+ end
196
+ end
197
+
198
+ subject { NNEClient.search(:tdcId => '100319964').first }
199
+
200
+ its(:ownerships) {
201
+ should include NNEClient::Ownership.new(
202
+ :share => '33 ',
203
+ :name => 'Henrik Harald Halberg',
204
+ :country => nil
205
+ )
206
+ }
207
+ end
208
+
209
+ context "with no subsidiaries" do
210
+ it "has no subsidiares" do
211
+ soap_vcr('result_no_subsidiaries') do
212
+ result = NNEClient.search(:tdcId => '100319964').first
213
+ result.subsidiaries.should be_empty
214
+ end
215
+ end
216
+ end
217
+
218
+ context "with a single subsidiary" do
219
+ it "returns the subsidiary" do
220
+ soap_vcr('result_single_subsidiary') do
221
+ NNEClient.search(:name => 'Ikea').first.subsidiaries.should eq [
222
+ NNEClient::Subsidiary.new(
223
+ :country => "Danmark",
224
+ :share => "100",
225
+ :name => "Ikea Ejendomme ApS"
226
+ )
227
+ ]
228
+ end
229
+ end
230
+ end
231
+
232
+ context 'with no finances' do
233
+ it "returns an empty array of finances" do
234
+ soap_vcr('result_no_finance') do
235
+ NNEClient.search(:name => 'Incremental').first.finances.should be_empty
236
+ end
237
+ end
238
+ end
239
+
240
+ context 'with a single finance record' do
241
+ it "has a finance record" do
242
+ soap_vcr('result_single_finance') do
243
+ records = NNEClient.search(:name => 'Etech').first.finances
244
+ records.map(&:year).should == ['2010']
245
+ end
246
+ end
247
+ end
248
+
249
+ context 'with multiple finance records' do
250
+ it "has several finance records" do
251
+ soap_vcr('result_multiple_finances') do
252
+ records = NNEClient.search(:name => 'Ikea').first.finances
253
+ records.map(&:year).should == ["2011", "2010", "2009", "2008", "2007"]
254
+ end
255
+ end
256
+ end
257
+
258
+ it "knows all names" do
259
+ soap_vcr('result_names') do
260
+ result = NNEClient::Result.new(:official_name => 'Name', :tdc_id => '100323228')
261
+ result.additional_names.should == [
262
+ "Tv Holbæk A/S",
263
+ "A/S Trykkeriet Nordvest",
264
+ "A/S Trykkeriet Nordvestsjælland",
265
+ "Nordvestsjællands Media Selskab A/S",
266
+ "Radio Holbæk A/S"
267
+ ]
268
+ end
269
+ end
270
+
271
+ it "will convert additional_names to an array" do
272
+ soap_vcr('result_additional_names_single') do
273
+ result = NNEClient::Result.new(:tdc_id => '101952996')
274
+ result.additional_names.should == [ 'Eb Flytning ApS' ]
275
+ end
276
+ end
277
+
278
+ it "is an empty array if no additinal names present" do
279
+ soap_vcr('result_names_empty') do
280
+ result = NNEClient::Result.new(:official_name => 'Name', :tdc_id => '202541543')
281
+ result.additional_names.should == []
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+ require 'nne_client'
3
+
4
+ describe NNEClient::Search do
5
+ describe 'a search with a single match' do
6
+ it 'finds the company' do
7
+ soap_vcr('search_lokalebasen') do
8
+ NNEClient::Search.new(:name => 'Lokalebasen').result_set.first.official_name.should == 'Lokalebasen.DK A/S'
9
+ end
10
+ end
11
+ end
12
+
13
+ describe 'a search with multiple matches' do
14
+ subject do
15
+ soap_vcr('search_lokale') do
16
+ NNEClient::Search.new(:name => 'Lokale').result_set
17
+ end
18
+ end
19
+
20
+ it 'finds the company' do
21
+ subject.first.official_name.should == 'Andelsselskabet De Lokale Boliger'
22
+ end
23
+
24
+ it 'knows the number of matches' do
25
+ subject.total.should == 124
26
+ end
27
+ end
28
+
29
+ describe 'asking for more results' do
30
+ subject do
31
+ soap_vcr('search_lokale_100') do
32
+ NNEClient::Search.new(:name => 'Lokale', :hits_per_page => 100).result_set
33
+ end
34
+ end
35
+
36
+ it 'finds the company' do
37
+ subject.first.official_name.should == 'Andelsselskabet De Lokale Boliger'
38
+ end
39
+
40
+ it 'fetches 100 records' do
41
+ subject.count.should == 100
42
+ end
43
+ end
44
+
45
+ describe "searching for something non existent" do
46
+ subject do
47
+ soap_vcr('search_for_noise') do
48
+ NNEClient::Search.new(:name => 'asdfasdfasdf').result_set
49
+ end
50
+ end
51
+
52
+ it 'has a total of 0 results' do
53
+ subject.total.should == 0
54
+ end
55
+
56
+ it 'fetches 0 records' do
57
+ subject.count.should == 0
58
+ end
59
+
60
+ it 'can iterate' do
61
+ expect { |block|
62
+ subject.each(&block)
63
+ }.not_to yield_control
64
+ end
65
+ end
66
+
67
+ describe 'with an access key' do
68
+ before(:each) do
69
+ NNEClient.configure { |config| config.access_key = 'some key' }
70
+ end
71
+
72
+ it 'finds the company' do
73
+ soap_vcr('search_lokalebasen_with_access_key') do
74
+ NNEClient::Search.new(:name => 'Lokalebasen').result_set.first.official_name.should == 'Lokalebasen.DK A/S'
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'vcr'
3
+ require 'equivalent-xml'
4
+ require 'nne_client'
5
+
6
+ HTTPI.log = false
7
+
8
+ Savon.configure do |config|
9
+ config.log = false # disable logging
10
+ config.log_level = :info # changing the log level
11
+ # config.logger = Rails.logger # using the Rails logger
12
+ end
13
+
14
+
15
+ VCR.configure do |c|
16
+ c.cassette_library_dir = 'spec/vcr_cassettes'
17
+ c.hook_into :fakeweb
18
+ c.register_request_matcher :soap_body_matcher do |request_1, request_2|
19
+ node_1 = Nokogiri::XML(request_1.body)
20
+ node_2 = Nokogiri::XML(request_2.body)
21
+ EquivalentXml.equivalent?(node_1, node_2, opts = { :element_order => true, :normalize_whitespace => false })
22
+ end
23
+ end
24
+
25
+ def soap_vcr(cassette_name)
26
+ VCR.use_cassette(cassette_name, :match_requests_on => [:soap_body_matcher]) do
27
+ yield
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe NNEClient::Subsidiary do
4
+ let(:subsidiary_hash) do
5
+ {
6
+ :country => "Holland",
7
+ :"@xsi:type" => "ns0:Subsidiary",
8
+ :share => "100 ",
9
+ :tdc_id => "123",
10
+ :@id => "ID2",
11
+ :name => "Ingka Holding Scandinavia Bv"
12
+ }
13
+ end
14
+
15
+ subject { NNEClient::Subsidiary.new(subsidiary_hash) }
16
+
17
+ it { should eq NNEClient::Subsidiary.new(subsidiary_hash) }
18
+ its(:share) { should == '100' }
19
+ its(:name) { should == subsidiary_hash[:name] }
20
+ its(:country) { should == subsidiary_hash[:country] }
21
+
22
+ describe "#company" do
23
+ let(:result) { double(:result) }
24
+
25
+ it "knows how to fetch company information" do
26
+ NNEClient::Result.should_receive(:new).with(:tdc_id => '123') { result }
27
+ subject.company
28
+ end
29
+ it "knows how to fetch company information" do
30
+ NNEClient::Result.stub(:new) { result }
31
+ subject.company.should == result
32
+ end
33
+ end
34
+
35
+ end
36
+
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe NNEClient::Trade do
4
+ let(:trade_hash) do
5
+ {
6
+ :"@xsi:type" => "ns0:Trade",
7
+ :primary => true,
8
+ :trade_code => "471900",
9
+ :@id => "ID2",
10
+ :trade => "Anden detailhandel fra ikke-specialiserede forretninger"
11
+ }
12
+ end
13
+
14
+ subject { NNEClient::Trade.new(trade_hash) }
15
+
16
+ it { should be_primary }
17
+ it { should eq NNEClient::Trade.new(trade_hash) }
18
+ its(:trade_code) { should == trade_hash[:trade_code] }
19
+ its(:trade) { should == trade_hash[:trade] }
20
+
21
+ end