ruby-experian 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0e0371a986bd95bab1599a0f614435a49f5dbeffd31f697b3c4c16f0fef69abe
4
+ data.tar.gz: 0d77ee8c6e4f27391c377fecb9e4d65fb2655c41fd788852060a78aab0652c55
5
+ SHA512:
6
+ metadata.gz: 4a652cd2104b641d78efddf0c838b7544949eeedf013d33fec6f7737af5a9c0d0014e68c1f97024eff464745fa08d85e765b3570b5c9e3c4f079920cab0cbe00
7
+ data.tar.gz: 011dc686d3221ec58536df841b04a7d3f80595cb87f88e64dacbe62706d1989cd1be556d7d460d15af2cb3218348756f10d55a367a82090ca8bf3242fd0c230e
@@ -0,0 +1,15 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: daily
7
+ open-pull-requests-limit: 10
8
+ ignore:
9
+ - dependency-name: webmock
10
+ versions:
11
+ - 3.11.1
12
+ - 3.11.3
13
+ - dependency-name: rspec
14
+ versions:
15
+ - 3.10.0
@@ -0,0 +1,5 @@
1
+ ## All Submissions:
2
+
3
+ - [ ] Have you followed the guidelines in our [Contributing document](../blob/main/CONTRIBUTING.md)?
4
+ - [ ] Have you checked to ensure there aren't other open [Pull Requests](../pulls) for the same update/change?
5
+ - [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
@@ -0,0 +1,44 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ test:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - name: Checkout repository
20
+ uses: actions/checkout@v2
21
+
22
+ - name: Install Ruby version specified in `.ruby-version`
23
+ uses: eregon/use-ruby-action@master # this will use by default the .ruby-version file in your repository
24
+
25
+ - name: Install required apt packages
26
+ run: |
27
+ sudo apt-get -y install libpq-dev
28
+
29
+ - name: Bundle install
30
+ run: |
31
+ bundle config path vendor/bundle
32
+ bundle install
33
+
34
+ - name: Rspec tests
35
+ run: bundle exec rspec
36
+ env:
37
+ COVERAGE_DIR: coverage
38
+
39
+ - name: Upload to Codecov
40
+ uses: codecov/codecov-action@v4-beta
41
+ env:
42
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
43
+ with:
44
+ file: coverage/coverage.xml
data/.gitignore ADDED
@@ -0,0 +1,74 @@
1
+ ### Ruby ###
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/examples.txt
10
+ /test/tmp/
11
+ /test/version_tmp/
12
+ /tmp/
13
+ /.bundle/
14
+ /.yardoc
15
+ /_yardoc/
16
+ /doc/
17
+
18
+
19
+ # Used by dotenv library to load environment variables.
20
+ .env
21
+
22
+ # Ignore Byebug command history file.
23
+ .byebug_history
24
+
25
+ ## Specific to RubyMotion:
26
+ .dat*
27
+ .repl_history
28
+ build/
29
+ *.bridgesupport
30
+ build-iPhoneOS/
31
+ build-iPhoneSimulator/
32
+
33
+ ## Specific to RubyMotion (use of CocoaPods):
34
+ #
35
+ # We recommend against adding the Pods directory to your .gitignore. However
36
+ # you should judge for yourself, the pros and cons are mentioned at:
37
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
38
+ # vendor/Pods/
39
+
40
+ ## Documentation cache and generated files:
41
+ /.yardoc/
42
+ /_yardoc/
43
+ /doc/
44
+ /rdoc/
45
+
46
+ ## Environment normalization:
47
+ /.bundle/
48
+ /vendor/bundle
49
+ /lib/bundler/man/
50
+
51
+ # for a library or gem, you might want to ignore these files since the code is
52
+ # intended to run in multiple environments; otherwise, check them in:
53
+ # Gemfile.lock
54
+ # .ruby-version
55
+ # .ruby-gemset
56
+
57
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
58
+ .rvmrc
59
+
60
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
61
+ # .rubocop-https?--*
62
+
63
+ # rspec failure tracking
64
+ .rspec_status
65
+
66
+ # IDE
67
+ .idea
68
+ .idea/
69
+ .idea/*
70
+ .vscode
71
+ .vs/
72
+
73
+ # Mac
74
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/Documentation:
7
+ # Skips checking to make sure top level modules / classes have a comment.
8
+ Enabled: false
9
+
10
+ Layout/LineLength:
11
+ Max: 100
12
+ Exclude:
13
+ - "**/*.gemspec"
14
+
15
+ Lint/AmbiguousOperator:
16
+ # https://github.com/rubocop/rubocop/issues/4294
17
+ Exclude:
18
+ - "lib/experian/client.rb"
19
+
20
+ Metrics/AbcSize:
21
+ Max: 20
22
+
23
+ Metrics/BlockLength:
24
+ Exclude:
25
+ - "spec/**/*"
26
+
27
+ Style/StringLiterals:
28
+ EnforcedStyle: double_quotes
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ - Using welcoming and inclusive language
18
+ - Being respectful of differing viewpoints and experiences
19
+ - Gracefully accepting constructive criticism
20
+ - Focusing on what is best for the community
21
+ - Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ - The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ - Trolling, insulting/derogatory comments, and personal or political attacks
28
+ - Public or private harassment
29
+ - Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ - Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alexrudall@users.noreply.github.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,3 @@
1
+ ## Contributing
2
+
3
+ Bug reports and pull requests are welcome on GitHub at https://github.com/moraki/ruby-experian. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alexrudall/ruby-experian/blob/main/CODE_OF_CONDUCT.md).
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Include gem dependencies from ruby-experian.gemspec
4
+ gemspec
5
+
6
+ gem "dotenv", "~> 2.8.1"
7
+ gem "rake", "~> 13.1"
8
+ gem "rspec", "~> 3.12"
9
+ gem "rubocop", "~> 1.50.2"
10
+ gem "vcr", "~> 6.1.0"
11
+ gem "webmock", "~> 3.19.1"
12
+ gem "sha3"
13
+ gem "rexml", '~> 3.2'
14
+ gem "multi_xml", '~> 0.6.0'
15
+
16
+ group :development, :test do
17
+ gem "byebug", "~> 11.1"
18
+ gem "pry", "~> 0.14.2"
19
+ gem "pry-byebug", "~> 3.10"
20
+ gem "pry-rescue", "~> 1.5"
21
+ gem "pry-stack_explorer", "~> 0.6.1"
22
+ end
23
+
24
+ group :test do
25
+ gem "simplecov"
26
+ gem "simplecov-cobertura"
27
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,124 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-experian (0.0.1)
5
+ faraday (>= 1)
6
+ faraday_middleware (>= 1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.8.6)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ ast (2.4.2)
14
+ binding_of_caller (1.0.0)
15
+ debug_inspector (>= 0.0.1)
16
+ byebug (11.1.3)
17
+ coderay (1.1.3)
18
+ crack (0.4.5)
19
+ rexml
20
+ debug_inspector (1.2.0)
21
+ diff-lcs (1.5.0)
22
+ docile (1.4.0)
23
+ dotenv (2.8.1)
24
+ faraday (1.2.0)
25
+ multipart-post (>= 1.2, < 3)
26
+ ruby2_keywords
27
+ faraday_middleware (1.2.0)
28
+ faraday (~> 1.0)
29
+ hashdiff (1.1.0)
30
+ interception (0.5)
31
+ json (2.7.1)
32
+ method_source (1.0.0)
33
+ multi_xml (0.6.0)
34
+ multipart-post (2.3.0)
35
+ parallel (1.24.0)
36
+ parser (3.2.2.4)
37
+ ast (~> 2.4.1)
38
+ racc
39
+ pry (0.14.2)
40
+ coderay (~> 1.1)
41
+ method_source (~> 1.0)
42
+ pry-byebug (3.10.1)
43
+ byebug (~> 11.0)
44
+ pry (>= 0.13, < 0.15)
45
+ pry-rescue (1.5.2)
46
+ interception (>= 0.5)
47
+ pry (>= 0.12.0)
48
+ pry-stack_explorer (0.6.1)
49
+ binding_of_caller (~> 1.0)
50
+ pry (~> 0.13)
51
+ public_suffix (5.0.4)
52
+ racc (1.7.3)
53
+ rainbow (3.1.1)
54
+ rake (13.1.0)
55
+ regexp_parser (2.8.3)
56
+ rexml (3.2.6)
57
+ rspec (3.12.0)
58
+ rspec-core (~> 3.12.0)
59
+ rspec-expectations (~> 3.12.0)
60
+ rspec-mocks (~> 3.12.0)
61
+ rspec-core (3.12.2)
62
+ rspec-support (~> 3.12.0)
63
+ rspec-expectations (3.12.3)
64
+ diff-lcs (>= 1.2.0, < 2.0)
65
+ rspec-support (~> 3.12.0)
66
+ rspec-mocks (3.12.6)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.12.0)
69
+ rspec-support (3.12.1)
70
+ rubocop (1.50.2)
71
+ json (~> 2.3)
72
+ parallel (~> 1.10)
73
+ parser (>= 3.2.0.0)
74
+ rainbow (>= 2.2.2, < 4.0)
75
+ regexp_parser (>= 1.8, < 3.0)
76
+ rexml (>= 3.2.5, < 4.0)
77
+ rubocop-ast (>= 1.28.0, < 2.0)
78
+ ruby-progressbar (~> 1.7)
79
+ unicode-display_width (>= 2.4.0, < 3.0)
80
+ rubocop-ast (1.30.0)
81
+ parser (>= 3.2.1.0)
82
+ ruby-progressbar (1.13.0)
83
+ ruby2_keywords (0.0.5)
84
+ sha3 (1.0.5)
85
+ simplecov (0.21.2)
86
+ docile (~> 1.1)
87
+ simplecov-html (~> 0.11)
88
+ simplecov_json_formatter (~> 0.1)
89
+ simplecov-cobertura (2.1.0)
90
+ rexml
91
+ simplecov (~> 0.19)
92
+ simplecov-html (0.12.3)
93
+ simplecov_json_formatter (0.1.4)
94
+ unicode-display_width (2.5.0)
95
+ vcr (6.1.0)
96
+ webmock (3.19.1)
97
+ addressable (>= 2.8.0)
98
+ crack (>= 0.3.2)
99
+ hashdiff (>= 0.4.0, < 2.0.0)
100
+
101
+ PLATFORMS
102
+ ruby
103
+
104
+ DEPENDENCIES
105
+ byebug (~> 11.1)
106
+ dotenv (~> 2.8.1)
107
+ multi_xml (~> 0.6.0)
108
+ pry (~> 0.14.2)
109
+ pry-byebug (~> 3.10)
110
+ pry-rescue (~> 1.5)
111
+ pry-stack_explorer (~> 0.6.1)
112
+ rake (~> 13.1)
113
+ rexml (~> 3.2)
114
+ rspec (~> 3.12)
115
+ rubocop (~> 1.50.2)
116
+ ruby-experian!
117
+ sha3
118
+ simplecov
119
+ simplecov-cobertura
120
+ vcr (~> 6.1.0)
121
+ webmock (~> 3.19.1)
122
+
123
+ BUNDLED WITH
124
+ 2.4.22
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # Ruby Experian
2
+
3
+ <a href="https://codecov.io/github/moraki-finance/ruby-experian" >
4
+ <img src="https://codecov.io/github/moraki-finance/ruby-experian/graph/badge.svg?token=SKTT14JJGV"/>
5
+ </a>
6
+
7
+ [![Tests](https://github.com/moraki-finance/ruby-experian/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/moraki-finance/ruby-experian/actions/workflows/tests.yml)
8
+
9
+ Use the [Experian Axesor Informe 360](<https://axesor.es/blog/openai-api/](https://www.axesor.es/informacion-empresas/informes/informe-axesor-360.aspx)https://www.axesor.es/informacion-empresas/informes/informe-axesor-360.aspx>) API with Ruby! 🩵
10
+
11
+ Allows you to get a detailed credit risk report for Spanish companies.
12
+
13
+ ### Bundler
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem "ruby-experian"
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```bash
24
+ $ bundle install
25
+ ```
26
+
27
+ ### Gem install
28
+
29
+ Or install with:
30
+
31
+ ```bash
32
+ $ gem install ruby-experian
33
+ ```
34
+
35
+ and require with:
36
+
37
+ ```ruby
38
+ require "experian"
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ - Get your user_code and password from [https://axesor.es](https://www.axesor.es/)
44
+
45
+ ### Quickstart
46
+
47
+ For a quick test you can pass your token directly to a new client:
48
+
49
+ ```ruby
50
+ client = Experian::Client.new(user_code: "user code goes here", password: "password goes here")
51
+ ```
52
+
53
+ ### With Config
54
+
55
+ For a more robust setup, you can configure the gem with your API keys, for example in an `experian.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
56
+
57
+ ```ruby
58
+ Experian.configure do |config|
59
+ config.user_code = ENV.fetch("EXPERIAN_USER_CODE")
60
+ config.password = ENV.fetch("EXPERIAN_PASSWORD")
61
+ end
62
+ ```
63
+
64
+ Then you can create a client like this:
65
+
66
+ ```ruby
67
+ client = Experian::Client.new
68
+ ```
69
+
70
+ You can still override the config defaults when making new clients; any options not included will fall back to any global config set with Experian.configure. e.g. in this example the base_uri, request_timeout, etc. will fallback to any set globally using Experian.configure, with only the access_token overridden:
71
+
72
+ ```ruby
73
+ client = Experian::Client.new(password: "some other password")
74
+ ```
75
+
76
+ #### Custom timeout or base URI
77
+
78
+ The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client. You can also change the base URI used for all requests, eg. to use observability tools like [Helicone](https://docs.helicone.ai/quickstart/integrate-in-one-line-of-code).
79
+
80
+ ```ruby
81
+ client = Experian::Client.new(
82
+ user_code: "user code goes here",
83
+ base_uri: "https://oai.hconeai.com/",
84
+ request_timeout: 240,
85
+ extra_headers: {
86
+ "Helicone-Auth": "Bearer HELICONE_API_KEY"
87
+ "helicone-stream-force-format" => "true",
88
+ }
89
+ )
90
+ ```
91
+
92
+ or when configuring the gem:
93
+
94
+ ```ruby
95
+ Experian.configure do |config|
96
+ config.user_code = ENV.fetch("EXPERIAN_USER_CODE")
97
+ config.password = ENV.fetch("EXPERIAN_PASSWORD")
98
+ config.base_uri = "https://oai.hconeai.com/" # Optional
99
+ config.request_timeout = 240 # Optional
100
+ config.extra_headers = {
101
+ "Helicone-Auth": "Bearer HELICONE_API_KEY"
102
+ } # Optional
103
+ end
104
+ ```
105
+
106
+ #### Extra Headers per Client
107
+
108
+ You can dynamically pass headers per client object, which will be merged with any headers set globally with Experian.configure:
109
+
110
+ ```ruby
111
+ client = Experian::Client.new(user_code: "code goes here", password: "password goes here")
112
+ client.add_headers("X-Proxy-TTL" => "43200")
113
+ ```
114
+
115
+ #### Verbose Logging
116
+
117
+ You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging with Ruby's [Logger](https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html):
118
+
119
+ ```ruby
120
+ client = Experian::Client.new do |f|
121
+ f.response :logger, Logger.new($stdout), bodies: true
122
+ end
123
+ ```
124
+
125
+ ### Report
126
+
127
+ You can hit the report api to get the 360 credit report from Experian by passing in a CIF to the call. Note that only some sections of the report are exposed. Other sections will be exposed as needed / requested.
128
+
129
+ The exposed sections for now are:
130
+
131
+ - id
132
+ - address
133
+ - rating
134
+ - number_of_employees
135
+
136
+ ```ruby
137
+ report = client.report(cif: "cif goes here")
138
+ report.rating.inspect
139
+ # => "#<OpenStruct score=8, default_probability=0.529, risk=\"Mínimo\", size=\"Grande\">"
140
+ ```
141
+
142
+ ## Development
143
+
144
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
145
+
146
+ To install this gem onto your local machine, run `bundle exec rake install`.
147
+
148
+ ### Warning
149
+
150
+ If you have an `EXPERIAN_USER_CODE` and `EXPERIAN_PASSWORD` in your `ENV`, running the specs will use this to run the specs against the actual API, which will be slow! Remove it from your environment with `unset` or similar if you just want to run the specs against the stored VCR responses.
151
+
152
+ ## Release
153
+
154
+ In order to release this gem, you'll need the `gem-release` gem globally installed:
155
+
156
+ ```bash
157
+ gem install gem-release
158
+ ```
159
+
160
+ Second, run the specs without VCR so they actually hit the API. Set `EXPERIAN_USER_CODE` and `EXPERIAN_PASSWORD` in your environment or pass it in like this:
161
+
162
+ ```
163
+ EXPERIAN_USER_CODE=code EXPERIAN_PASSWORD=password bundle exec rspec
164
+ ```
165
+
166
+ Then update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, 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).
167
+
168
+ ## Contributing
169
+
170
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/moraki-finance/ruby-experian>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/moraki-finance/ruby-experian/blob/main/CODE_OF_CONDUCT.md).
171
+
172
+ ## License
173
+
174
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
175
+
176
+ ## Code of Conduct
177
+
178
+ Everyone interacting in the Ruby OpenAI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/moraki-finance/ruby-experian/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "experian"
5
+ require "pry"
6
+ require "pry-byebug"
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
14
+
15
+ require "irb"
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -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,27 @@
1
+ module Experian
2
+ class Client
3
+ include Experian::HTTP
4
+
5
+ CONFIG_KEYS = %i[
6
+ user_code password request_timeout base_uri extra_headers
7
+ ].freeze
8
+ attr_reader(*CONFIG_KEYS, :faraday_middleware)
9
+
10
+ def initialize(config = {}, &faraday_middleware)
11
+ CONFIG_KEYS.each do |key|
12
+ # Set instance variables like api_type & access_token. Fall back to global config
13
+ # if not present.
14
+ instance_variable_set("@#{key}", config[key] || Experian.configuration.send(key))
15
+ end
16
+ @faraday_middleware = faraday_middleware
17
+ end
18
+
19
+ def report(cif:, format: :xml)
20
+ response = get(path: "/informe", format:, cif:, cod_servicio: 57)
21
+
22
+ return Experian::Report.new(response) if format == :xml
23
+
24
+ response
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,122 @@
1
+ require "base64"
2
+ require "sha3"
3
+
4
+ module Experian
5
+ module HTTP
6
+ module FlatParamsEncoder
7
+ class << self
8
+ extend Forwardable
9
+ def_delegators :'Faraday::Utils', :escape, :unescape
10
+ end
11
+
12
+ def self.encode(params)
13
+ return nil if params == nil
14
+
15
+ if !params.is_a?(Array)
16
+ if !params.respond_to?(:to_hash)
17
+ raise TypeError,
18
+ "Can't convert #{params.class} into Hash."
19
+ end
20
+ params = params.to_hash
21
+ params = params.map do |key, value|
22
+ key = key.to_s if key.kind_of?(Symbol)
23
+ [key, value]
24
+ end
25
+ end
26
+
27
+ # The params have form [['key1', 'value1'], ['key2', 'value2']].
28
+ buffer = ''
29
+ params.each do |key, value|
30
+ encoded_key = escape(key)
31
+ value = value.to_s if value == true || value == false
32
+ if value == nil
33
+ buffer << "#{encoded_key}&"
34
+ elsif value.kind_of?(Array)
35
+ value.each do |sub_value|
36
+ encoded_value = escape(sub_value)
37
+ buffer << "#{encoded_key}=#{encoded_value}&"
38
+ end
39
+ else
40
+ encoded_value = escape(value)
41
+ buffer << "#{encoded_key}=#{encoded_value}&"
42
+ end
43
+ end
44
+ return buffer.chop
45
+ end
46
+
47
+ def self.decode(query)
48
+ empty_accumulator = {}
49
+ return nil if query == nil
50
+ split_query = (query.split('&').map do |pair|
51
+ pair.split('=', 2) if pair && !pair.empty?
52
+ end).compact
53
+ return split_query.inject(empty_accumulator.dup) do |accu, pair|
54
+ pair[0] = unescape(pair[0])
55
+ pair[1] = true if pair[1].nil?
56
+ if pair[1].respond_to?(:to_str)
57
+ pair[1] = unescape(pair[1].to_str.gsub(/\+/, " "))
58
+ end
59
+ if accu[pair[0]].kind_of?(Array)
60
+ accu[pair[0]] << pair[1]
61
+ elsif accu[pair[0]]
62
+ accu[pair[0]] = [accu[pair[0]], pair[1]]
63
+ else
64
+ accu[pair[0]] = pair[1]
65
+ end
66
+ accu
67
+ end
68
+ end
69
+ end
70
+
71
+ def get(path:, format:, **query)
72
+ tip_formato = {
73
+ xml: 2,
74
+ pdf: 3
75
+ }[format]
76
+
77
+ raise Experian::Error, "Invalid format: #{format}" unless tip_formato
78
+
79
+ query.merge!(tip_formato:)
80
+ full_uri = uri(path:, query:)
81
+
82
+ if format == :xml
83
+ return conn.get(full_uri) do |req|
84
+ req.headers = headers
85
+ end
86
+ end
87
+
88
+ full_uri
89
+ end
90
+
91
+ private
92
+
93
+ def conn
94
+ connection = Faraday.new do |f|
95
+ f.options[:timeout] = request_timeout
96
+ f.options[:params_encoder] = FlatParamsEncoder
97
+ f.use MiddlewareErrors
98
+ f.response :raise_error
99
+ end
100
+
101
+ @faraday_middleware&.call(connection)
102
+
103
+ connection
104
+ end
105
+
106
+ def uri(path:, query: {})
107
+ query[:cod_usuario] = user_code
108
+ query[:crc] = crc(query)
109
+ File.join(base_uri, path) + "?#{URI.encode_www_form(query)}"
110
+ end
111
+
112
+ def crc(query = {})
113
+ SHA3::Digest.hexdigest(:sha256, query.values.join << password)
114
+ rescue => e
115
+ raise Experian::Error, "Error calculating CRC: #{e.message}"
116
+ end
117
+
118
+ def headers
119
+ {}.merge(extra_headers)
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,70 @@
1
+ require "multi_xml"
2
+ require "rexml"
3
+
4
+ module Experian
5
+ class Report
6
+ attr_reader :response, :url, :raw_xml, :xml
7
+
8
+ def initialize(response)
9
+ @response = response
10
+ @url = response.env.url.to_s
11
+ @raw_xml = response.body
12
+ MultiXml.parser = :rexml
13
+ @xml = MultiXml.parse(@raw_xml)
14
+
15
+ raise Experian::AuthenticationError if authentication_error?
16
+ end
17
+
18
+ def id
19
+ if (id_xml = data["DatosIdentificativos"])
20
+ OpenStruct.new(
21
+ cif: id_xml["Cif"],
22
+ name: id_xml["Nombre"],
23
+ infotel_code: id_xml["CodigoInfotel"],
24
+ incorporation_date: id_xml["FechaFundacion"],
25
+ social_form: id_xml["FormaSocial"]["__content__"],
26
+ )
27
+ end
28
+ end
29
+
30
+ def address
31
+ if (address_xml = data["DomicilioComercial"])
32
+ OpenStruct.new(
33
+ line: address_xml["Domicilio"],
34
+ city: address_xml["Poblacion"],
35
+ province: address_xml["Provincia"],
36
+ postal_code: address_xml["CodigoPostal"],
37
+ municipality: address_xml["Municipio"],
38
+ )
39
+ end
40
+ end
41
+
42
+ # Number of employees in the last recorded excercise
43
+ def number_of_employees
44
+ data.dig("ListaAnualEmpleados", "Empleado")&.first&.dig("EmpleadoFijo")&.to_i
45
+ end
46
+
47
+ def rating
48
+ if (rating_xml = data["Rating"])
49
+ return unless rating_xml["RatingAxesorDef"]
50
+
51
+ OpenStruct.new(
52
+ score: rating_xml["RatingAxesorDef"]&.strip&.to_i,
53
+ default_probability: rating_xml["ProbImpago"]&.to_f,
54
+ risk: rating_xml["GrupoRiesgo"],
55
+ size: rating_xml["Tamaño"],
56
+ )
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def data
63
+ xml.dig("ServicioWebAxesor", "ListaPaquetesNegocio")
64
+ end
65
+
66
+ def authentication_error?
67
+ xml.dig("DatosError", "CodError") == "1"
68
+ end
69
+ end
70
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module Experian
2
+ VERSION = "0.0.1".freeze
3
+ end
data/lib/experian.rb ADDED
@@ -0,0 +1,69 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+
4
+ require_relative "experian/http"
5
+ require_relative "experian/client"
6
+ require_relative "experian/version"
7
+ require_relative "experian/report"
8
+
9
+ module Experian
10
+ class Error < StandardError; end
11
+ class AuthenticationError < Error; end
12
+ class ConfigurationError < Error; end
13
+
14
+ class MiddlewareErrors < Faraday::Middleware
15
+ def call(env)
16
+ @app.call(env)
17
+ rescue Faraday::Error => e
18
+ raise e unless e.response.is_a?(Hash)
19
+
20
+ logger = Logger.new($stdout)
21
+ logger.formatter = proc do |_severity, _datetime, _progname, msg|
22
+ "\033[31mExperian HTTP Error (spotted in ruby-experian #{VERSION}): #{msg}\n\033[0m"
23
+ end
24
+ logger.error(e.response[:body])
25
+
26
+ raise e
27
+ end
28
+ end
29
+
30
+ class Configuration
31
+ attr_writer :user_code, :password, :version, :request_timeout, :base_uri, :extra_headers
32
+ attr_reader :base_uri, :request_timeout, :version, :extra_headers
33
+
34
+ DEFAULT_BASE_URI = "https://informes.axesor.es".freeze
35
+ DEFAULT_VERSION = "9.0".freeze
36
+ DEFAULT_REQUEST_TIMEOUT = 120
37
+
38
+ def initialize
39
+ @user_code = nil
40
+ @password = nil
41
+ @version = DEFAULT_VERSION
42
+ @request_timeout = DEFAULT_REQUEST_TIMEOUT
43
+ @base_uri = DEFAULT_BASE_URI
44
+ @extra_headers = {}
45
+ end
46
+
47
+ def user_code
48
+ return @user_code if @user_code
49
+ raise ConfigurationError, "Experian user_code missing!"
50
+ end
51
+
52
+ def password
53
+ return @password if @password
54
+ raise ConfigurationError, "Experian password missing!"
55
+ end
56
+ end
57
+
58
+ class << self
59
+ attr_writer :configuration
60
+ end
61
+
62
+ def self.configuration
63
+ @configuration ||= Experian::Configuration.new
64
+ end
65
+
66
+ def self.configure
67
+ yield(configuration)
68
+ end
69
+ end
@@ -0,0 +1 @@
1
+ require_relative "../experian"
@@ -0,0 +1,22 @@
1
+ require_relative "lib/experian/version"
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "ruby-experian"
5
+ s.version = Experian::VERSION
6
+ s.summary = "Experian connector"
7
+ s.description = "A simple hello world gem"
8
+ s.authors = ["Martin Mochetti"]
9
+ s.email = "martin@moraki.co"
10
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
11
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
12
+ end
13
+ s.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
14
+ s.homepage = "https://github.com/moraki/ruby-experian"
15
+ s.license = "MIT"
16
+ s.bindir = "bin"
17
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "faraday", ">= 1"
21
+ s.add_dependency "faraday_middleware", ">= 1"
22
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-experian
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Mochetti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-26 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: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
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: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ description: A simple hello world gem
42
+ email: martin@moraki.co
43
+ executables:
44
+ - console
45
+ - setup
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".github/dependabot.yml"
50
+ - ".github/pull_request_template.md"
51
+ - ".github/workflows/tests.yml"
52
+ - ".gitignore"
53
+ - ".rspec"
54
+ - ".rubocop.yml"
55
+ - ".ruby-version"
56
+ - CODE_OF_CONDUCT.md
57
+ - CONTRIBUTING.md
58
+ - Gemfile
59
+ - Gemfile.lock
60
+ - README.md
61
+ - Rakefile
62
+ - bin/console
63
+ - bin/setup
64
+ - lib/experian.rb
65
+ - lib/experian/client.rb
66
+ - lib/experian/http.rb
67
+ - lib/experian/report.rb
68
+ - lib/experian/response.rb
69
+ - lib/experian/version.rb
70
+ - lib/ruby/experian.rb
71
+ - ruby-experian.gemspec
72
+ homepage: https://github.com/moraki/ruby-experian
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.6.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.2.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Experian connector
95
+ test_files: []