creditsafe 0.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.rubocop.yml +24 -0
- data/.rubocop_todo.yml +16 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +141 -0
- data/Guardfile +75 -0
- data/README.md +55 -0
- data/circle.yml +8 -0
- data/creditsafe.gemspec +30 -0
- data/data/creditsafe-live.xml +1 -0
- data/lib/creditsafe.rb +2 -0
- data/lib/creditsafe/client.rb +185 -0
- data/lib/creditsafe/errors.rb +6 -0
- data/lib/creditsafe/messages.rb +81 -0
- data/lib/creditsafe/version.rb +3 -0
- data/spec/creditsafe/client_spec.rb +237 -0
- data/spec/creditsafe/messages_spec.rb +33 -0
- data/spec/fixtures/company-report-not-found.xml +13 -0
- data/spec/fixtures/company-report-successful.xml +582 -0
- data/spec/fixtures/error-fault.xml +8 -0
- data/spec/fixtures/error-invalid-credentials.html +31 -0
- data/spec/fixtures/find-companies-error-no-text.xml +11 -0
- data/spec/fixtures/find-companies-error.xml +11 -0
- data/spec/fixtures/find-companies-none-found.xml +13 -0
- data/spec/fixtures/find-companies-successful-multi.xml +493 -0
- data/spec/fixtures/find-companies-successful.xml +29 -0
- data/spec/spec_helper.rb +11 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e29e350fc4b5fe1cd81b1855d7cfc43fa35afc4
|
4
|
+
data.tar.gz: 36bb660af1c51a7e2dde56443cfbba02e2c22b1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81d10c8255127c3f1bad547ea4beaed8573de038b01188846c4e0ed3a7771ce54e446d7e931681d33dc9df2a6be59f9e5825f2602f1ed98423c2a51ae47b2feb
|
7
|
+
data.tar.gz: 7c4c938c09a66213c0267172d1e16c9b169dc8dfff24f3acb342f9ae2998c89d3cc1613b7694714d6848b1bd64fee13985a5d8fe7fad3a5458844c720ec570cd
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
# Avoid single-line methods.
|
4
|
+
SingleLineMethods:
|
5
|
+
AllowIfMethodIsEmpty: true
|
6
|
+
|
7
|
+
StringLiterals:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/SignalException:
|
11
|
+
EnforcedStyle: 'only_raise'
|
12
|
+
|
13
|
+
# Use trailing rather than leading dots on multi-line call chains
|
14
|
+
Style/DotPosition:
|
15
|
+
EnforcedStyle: trailing
|
16
|
+
|
17
|
+
Style/Documentation:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/MethodLength:
|
21
|
+
Max: 15
|
22
|
+
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Max: 150
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-06-12 14:00:56 +0100 using RuboCop version 0.32.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
7
|
+
|
8
|
+
# Offense count: 1
|
9
|
+
# Configuration parameters: CountComments.
|
10
|
+
Metrics/ClassLength:
|
11
|
+
Max: 114
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 14
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
creditsafe (0.1.1)
|
5
|
+
excon (~> 0.45)
|
6
|
+
savon (~> 2.8)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.3.8)
|
12
|
+
akami (1.3.1)
|
13
|
+
gyoku (>= 0.4.0)
|
14
|
+
nokogiri
|
15
|
+
ast (2.2.0)
|
16
|
+
builder (3.2.2)
|
17
|
+
byebug (4.0.5)
|
18
|
+
columnize (= 0.9.0)
|
19
|
+
celluloid (0.16.0)
|
20
|
+
timers (~> 4.0.0)
|
21
|
+
coderay (1.1.0)
|
22
|
+
columnize (0.9.0)
|
23
|
+
crack (0.4.2)
|
24
|
+
safe_yaml (~> 1.0.0)
|
25
|
+
diff-lcs (1.2.5)
|
26
|
+
excon (0.45.3)
|
27
|
+
ffi (1.9.8)
|
28
|
+
formatador (0.2.5)
|
29
|
+
guard (2.12.6)
|
30
|
+
formatador (>= 0.2.4)
|
31
|
+
listen (~> 2.7)
|
32
|
+
lumberjack (~> 1.0)
|
33
|
+
nenv (~> 0.1)
|
34
|
+
notiffany (~> 0.0)
|
35
|
+
pry (>= 0.9.12)
|
36
|
+
shellany (~> 0.0)
|
37
|
+
thor (>= 0.18.1)
|
38
|
+
guard-compat (1.2.1)
|
39
|
+
guard-rspec (4.5.2)
|
40
|
+
guard (~> 2.1)
|
41
|
+
guard-compat (~> 1.1)
|
42
|
+
rspec (>= 2.99.0, < 4.0)
|
43
|
+
guard-rubocop (1.2.0)
|
44
|
+
guard (~> 2.0)
|
45
|
+
rubocop (~> 0.20)
|
46
|
+
gyoku (1.3.1)
|
47
|
+
builder (>= 2.1.2)
|
48
|
+
hitimes (1.2.2)
|
49
|
+
httpi (2.4.0)
|
50
|
+
rack
|
51
|
+
listen (2.10.0)
|
52
|
+
celluloid (~> 0.16.0)
|
53
|
+
rb-fsevent (>= 0.9.3)
|
54
|
+
rb-inotify (>= 0.9)
|
55
|
+
lumberjack (1.0.9)
|
56
|
+
method_source (0.8.2)
|
57
|
+
mini_portile (0.6.2)
|
58
|
+
nenv (0.2.0)
|
59
|
+
nokogiri (1.6.6.2)
|
60
|
+
mini_portile (~> 0.6.0)
|
61
|
+
nori (2.6.0)
|
62
|
+
notiffany (0.0.6)
|
63
|
+
nenv (~> 0.1)
|
64
|
+
shellany (~> 0.0)
|
65
|
+
parser (2.3.0.6)
|
66
|
+
ast (~> 2.2)
|
67
|
+
powerpack (0.1.1)
|
68
|
+
pry (0.10.1)
|
69
|
+
coderay (~> 1.1.0)
|
70
|
+
method_source (~> 0.8.1)
|
71
|
+
slop (~> 3.4)
|
72
|
+
pry-byebug (3.1.0)
|
73
|
+
byebug (~> 4.0)
|
74
|
+
pry (~> 0.10)
|
75
|
+
rack (1.6.1)
|
76
|
+
rainbow (2.1.0)
|
77
|
+
rb-fsevent (0.9.5)
|
78
|
+
rb-inotify (0.9.5)
|
79
|
+
ffi (>= 0.5.0)
|
80
|
+
rspec (3.2.0)
|
81
|
+
rspec-core (~> 3.2.0)
|
82
|
+
rspec-expectations (~> 3.2.0)
|
83
|
+
rspec-mocks (~> 3.2.0)
|
84
|
+
rspec-core (3.2.3)
|
85
|
+
rspec-support (~> 3.2.0)
|
86
|
+
rspec-expectations (3.2.1)
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
88
|
+
rspec-support (~> 3.2.0)
|
89
|
+
rspec-its (1.2.0)
|
90
|
+
rspec-core (>= 3.0.0)
|
91
|
+
rspec-expectations (>= 3.0.0)
|
92
|
+
rspec-mocks (3.2.1)
|
93
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
94
|
+
rspec-support (~> 3.2.0)
|
95
|
+
rspec-support (3.2.2)
|
96
|
+
rubocop (0.37.2)
|
97
|
+
parser (>= 2.3.0.4, < 3.0)
|
98
|
+
powerpack (~> 0.1)
|
99
|
+
rainbow (>= 1.99.1, < 3.0)
|
100
|
+
ruby-progressbar (~> 1.7)
|
101
|
+
unicode-display_width (~> 0.3)
|
102
|
+
ruby-progressbar (1.7.5)
|
103
|
+
safe_yaml (1.0.4)
|
104
|
+
savon (2.11.1)
|
105
|
+
akami (~> 1.2)
|
106
|
+
builder (>= 2.1.2)
|
107
|
+
gyoku (~> 1.2)
|
108
|
+
httpi (~> 2.3)
|
109
|
+
nokogiri (>= 1.4.0)
|
110
|
+
nori (~> 2.4)
|
111
|
+
wasabi (~> 3.4)
|
112
|
+
shellany (0.0.1)
|
113
|
+
slop (3.6.0)
|
114
|
+
thor (0.19.1)
|
115
|
+
timers (4.0.1)
|
116
|
+
hitimes
|
117
|
+
unicode-display_width (0.3.1)
|
118
|
+
wasabi (3.5.0)
|
119
|
+
httpi (~> 2.0)
|
120
|
+
nokogiri (>= 1.4.2)
|
121
|
+
webmock (1.21.0)
|
122
|
+
addressable (>= 2.3.6)
|
123
|
+
crack (>= 0.3.2)
|
124
|
+
|
125
|
+
PLATFORMS
|
126
|
+
ruby
|
127
|
+
|
128
|
+
DEPENDENCIES
|
129
|
+
bundler (~> 1.3)
|
130
|
+
creditsafe!
|
131
|
+
guard-rspec (~> 4.5)
|
132
|
+
guard-rubocop (~> 1.2)
|
133
|
+
pry
|
134
|
+
pry-byebug
|
135
|
+
rspec (~> 3.1)
|
136
|
+
rspec-its (~> 1.2)
|
137
|
+
rubocop (~> 0.37)
|
138
|
+
webmock (~> 1.20)
|
139
|
+
|
140
|
+
BUNDLED WITH
|
141
|
+
1.10.6
|
data/Guardfile
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
20
|
+
# * bundler: 'bundle exec rspec'
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
23
|
+
# installed the spring binstubs per the docs)
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
|
+
# * 'just' rspec: 'rspec'
|
26
|
+
|
27
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
28
|
+
require 'guard/rspec/dsl'
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
|
+
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
32
|
+
|
33
|
+
# RSpec files
|
34
|
+
rspec = dsl.rspec
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_files)
|
38
|
+
|
39
|
+
# Ruby files
|
40
|
+
ruby = dsl.ruby
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
42
|
+
|
43
|
+
# Rails files
|
44
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
45
|
+
dsl.watch_spec_files_for(rails.app_files)
|
46
|
+
dsl.watch_spec_files_for(rails.views)
|
47
|
+
|
48
|
+
watch(rails.controllers) do |m|
|
49
|
+
[
|
50
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
51
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
52
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
53
|
+
]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Rails config changes
|
57
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
58
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
59
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
60
|
+
|
61
|
+
# Capybara features specs
|
62
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
63
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
64
|
+
|
65
|
+
# Turnip features and steps
|
66
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
67
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
guard :rubocop do
|
73
|
+
watch(/.+\.rb$/)
|
74
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
75
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# creditsafe-ruby
|
2
|
+
|
3
|
+
*Build status: [](https://circleci.com/gh/gocardless/creditsafe-ruby)*
|
4
|
+
|
5
|
+
A ruby library for interacting with the
|
6
|
+
[creditsafe](http://www.creditsafeuk.com/) API.
|
7
|
+
|
8
|
+
Currently, it only partially implements the API to support finding companies by
|
9
|
+
registration number and retrieving company online reports.
|
10
|
+
|
11
|
+
# Usage
|
12
|
+
|
13
|
+
Initialise the client with your `username` and `password`.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
client = Creditsafe::Client.new(username: "foo", password: "bar")
|
17
|
+
```
|
18
|
+
|
19
|
+
### Company Search
|
20
|
+
|
21
|
+
To perform a search for a company, you need to provide a country code and a company registration number.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
client.find_company(country_code: "GB", registration_number: "07495895")
|
25
|
+
=> {
|
26
|
+
name: "GOCARDLESS LTD",
|
27
|
+
type: "Ltd",
|
28
|
+
status: "Active",
|
29
|
+
registration_number: "07495895",
|
30
|
+
address: {
|
31
|
+
simple_value: "338-346, GOSWELL, LONDON",
|
32
|
+
postal_code: "EC1V7LQ"
|
33
|
+
},
|
34
|
+
available_report_types: { available_report_type: "Full" },
|
35
|
+
available_languages: { available_language: "EN" },
|
36
|
+
@date_of_latest_accounts: "2014-01-31T00:00:00Z",
|
37
|
+
@online_reports: "true",
|
38
|
+
@monitoring: "false",
|
39
|
+
@country: "GB",
|
40
|
+
@id: "GB003/0/07495895"
|
41
|
+
}
|
42
|
+
```
|
43
|
+
|
44
|
+
### Company Report
|
45
|
+
|
46
|
+
To download all the information available in an online company report, you will
|
47
|
+
need the company's creditsafe identifier (obtainable using
|
48
|
+
[find_company](#find_company) above.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
client.company_report(creditsafe_id: "GB003/0/07495895")
|
52
|
+
=> {
|
53
|
+
...
|
54
|
+
}
|
55
|
+
```
|
data/circle.yml
ADDED
data/creditsafe.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'creditsafe/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'creditsafe'
|
8
|
+
spec.version = Creditsafe::VERSION
|
9
|
+
spec.authors = ['Pete Hamilton']
|
10
|
+
spec.email = ['engineering@gocardless.com']
|
11
|
+
spec.summary = 'Ruby client for the Creditsafe SOAP API'
|
12
|
+
spec.description = 'Ruby client for the Creditsafe SOAP API'
|
13
|
+
spec.homepage = 'https://github.com/gocardless/creditsafe-ruby'
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'savon', '~> 2.8'
|
21
|
+
spec.add_runtime_dependency 'excon', '~> 0.45'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
25
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
26
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.5'
|
27
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.2'
|
28
|
+
spec.add_development_dependency 'rubocop', '~> 0.37'
|
29
|
+
spec.add_development_dependency 'webmock', '~> 1.20'
|
30
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?><wsdl:definitions name="MainServiceBasic" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:i1="http://www.creditsafe.com/globaldata/operations/administration" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:i0="http://www.creditsafe.com/globaldata/operations" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><wsp:Policy wsu:Id="BasicHttpBinding_GlobalDataService_policy"><wsp:ExactlyOne><wsp:All><sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:Policy><sp:TransportToken><wsp:Policy><sp:HttpsToken RequireClientCertificate="false"/></wsp:Policy></sp:TransportToken><sp:AlgorithmSuite><wsp:Policy><sp:Basic256/></wsp:Policy></sp:AlgorithmSuite><sp:Layout><wsp:Policy><sp:Strict/></wsp:Policy></sp:Layout></wsp:Policy></sp:TransportBinding></wsp:All></wsp:ExactlyOne></wsp:Policy><wsp:Policy wsu:Id="BasicHttpBinding_DataInputService_policy"><wsp:ExactlyOne><wsp:All><sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:Policy><sp:TransportToken><wsp:Policy><sp:HttpsToken RequireClientCertificate="false"/></wsp:Policy></sp:TransportToken><sp:AlgorithmSuite><wsp:Policy><sp:Basic256/></wsp:Policy></sp:AlgorithmSuite><sp:Layout><wsp:Policy><sp:Strict/></wsp:Policy></sp:Layout></wsp:Policy></sp:TransportBinding></wsp:All></wsp:ExactlyOne></wsp:Policy><wsdl:import namespace="http://www.creditsafe.com/globaldata/operations" location="https://webservices.creditsafe.com/GlobalData/1.3/MainServiceBasic.svc/meta?wsdl=wsdl0"/><wsdl:import namespace="http://www.creditsafe.com/globaldata/operations/administration" location="https://webservices.creditsafe.com/GlobalData/1.3/MainServiceBasic.svc/meta?wsdl=wsdl1"/><wsdl:types/><wsdl:binding name="BasicHttpBinding_GlobalDataService" type="i0:GlobalDataService"><wsp:PolicyReference URI="#BasicHttpBinding_GlobalDataService_policy"/><soap:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="GetPortfolios"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/GetPortfolios" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="ListMonitoredCompanies"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/ListMonitoredCompanies" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="CreatePortfolio"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/CreatePortfolio" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="RemovePortfolios"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/RemovePortfolios" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetPortfolioSettings"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/GetPortfolioSettings" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="SetPortfolioSettings"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/SetPortfolioSettings" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="AddCompaniesToPortfolios"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/AddCompaniesToPortfolios" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="ImportCompaniesToPortfolio"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/ImportCompaniesToPortfolio" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="RemoveCompaniesFromPortfolios"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/RemoveCompaniesFromPortfolios" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="ChangeCompaniesReferenceStrings"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/ChangeCompaniesReferenceStrings" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetSupportedChangeEvents"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/GetSupportedChangeEvents" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetMonitoringRules"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/GetMonitoringRules" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="SetMonitoringRules"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/SetMonitoringRules" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="SetDefaultChangesCheckPeriod"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyMonitoringService/SetDefaultChangesCheckPeriod" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="RetrieveCompanyOnlineReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/RetrieveCompanyOnlineReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="TryRetrieveCompanyOnlineReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/TryRetrieveCompanyOnlineReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="OrderCompanyOfflineReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/OrderCompanyOfflineReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetReportboxContents"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/GetReportboxContents" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetReportboxReports"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/GetReportboxReports" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="RemoveReportboxReports"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/CompanyDataAccessService/RemoveReportboxReports" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetCountries"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/DataBrowsingService/GetCountries" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetPossibleSearchCriteria"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/DataBrowsingService/GetPossibleSearchCriteria" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="FindCompanies"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/DataBrowsingService/FindCompanies" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetReportCustomDataSchema"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/DataBrowsingService/GetReportCustomDataSchema" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="BasicHttpBinding_DataInputService" type="i1:DataInputService"><wsp:PolicyReference URI="#BasicHttpBinding_DataInputService_policy"/><soap:binding transport="http://schemas.xmlsoap.org/soap/http"/><wsdl:operation name="DeliverOfflineCompanyReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/DeliverOfflineCompanyReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="MarkFailedOfflineOrder"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/MarkFailedOfflineOrder" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="ListOfflineOrders"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/ListOfflineOrders" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="ListRealisedOrders"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/ListRealisedOrders" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="GetStoredReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/GetStoredReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation><wsdl:operation name="UpdateStoredReport"><soap:operation soapAction="http://www.creditsafe.com/globaldata/operations/administration/DataInputService/UpdateStoredReport" style="document"/><wsdl:input><soap:body use="literal"/></wsdl:input><wsdl:output><soap:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="MainServiceBasic"><wsdl:port name="BasicHttpBinding_GlobalDataService" binding="tns:BasicHttpBinding_GlobalDataService"><soap:address location="https://webservices.creditsafe.com/GlobalData/1.3/MainServiceBasic.svc"/></wsdl:port><wsdl:port name="BasicHttpBinding_DataInputService" binding="tns:BasicHttpBinding_DataInputService"><soap:address location="https://webservices.creditsafe.com/GlobalData/1.3/MainServiceBasic.svc/dataInput"/></wsdl:port></wsdl:service></wsdl:definitions>
|
data/lib/creditsafe.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'savon'
|
3
|
+
require 'excon'
|
4
|
+
|
5
|
+
require 'creditsafe/errors'
|
6
|
+
require 'creditsafe/messages'
|
7
|
+
|
8
|
+
module Creditsafe
|
9
|
+
class Client
|
10
|
+
XMLNS_OPER = 'oper'.freeze
|
11
|
+
XMLNS_OPER_VAL = 'http://www.creditsafe.com/globaldata/operations'.freeze
|
12
|
+
|
13
|
+
XMLNS_DAT = 'dat'.freeze
|
14
|
+
XMLNS_DAT_VAL = 'http://www.creditsafe.com/globaldata/datatypes'.freeze
|
15
|
+
|
16
|
+
XMLNS_CRED = 'cred'.freeze
|
17
|
+
XMLNS_CRED_VAL =
|
18
|
+
'http://schemas.datacontract.org/2004/07/Creditsafe.GlobalData'.freeze
|
19
|
+
|
20
|
+
def initialize(username: nil, password: nil, savon_opts: {})
|
21
|
+
raise ArgumentError, "Username must be provided" if username.nil?
|
22
|
+
raise ArgumentError, "Password must be provided" if password.nil?
|
23
|
+
|
24
|
+
@username = username
|
25
|
+
@password = password
|
26
|
+
@savon_opts = savon_opts
|
27
|
+
end
|
28
|
+
|
29
|
+
def find_company(search_criteria = {})
|
30
|
+
check_search_criteria(search_criteria)
|
31
|
+
|
32
|
+
response = wrap_soap_errors do
|
33
|
+
message = find_company_message(search_criteria)
|
34
|
+
client.call(:find_companies, message: message)
|
35
|
+
end
|
36
|
+
|
37
|
+
companies = response.
|
38
|
+
fetch(:find_companies_response).
|
39
|
+
fetch(:find_companies_result).
|
40
|
+
fetch(:companies)
|
41
|
+
|
42
|
+
companies.nil? ? nil : companies.fetch(:company)
|
43
|
+
end
|
44
|
+
|
45
|
+
def company_report(creditsafe_id, custom_data: nil)
|
46
|
+
response = wrap_soap_errors do
|
47
|
+
message = retrieve_company_report_message(creditsafe_id, custom_data)
|
48
|
+
client.call(:retrieve_company_online_report, message: message)
|
49
|
+
end
|
50
|
+
|
51
|
+
response.
|
52
|
+
fetch(:retrieve_company_online_report_response).
|
53
|
+
fetch(:retrieve_company_online_report_result).
|
54
|
+
fetch(:reports).
|
55
|
+
fetch(:report)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def check_search_criteria(search_criteria)
|
61
|
+
if search_criteria[:country_code].nil?
|
62
|
+
raise ArgumentError, "country_code is a required search criteria"
|
63
|
+
end
|
64
|
+
|
65
|
+
if search_criteria[:registration_number].nil?
|
66
|
+
raise ArgumentError, "registration_number is a required search criteria"
|
67
|
+
end
|
68
|
+
|
69
|
+
if search_criteria[:city] && search_criteria[:country_code] != 'DE'
|
70
|
+
raise ArgumentError, "city is only supported for German searches"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def find_company_message(provided_criteria)
|
75
|
+
search_criteria = {
|
76
|
+
"#{XMLNS_DAT}:RegistrationNumber" =>
|
77
|
+
provided_criteria[:registration_number]
|
78
|
+
}
|
79
|
+
|
80
|
+
unless provided_criteria[:city].nil?
|
81
|
+
search_criteria["#{XMLNS_DAT}:Address"] =
|
82
|
+
{ "#{XMLNS_DAT}:City" => provided_criteria[:city] }
|
83
|
+
end
|
84
|
+
|
85
|
+
{
|
86
|
+
"#{XMLNS_OPER}:countries" => {
|
87
|
+
"#{XMLNS_CRED}:CountryCode" => provided_criteria[:country_code]
|
88
|
+
},
|
89
|
+
"#{XMLNS_OPER}:searchCriteria" => search_criteria
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
def retrieve_company_report_message(company_id, custom_data)
|
94
|
+
message = {
|
95
|
+
"#{XMLNS_OPER}:companyId" => company_id.to_s,
|
96
|
+
"#{XMLNS_OPER}:reportType" => 'Full',
|
97
|
+
"#{XMLNS_OPER}:language" => "EN"
|
98
|
+
}
|
99
|
+
|
100
|
+
unless custom_data.nil?
|
101
|
+
message["#{XMLNS_OPER}:customData"] = {
|
102
|
+
"#{XMLNS_DAT}:Entries" => {
|
103
|
+
"#{XMLNS_DAT}:Entry" => custom_data_entries(custom_data)
|
104
|
+
}
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
message
|
109
|
+
end
|
110
|
+
|
111
|
+
def custom_data_entries(custom_data)
|
112
|
+
custom_data.map { |key, value| { :@key => key, :content! => value } }
|
113
|
+
end
|
114
|
+
|
115
|
+
def handle_message_for_response(response)
|
116
|
+
[
|
117
|
+
*response.xpath('//q1:Message'),
|
118
|
+
*response.xpath('//xmlns:Message')
|
119
|
+
].each do |message|
|
120
|
+
api_message = Creditsafe::Messages.
|
121
|
+
for_code(message.attributes['Code'].value)
|
122
|
+
|
123
|
+
api_error_message = api_message.message
|
124
|
+
api_error_message += " (#{message.text})" unless message.text.blank?
|
125
|
+
|
126
|
+
raise ApiError, api_error_message if api_message.error?
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Takes a proc and rescues any SOAP faults, HTTP errors or Creditsafe errors
|
131
|
+
# There's a potential bug in the creditsafe API where they actually return
|
132
|
+
# an HTTP 401 if you're unauthorized, hence the sad special case below
|
133
|
+
def wrap_soap_errors
|
134
|
+
response = yield
|
135
|
+
handle_message_for_response(response)
|
136
|
+
response.body
|
137
|
+
rescue => error
|
138
|
+
handle_error(error)
|
139
|
+
end
|
140
|
+
|
141
|
+
def handle_error(error)
|
142
|
+
raise error
|
143
|
+
rescue Savon::SOAPFault => error
|
144
|
+
raise ApiError, error.message
|
145
|
+
rescue Savon::HTTPError => error
|
146
|
+
if error.to_hash[:code] == 401
|
147
|
+
raise ApiError, 'Unauthorized: invalid credentials'
|
148
|
+
end
|
149
|
+
raise ApiError, error.message
|
150
|
+
rescue Excon::Errors::Error => err
|
151
|
+
raise HttpError, "Error making HTTP request: #{err.message}"
|
152
|
+
end
|
153
|
+
|
154
|
+
def client
|
155
|
+
@client ||= build_savon_client
|
156
|
+
end
|
157
|
+
|
158
|
+
def auth_header
|
159
|
+
auth_value = 'Basic ' + Base64.encode64("#{@username}:#{@password}").chomp
|
160
|
+
{ 'Authorization' => auth_value }
|
161
|
+
end
|
162
|
+
|
163
|
+
def build_savon_client
|
164
|
+
options = {
|
165
|
+
env_namespace: 'soapenv',
|
166
|
+
namespace_identifier: XMLNS_OPER,
|
167
|
+
namespaces: {
|
168
|
+
"xmlns:#{XMLNS_OPER}" => XMLNS_OPER_VAL,
|
169
|
+
"xmlns:#{XMLNS_DAT}" => XMLNS_DAT_VAL,
|
170
|
+
"xmlns:#{XMLNS_CRED}" => XMLNS_CRED_VAL
|
171
|
+
},
|
172
|
+
wsdl: wsdl_path,
|
173
|
+
headers: auth_header,
|
174
|
+
convert_request_keys_to: :none,
|
175
|
+
adapter: :excon
|
176
|
+
}
|
177
|
+
Savon.client(options.merge(@savon_opts))
|
178
|
+
end
|
179
|
+
|
180
|
+
def wsdl_path
|
181
|
+
root_dir = File.join(File.dirname(__FILE__), '..', '..')
|
182
|
+
File.join(root_dir, 'data', "creditsafe-live.xml")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|