creditsafe_connect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +69 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +96 -0
  9. data/README.md +57 -0
  10. data/Rakefile +4 -0
  11. data/bin/console +13 -0
  12. data/bin/setup +8 -0
  13. data/creditsafe_connect.gemspec +38 -0
  14. data/lib/creditsafe.rb +23 -0
  15. data/lib/creditsafe/authenticate.rb +41 -0
  16. data/lib/creditsafe/base_model.rb +104 -0
  17. data/lib/creditsafe/camelizer_lower.rb +14 -0
  18. data/lib/creditsafe/client.rb +57 -0
  19. data/lib/creditsafe/configuration.rb +15 -0
  20. data/lib/creditsafe/errors.rb +9 -0
  21. data/lib/creditsafe/faraday_auth.rb +51 -0
  22. data/lib/creditsafe/models/activity.rb +11 -0
  23. data/lib/creditsafe/models/activity_classification.rb +18 -0
  24. data/lib/creditsafe/models/address.rb +16 -0
  25. data/lib/creditsafe/models/basic_information.rb +26 -0
  26. data/lib/creditsafe/models/company.rb +21 -0
  27. data/lib/creditsafe/models/company_identification.rb +21 -0
  28. data/lib/creditsafe/models/company_status.rb +11 -0
  29. data/lib/creditsafe/models/company_summary.rb +27 -0
  30. data/lib/creditsafe/models/contact_information.rb +21 -0
  31. data/lib/creditsafe/models/credit_rating.rb +21 -0
  32. data/lib/creditsafe/models/credit_report.rb +30 -0
  33. data/lib/creditsafe/models/credit_score.rb +22 -0
  34. data/lib/creditsafe/models/currency_value.rb +11 -0
  35. data/lib/creditsafe/models/legal_form.rb +11 -0
  36. data/lib/creditsafe/models/main_activity.rb +11 -0
  37. data/lib/creditsafe/models/provider_value.rb +11 -0
  38. data/lib/creditsafe/models/report.rb +32 -0
  39. data/lib/creditsafe/models/search.rb +41 -0
  40. data/lib/creditsafe/version.rb +5 -0
  41. data/lib/creditsafe_connect.rb +3 -0
  42. metadata +238 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 30a7000d4f2f571913e8a2336515469991d7070f197144f057bd90d61e423006
4
+ data.tar.gz: d7cafce50a0daf972686fc63a7da3f63abe5ba1330d39291c9749f0564638ae1
5
+ SHA512:
6
+ metadata.gz: cc424d4b9e666162cbb192ab2f1a5e52484ab1586731f4ce57e87a28862bc878565b88436df43eaf4dec70623948521f60bcde06ec2e2cbe413fa5ab8ed4a5bb
7
+ data.tar.gz: 355eb6e3701ae39e548d3c6d97c521f4ce932a0ca893e1014b17956e39dcc7f6cc976c07d804225f5ceb24fd910d7ba29b54a12061e63597e3456fb2cc0474bd
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.env
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,69 @@
1
+ require: rubocop-rspec
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5.1
5
+
6
+ # Don't force top level comments in every class
7
+ Style/Documentation:
8
+ Enabled: false
9
+
10
+ # A good line length is 100 chars
11
+ Layout/LineLength:
12
+ Max: 100
13
+ AllowURI: true
14
+
15
+ Metrics/BlockLength:
16
+ Enabled: false
17
+
18
+ Metrics/ClassLength:
19
+ Max: 300
20
+
21
+ Metrics/MethodLength:
22
+ Max: 20
23
+
24
+ Metrics/AbcSize:
25
+ Max: 30
26
+
27
+ RSpec/ExampleLength:
28
+ Enabled: false
29
+
30
+ RSpec/MultipleExpectations:
31
+ Max: 10
32
+
33
+ RSpec/RepeatedExample:
34
+ Exclude:
35
+ - 'spec/policies/**/*'
36
+
37
+ RSpec/RepeatedDescription:
38
+ Exclude:
39
+ - 'spec/policies/**/*'
40
+
41
+ Layout/EmptyLinesAroundAttributeAccessor:
42
+ Enabled: true
43
+ Layout/SpaceAroundMethodCallOperator:
44
+ Enabled: true
45
+ Lint/DeprecatedOpenSSLConstant:
46
+ Enabled: true
47
+ Lint/MixedRegexpCaptureTypes:
48
+ Enabled: true
49
+ Lint/RaiseException:
50
+ Enabled: true
51
+ Lint/StructNewOverride:
52
+ Enabled: true
53
+ Style/ExponentialNotation:
54
+ Enabled: true
55
+ Style/HashEachMethods:
56
+ Enabled: true
57
+ Style/HashTransformKeys:
58
+ Enabled: true
59
+ Style/HashTransformValues:
60
+ Enabled: true
61
+ Style/RedundantFetchBlock:
62
+ Enabled: true
63
+ Style/RedundantRegexpCharacterClass:
64
+ Enabled: true
65
+ Style/RedundantRegexpEscape:
66
+ Enabled: true
67
+ Style/SlicingWithRange:
68
+ Enabled: true
69
+
@@ -0,0 +1 @@
1
+ finpoint-app
@@ -0,0 +1 @@
1
+ 2.5.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in creditsafe.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 12.0'
@@ -0,0 +1,96 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ creditsafe_connect (0.1.0)
5
+ faraday (~> 0.15)
6
+ faraday_middleware (~> 0.12)
7
+ faraday_middleware-multi_json (~> 0.0.6)
8
+ multi_json (~> 1.13)
9
+ rainbow (~> 3.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.7.0)
15
+ public_suffix (>= 2.0.2, < 5.0)
16
+ ast (2.4.1)
17
+ byebug (11.1.3)
18
+ coderay (1.1.3)
19
+ crack (0.4.3)
20
+ safe_yaml (~> 1.0.0)
21
+ diff-lcs (1.4.4)
22
+ faraday (0.17.3)
23
+ multipart-post (>= 1.2, < 3)
24
+ faraday_middleware (0.14.0)
25
+ faraday (>= 0.7.4, < 1.0)
26
+ faraday_middleware-multi_json (0.0.6)
27
+ faraday_middleware
28
+ multi_json
29
+ hashdiff (1.0.1)
30
+ method_source (1.0.0)
31
+ multi_json (1.15.0)
32
+ multipart-post (2.1.1)
33
+ parallel (1.19.2)
34
+ parser (2.7.1.4)
35
+ ast (~> 2.4.1)
36
+ pry (0.13.1)
37
+ coderay (~> 1.1)
38
+ method_source (~> 1.0)
39
+ pry-byebug (3.9.0)
40
+ byebug (~> 11.0)
41
+ pry (~> 0.13.0)
42
+ public_suffix (4.0.5)
43
+ rainbow (3.0.0)
44
+ rake (12.3.3)
45
+ regexp_parser (1.7.1)
46
+ rexml (3.2.4)
47
+ rspec (3.9.0)
48
+ rspec-core (~> 3.9.0)
49
+ rspec-expectations (~> 3.9.0)
50
+ rspec-mocks (~> 3.9.0)
51
+ rspec-core (3.9.2)
52
+ rspec-support (~> 3.9.3)
53
+ rspec-expectations (3.9.2)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.9.0)
56
+ rspec-mocks (3.9.1)
57
+ diff-lcs (>= 1.2.0, < 2.0)
58
+ rspec-support (~> 3.9.0)
59
+ rspec-support (3.9.3)
60
+ rubocop (0.86.0)
61
+ parallel (~> 1.10)
62
+ parser (>= 2.7.0.1)
63
+ rainbow (>= 2.2.2, < 4.0)
64
+ regexp_parser (>= 1.7)
65
+ rexml
66
+ rubocop-ast (>= 0.0.3, < 1.0)
67
+ ruby-progressbar (~> 1.7)
68
+ unicode-display_width (>= 1.4.0, < 2.0)
69
+ rubocop-ast (0.1.0)
70
+ parser (>= 2.7.0.1)
71
+ rubocop-rspec (1.41.0)
72
+ rubocop (>= 0.68.1)
73
+ ruby-progressbar (1.10.1)
74
+ safe_yaml (1.0.5)
75
+ unicode-display_width (1.7.0)
76
+ vcr (4.0.0)
77
+ webmock (3.7.6)
78
+ addressable (>= 2.3.6)
79
+ crack (>= 0.3.2)
80
+ hashdiff (>= 0.4.0, < 2.0.0)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ creditsafe_connect!
87
+ pry-byebug (~> 3.6)
88
+ rake (~> 12.0)
89
+ rspec (~> 3.0)
90
+ rubocop (~> 0.58)
91
+ rubocop-rspec (~> 1.27)
92
+ vcr (~> 4.0.0)
93
+ webmock (~> 3.7.2)
94
+
95
+ BUNDLED WITH
96
+ 2.1.4
@@ -0,0 +1,57 @@
1
+ # Creditsafe Connect
2
+
3
+ Creditsafe Connect API Wrapper
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'creditsafe_connect'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install creditsafe_connect
20
+
21
+ ## Usage
22
+
23
+ Configure credentials using `Creditsafe.configure` block
24
+
25
+ ```
26
+ Creditsafe.configure do |config|
27
+ config.debug = ENV['CREDITSAFE_DEBUG'].present?
28
+ config.username = ENV['CREDITSAFE_USERNAME']
29
+ config.password = ENV['CREDITSAFE_PASSWORD']
30
+ end
31
+ ```
32
+
33
+ Search for companies:
34
+ ```
35
+ # by company number
36
+ Creditsafe::Models::Search.find(NUMBER)
37
+
38
+ # by any other criteria
39
+ # e.g. name
40
+ Creditsafe::Models::Search.where(name: COMPANY_NAME, pageSize: 25)
41
+ ```
42
+
43
+ Report for company, by company ID:
44
+ ```
45
+ Creditsafe::Models::CreditReport.for(COMPANY_ID)
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/finpoint/creditsafe_connect.
57
+
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'creditsafe'
6
+ require 'json'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ require 'pry'
13
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/creditsafe/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'creditsafe_connect'
7
+ spec.version = Creditsafe::VERSION
8
+ spec.authors = ['Nenad Petronijevic']
9
+ spec.email = ['nenad@finpoint.co.uk']
10
+
11
+ spec.summary = 'Creditsafe Connect API Wrapper'
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://gitlab.com/finpoint/creditsafe_connect'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+ spec.license = 'MIT'
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_dependency 'faraday', '~> 0.15'
27
+ spec.add_dependency 'faraday_middleware', '~> 0.12'
28
+ spec.add_dependency 'faraday_middleware-multi_json', '~> 0.0.6'
29
+ spec.add_dependency 'multi_json', '~> 1.13'
30
+ spec.add_dependency 'rainbow', '~> 3.0'
31
+
32
+ spec.add_development_dependency 'pry-byebug', '~> 3.6'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+ spec.add_development_dependency 'rubocop', '~> 0.58'
35
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.27'
36
+ spec.add_development_dependency 'vcr', '~> 4.0.0'
37
+ spec.add_development_dependency 'webmock', '~> 3.7.2'
38
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/version'
4
+ require 'creditsafe/configuration'
5
+ require 'creditsafe/client'
6
+ require 'creditsafe/models/search'
7
+ require 'creditsafe/models/credit_report'
8
+
9
+ module Creditsafe
10
+ module_function
11
+
12
+ def configure
13
+ yield(configuration)
14
+ end
15
+
16
+ def client
17
+ @client ||= Client.new
18
+ end
19
+
20
+ def configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/client'
4
+ require 'creditsafe/errors'
5
+ require 'creditsafe/version'
6
+
7
+ module Creditsafe
8
+ class Authenticate
9
+ def call(username, password)
10
+ response = post('authenticate', username: username, password: password)
11
+
12
+ if response.success?
13
+ response.body[:token]
14
+ elsif response.status == 401
15
+ raise UnauthorizedError, response.body
16
+ else
17
+ raise GenericError, response.body
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def post(path, params = {})
24
+ connection.post(path, MultiJson.dump(params))
25
+ end
26
+
27
+ def connection
28
+ api_url = Client.new.api_url
29
+
30
+ @connection ||= Faraday.new(url: api_url) do |conn|
31
+ conn.headers.merge!(
32
+ content_type: 'application/json',
33
+ user_agent: "finpoint/#{Creditsafe::VERSION}"
34
+ )
35
+ conn.response :multi_json, symbolize_keys: true
36
+ conn.response :logger if Creditsafe.configuration.debug
37
+ conn.adapter Faraday.default_adapter
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/errors'
4
+ require 'creditsafe/camelizer_lower'
5
+
6
+ module Creditsafe
7
+ class BaseModel
8
+ class << self
9
+ def get(path, params = {})
10
+ result = Creditsafe.client.get(path.strip, params)
11
+
12
+ raise APIKeyError, result.body[:error] if result.status == 401
13
+
14
+ result
15
+ end
16
+
17
+ def post(path, params = {})
18
+ result = Creditsafe.client.post(path.strip, params)
19
+
20
+ raise APIKeyError, result.body[:error] if result.status == 401
21
+
22
+ result
23
+ end
24
+
25
+ def attributes(*attributes)
26
+ @attributes ||= []
27
+
28
+ return @attributes unless attributes
29
+
30
+ attr_accessor(*attributes)
31
+
32
+ @attributes += attributes
33
+ end
34
+
35
+ def attribute_aliases(aliases = nil)
36
+ @attribute_aliases ||= {}
37
+
38
+ return @attribute_aliases unless aliases
39
+
40
+ @attribute_aliases.merge!(aliases)
41
+ end
42
+
43
+ def format_url(url, params)
44
+ formatted = url.dup.strip
45
+
46
+ params.each { |key, value| formatted.sub!(":#{key}", value) }
47
+
48
+ formatted
49
+ end
50
+
51
+ def successful_response?(result)
52
+ result.status < 400
53
+ end
54
+
55
+ def key_transformer
56
+ CamelizerLower
57
+ end
58
+
59
+ # Sets all the instance variables by reading the JSON from Creditsafe and converting the keys from
60
+ # camelCase to snake_case, as it's the standard in Ruby.
61
+ def build(json: {}, key_transformer: self.key_transformer)
62
+ new.tap do |record|
63
+ attributes.each do |attr|
64
+ key = attribute_aliases.key?(attr) ? attribute_aliases[attr] : attr
65
+ record.public_send("#{attr}=", json[key_transformer.transform(key)])
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ def initialize(attributes = {})
72
+ attributes.each do |attr, value|
73
+ public_send("#{attr}=", value)
74
+ end
75
+ end
76
+
77
+ def get(path, params = {})
78
+ self.class.get(path, params)
79
+ end
80
+
81
+ def post(path, params = {})
82
+ self.class.post(path, params)
83
+ end
84
+
85
+ def format_url(url, params)
86
+ self.class.format_url(url, params)
87
+ end
88
+
89
+ def as_json
90
+ self.class.attributes.each_with_object({}) do |attr, hash|
91
+ value = public_send(attr)
92
+
93
+ value = value.as_json if value.respond_to?(:as_json)
94
+ if value.is_a?(Array)
95
+ value = value.map { |v| v.respond_to?(:as_json) ? v.as_json : v }
96
+ end
97
+
98
+ key = self.class.key_transformer.transform(attr)
99
+
100
+ hash[key] = value
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ class CamelizerLower
5
+ # Converts this_is_my_string to thisIsMyString and returns it as a symbol.
6
+ def self.transform(underscore_string)
7
+ parts = underscore_string.to_s.split('_')
8
+
9
+ rest = parts[1..-1].map(&:capitalize)
10
+
11
+ rest.unshift(parts[0]).join.to_sym
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'faraday_middleware/multi_json'
5
+ require 'creditsafe/configuration'
6
+ require 'creditsafe/faraday_auth'
7
+
8
+ module Creditsafe
9
+ class Client
10
+ BASE_URLS = {
11
+ production: 'https://connect.creditsafe.com/v1/',
12
+ sandbox: 'https://connect.sandbox.creditsafe.com/v1/'
13
+ }.freeze
14
+
15
+ def initialize
16
+ Faraday::Request.register_middleware creditsafe_auth: -> { Creditsafe::FaradayAuth }
17
+ end
18
+
19
+ def get(path, params = {})
20
+ connection.get(path, params).tap do |response|
21
+ handle_response(response)
22
+ end
23
+ end
24
+
25
+ def post(path, params = {})
26
+ connection.post(path, MultiJson.dump(params)).tap do |response|
27
+ handle_response(response)
28
+ end
29
+ end
30
+
31
+ def connection
32
+ @connection ||= Faraday.new(url: api_url) do |conn|
33
+ conn.request :creditsafe_auth, Creditsafe.configuration.username, Creditsafe.configuration.password
34
+ conn.response :multi_json, symbolize_keys: true
35
+ conn.response :logger if Creditsafe.configuration.debug
36
+ conn.adapter Faraday.default_adapter
37
+ end
38
+ end
39
+
40
+ def api_url
41
+ BASE_URLS.dig(Creditsafe.configuration.environment.to_sym)
42
+ end
43
+
44
+ def handle_response(response)
45
+ return if response.success?
46
+
47
+ case response.status
48
+ when 401
49
+ raise UnauthorizedError, response.body
50
+ when 400
51
+ raise InvalidRequestError, response.body
52
+ else
53
+ raise GenericError, response.body
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ class Configuration
5
+ attr_accessor :username, :password, :environment, :debug, :countries
6
+
7
+ def initialize
8
+ @username = ''
9
+ @password = ''
10
+ @environment = :sandbox # can be either :sandbox or :production
11
+ @debug = false
12
+ @countries = %w[GB]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ class UnauthorizedError < StandardError; end
5
+
6
+ class GenericError < StandardError; end
7
+
8
+ class InvalidRequestError < StandardError; end
9
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/authenticate'
4
+ require 'creditsafe/version'
5
+ require 'creditsafe/errors'
6
+
7
+ module Creditsafe
8
+ class FaradayAuth < Faraday::Middleware
9
+ def initialize(app, username, password, options = {})
10
+ super(app)
11
+ @username = username
12
+ @password = password
13
+ @token = nil
14
+ @options = options
15
+ end
16
+
17
+ def call(env)
18
+ retry_count = 0
19
+
20
+ authenticate! unless @token
21
+
22
+ begin
23
+ env[:request_headers]['Authorization'] = @token
24
+ env[:request_headers]['Content-Type'] = 'application/json'
25
+ env[:request_headers]['User-Agent'] = "finpoint/#{Creditsafe::VERSION}"
26
+
27
+ @app.call(env).tap do |resp|
28
+ if resp.status == 401
29
+ raise Creditsafe::UnauthorizedError, resp.body
30
+ end
31
+ end
32
+ rescue Creditsafe::UnauthorizedError => e
33
+ retry_count += 1
34
+
35
+ if retry_count <= 1
36
+ authenticate!
37
+
38
+ retry
39
+ else
40
+ raise e
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def authenticate!
48
+ @token = Authenticate.new.call(@username, @password)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class Activity < BaseModel
8
+ attributes :code, :description
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/activity'
5
+
6
+ module Creditsafe
7
+ module Models
8
+ class ActivityClassification < BaseModel
9
+ attributes :classification, :activities
10
+
11
+ def self.build(json:)
12
+ super.tap do |record|
13
+ record.activities = json.fetch(:activities, []).map { |act| Activity.build(json: act) }
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class Address < BaseModel
8
+ attributes :type, :simple_value, :street, :house_number,
9
+ :city, :postal_code, :province, :telephone, :direct_marketing_opt_out
10
+
11
+ def line_1
12
+ [street, house_number].compact.join(' ')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/legal_form'
5
+ require 'creditsafe/models/company_status'
6
+ require 'creditsafe/models/main_activity'
7
+ require 'creditsafe/models/address'
8
+
9
+ module Creditsafe
10
+ module Models
11
+ class BasicInformation < BaseModel
12
+ attributes :business_name, :registered_company_name, :company_registration_number,
13
+ :country, :vat_registration_number, :company_registration_date, :legal_form,
14
+ :company_status, :principal_activity, :contact_address
15
+
16
+ def self.build(json:)
17
+ super.tap do |record|
18
+ record.legal_form = LegalForm.build(json: json.fetch(:legalForm, {}))
19
+ record.company_status = CompanyStatus.build(json: json.fetch(:companyStatus, {}))
20
+ record.principal_activity = MainActivity.build(json: json.fetch(:principalActivity, {}))
21
+ record.contact_address = Address.build(json: json.fetch(:contactAddress, {}))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/address'
5
+
6
+ module Creditsafe
7
+ module Models
8
+ class Company < BaseModel
9
+ attributes :id, :address, :country, :reg_no, :vat_no, :safe_no,
10
+ :name, :status, :type,
11
+ :date_of_latest_accounts, :date_of_latest_change,
12
+ :activity_code, :status_description
13
+
14
+ def self.build(json:)
15
+ super.tap do |record|
16
+ record.address = Address.build(json: json.fetch(:address, {}))
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/basic_information'
5
+ require 'creditsafe/models/activity_classification'
6
+
7
+ module Creditsafe
8
+ module Models
9
+ class CompanyIdentification < BaseModel
10
+ attributes :basic_information, :activity_classifications
11
+
12
+ def self.build(json:)
13
+ super.tap do |record|
14
+ record.basic_information = BasicInformation.build(json: json.fetch(:basicInformation, {}))
15
+ record.activity_classifications = json.fetch(:activityClassifications, [])
16
+ .map { |ac| ActivityClassification.build(json: ac) }
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class CompanyStatus < BaseModel
8
+ attributes :status, :description
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/main_activity'
5
+ require 'creditsafe/models/company_status'
6
+ require 'creditsafe/models/currency_value'
7
+ require 'creditsafe/models/credit_rating'
8
+
9
+ module Creditsafe
10
+ module Models
11
+ class CompanySummary < BaseModel
12
+ attributes :business_name, :country, :company_number, :company_registration_number,
13
+ :main_activity, :company_status, :latest_shareholders_equity_figure, :credit_rating
14
+
15
+ def self.build(json:)
16
+ super.tap do |record|
17
+ record.main_activity = MainActivity.build(json: json.fetch(:mainActivity, {}))
18
+ record.company_status = CompanyStatus.build(json: json.fetch(:companyStatus, {}))
19
+ record.latest_shareholders_equity_figure = CurrencyValue.build(
20
+ json: json.fetch(:latestShareholdersEquityFigure, {})
21
+ )
22
+ record.credit_rating = CreditRating.build(json: json.fetch(:creditRating, {}))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/address'
5
+
6
+ module Creditsafe
7
+ module Models
8
+ class ContactInformation < BaseModel
9
+ attributes :main_address, :other_addresses
10
+
11
+ def self.build(json:)
12
+ super.tap do |record|
13
+ record.main_address = Address.build(json: json.fetch(:mainAddress, {}))
14
+ record.other_addresses = json.fetch(:otherAddresses, []).map do |addr|
15
+ Address.build(json: addr)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/currency_value'
5
+ require 'creditsafe/models/provider_value'
6
+
7
+ module Creditsafe
8
+ module Models
9
+ class CreditRating < BaseModel
10
+ attributes :common_value, :common_description, :credit_limit,
11
+ :provider_value, :provider_description
12
+
13
+ def self.build(json:)
14
+ super.tap do |record|
15
+ record.credit_limit = CurrencyValue.build(json: json.fetch(:creditLimit, {}))
16
+ record.provider_value = ProviderValue.build(json: json.fetch(:providerValue, {}))
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/report'
5
+
6
+ module Creditsafe
7
+ module Models
8
+ class CreditReport < BaseModel
9
+ ENDPOINT = 'companies/:connect_id'
10
+
11
+ attributes :report, :company_id, :user_id, :date_of_order, :language
12
+
13
+ def self.for(company_id)
14
+ url = format_url(ENDPOINT, connect_id: company_id.to_s.strip)
15
+
16
+ result = get(url)
17
+
18
+ build(json: result.body)
19
+ rescue InvalidRequestError
20
+ build(json: {})
21
+ end
22
+
23
+ def self.build(json:)
24
+ super.tap do |record|
25
+ record.report = Report.build(json: json[:report]) if json.key?(:report)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/credit_rating'
5
+ require 'creditsafe/models/currency_value'
6
+
7
+ module Creditsafe
8
+ module Models
9
+ class CreditScore < BaseModel
10
+ attributes :current_credit_rating, :current_contract_limit,
11
+ :previous_credit_rating, :latest_rating_change_date
12
+
13
+ def self.build(json:)
14
+ super.tap do |record|
15
+ record.current_credit_rating = CreditRating.build(json: json.fetch(:currentCreditRating, {}))
16
+ record.current_contract_limit = CurrencyValue.build(json: json.fetch(:currentContractLimit, {}))
17
+ record.previous_credit_rating = CreditRating.build(json: json.fetch(:previousCreditRating, {}))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class CurrencyValue < BaseModel
8
+ attributes :currency, :value
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class LegalForm < BaseModel
8
+ attributes :description
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class MainActivity < BaseModel
8
+ attributes :code, :description, :classification
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+
5
+ module Creditsafe
6
+ module Models
7
+ class ProviderValue < BaseModel
8
+ attributes :max_value, :min_value, :value
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/company_summary'
5
+ require 'creditsafe/models/company_identification'
6
+ require 'creditsafe/models/credit_score'
7
+ require 'creditsafe/models/contact_information'
8
+
9
+ module Creditsafe
10
+ module Models
11
+ class Report < BaseModel
12
+ attributes :company_id, :language,
13
+ :company_summary, :company_identification, :credit_score,
14
+ :contact_information,
15
+ :share_capital_structure, :directors, :directorships,
16
+ :financial_statements, :local_financial_statements,
17
+ :payment_data, :payment_data_extra,
18
+ :negative_information, :additional_information
19
+
20
+ def self.build(json:)
21
+ super.tap do |record|
22
+ record.company_summary = CompanySummary.build(json: json.fetch(:companySummary, {}))
23
+ record.company_identification = CompanyIdentification.build(
24
+ json: json.fetch(:companyIdentification, {})
25
+ )
26
+ record.credit_score = CreditScore.build(json: json.fetch(:creditScore, {}))
27
+ record.contact_information = ContactInformation.build(json: json.fetch(:contactInformation, {}))
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe/base_model'
4
+ require 'creditsafe/models/company'
5
+
6
+ module Creditsafe
7
+ module Models
8
+ class Search < BaseModel
9
+ ENDPOINT = 'companies'
10
+
11
+ attributes :companies
12
+
13
+ def self.find(reg_no, countries = Creditsafe.configuration.countries)
14
+ result = get(ENDPOINT, regNo: reg_no, countries: countries.join(','))
15
+
16
+ return nil unless successful_response?(result)
17
+
18
+ build(json: result.body)
19
+ end
20
+
21
+ def self.where(params = {})
22
+ unless params.key?(:countries)
23
+ countries = Creditsafe.configuration.countries
24
+ params = params.merge(countries: countries.join(','))
25
+ end
26
+
27
+ result = get(ENDPOINT, params)
28
+
29
+ return nil unless successful_response?(result)
30
+
31
+ build(json: result.body)
32
+ end
33
+
34
+ def self.build(json:)
35
+ super.tap do |record|
36
+ record.companies = json.fetch(:companies, []).map { |c| Company.build(json: c) }
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Creditsafe
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'creditsafe'
metadata ADDED
@@ -0,0 +1,238 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: creditsafe_connect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nenad Petronijevic
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.15'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware-multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.6
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.13'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.13'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rainbow
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.58'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.58'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.27'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.27'
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 4.0.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 4.0.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 3.7.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 3.7.2
167
+ description: Creditsafe Connect API Wrapper
168
+ email:
169
+ - nenad@finpoint.co.uk
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - ".ruby-gemset"
178
+ - ".ruby-version"
179
+ - Gemfile
180
+ - Gemfile.lock
181
+ - README.md
182
+ - Rakefile
183
+ - bin/console
184
+ - bin/setup
185
+ - creditsafe_connect.gemspec
186
+ - lib/creditsafe.rb
187
+ - lib/creditsafe/authenticate.rb
188
+ - lib/creditsafe/base_model.rb
189
+ - lib/creditsafe/camelizer_lower.rb
190
+ - lib/creditsafe/client.rb
191
+ - lib/creditsafe/configuration.rb
192
+ - lib/creditsafe/errors.rb
193
+ - lib/creditsafe/faraday_auth.rb
194
+ - lib/creditsafe/models/activity.rb
195
+ - lib/creditsafe/models/activity_classification.rb
196
+ - lib/creditsafe/models/address.rb
197
+ - lib/creditsafe/models/basic_information.rb
198
+ - lib/creditsafe/models/company.rb
199
+ - lib/creditsafe/models/company_identification.rb
200
+ - lib/creditsafe/models/company_status.rb
201
+ - lib/creditsafe/models/company_summary.rb
202
+ - lib/creditsafe/models/contact_information.rb
203
+ - lib/creditsafe/models/credit_rating.rb
204
+ - lib/creditsafe/models/credit_report.rb
205
+ - lib/creditsafe/models/credit_score.rb
206
+ - lib/creditsafe/models/currency_value.rb
207
+ - lib/creditsafe/models/legal_form.rb
208
+ - lib/creditsafe/models/main_activity.rb
209
+ - lib/creditsafe/models/provider_value.rb
210
+ - lib/creditsafe/models/report.rb
211
+ - lib/creditsafe/models/search.rb
212
+ - lib/creditsafe/version.rb
213
+ - lib/creditsafe_connect.rb
214
+ homepage: https://gitlab.com/finpoint/creditsafe_connect
215
+ licenses:
216
+ - MIT
217
+ metadata: {}
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: 2.3.0
227
+ required_rubygems_version: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '0'
232
+ requirements: []
233
+ rubyforge_project:
234
+ rubygems_version: 2.7.6
235
+ signing_key:
236
+ specification_version: 4
237
+ summary: Creditsafe Connect API Wrapper
238
+ test_files: []