dadata-rb 3.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4282ab1b196c52619d9caa5874dba8b3f6eb68770fb0958d9de05633adcedcf9
4
+ data.tar.gz: 04a96cd667879a35f2fd34b69c3b01e08ce29e055893f58da1388c20db047004
5
+ SHA512:
6
+ metadata.gz: 1f72031f482ef11ab15415396da0dc00da2f350db2e350f274e8d79e53b938c75c26f0dd2e8e1b65c6068d2193accaa7df3221747385cfc0ab06ef3ad47bfc59
7
+ data.tar.gz: 2c924cf578c1fb906a7aac22cfe15a2490386e503d3c42010222e5cd4a9f5216c55b3462348fa02d1c9d4eb405d0b8cb812b95009c73bd2bd026cebb9123ecd4
data/.rubocop.yml ADDED
@@ -0,0 +1,134 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.3
3
+ SuggestExtensions: false # Disable extension suggestions
4
+ NewCops: enable
5
+ Exclude:
6
+ - 'Gemfile.lock'
7
+ - '.*/**'
8
+ - 'test/fixtures/**/*'
9
+ - 'tmp/**/*'
10
+ - '.git/**/*'
11
+ - 'bin/*'
12
+ - '.idea/**/*'
13
+ - '.vscode/**/*'
14
+ - '.ruby-lsp/**/*'
15
+ - 'vendor/**/*'
16
+
17
+ require:
18
+ - rubocop-minitest
19
+ - rubocop-rake
20
+ - rubocop-performance
21
+
22
+ Style/StringLiterals:
23
+ Enabled: true
24
+ EnforcedStyle: single_quotes
25
+
26
+ Style/StringLiteralsInInterpolation:
27
+ Enabled: true
28
+ EnforcedStyle: double_quotes
29
+
30
+ Layout/LineLength:
31
+ Max: 120
32
+ # Allow long lines in test assertions, error messages, and gem requirement messages
33
+ AllowedPatterns:
34
+ - '^(\s+)?#' # Allow long comments
35
+ - 'assert(_\w+)?\s+.+,\s+".*"$' # Allow long assertion messages
36
+ - ".*gem '.*' is required.*" # Allow long gem requirement messages
37
+ - ".*gem install.*" # Allow long gem install instructions
38
+ - ".*unless.*" # Allow unless conditions that make code more readable
39
+
40
+ Layout/ArgumentAlignment:
41
+ EnforcedStyle: with_first_argument
42
+
43
+ Layout/HashAlignment:
44
+ EnforcedHashRocketStyle: table
45
+ EnforcedColonStyle: table
46
+ EnforcedLastArgumentHashStyle: always_inspect
47
+
48
+ Layout/MultilineMethodCallIndentation:
49
+ EnforcedStyle: aligned
50
+
51
+ Layout/TrailingWhitespace:
52
+ Enabled: true
53
+
54
+ Style/Documentation:
55
+ Enabled: true
56
+ Exclude:
57
+ - 'test/**/*'
58
+ - 'lib/generators/**/*'
59
+ - 'lib/dadata/api_exceptions.rb'
60
+
61
+ Style/ClassAndModuleChildren:
62
+ Enabled: true
63
+ EnforcedStyle: nested
64
+ Exclude:
65
+ - 'test/**/*'
66
+
67
+ Style/Lambda:
68
+ EnforcedStyle: literal
69
+
70
+ Style/NumericPredicate:
71
+ Enabled: true
72
+ EnforcedStyle: predicate
73
+ Exclude:
74
+ - 'test/**/*'
75
+
76
+ Performance/RedundantEqualityComparisonBlock:
77
+ Enabled: true
78
+
79
+ Minitest/MultipleAssertions:
80
+ Enabled: true
81
+ Max: 10
82
+ Exclude:
83
+ - 'test/generators/**/*' # Generator tests often need multiple assertions
84
+
85
+ Style/FrozenStringLiteralComment:
86
+ Enabled: true
87
+ Exclude:
88
+ - 'Gemfile'
89
+ - 'Rakefile'
90
+
91
+ Metrics/BlockLength:
92
+ Exclude:
93
+ - 'test/**/*'
94
+ - '*.gemspec'
95
+ - 'Rakefile'
96
+ - 'lib/dadata/client/base.rb' # Allow longer blocks for connection setup
97
+
98
+ Metrics/MethodLength:
99
+ Max: 40
100
+ Exclude:
101
+ - 'test/**/*'
102
+
103
+ Metrics/AbcSize:
104
+ Max: 40
105
+ Exclude:
106
+ - 'test/**/*'
107
+
108
+ Metrics/ClassLength:
109
+ Max: 150
110
+ Exclude:
111
+ - 'test/**/*'
112
+
113
+ Metrics/CyclomaticComplexity:
114
+ Max: 8 # Increased from 7 to accommodate validate! and build_connection methods
115
+
116
+ Metrics/PerceivedComplexity:
117
+ Max: 9 # Increased to match our codebase's needs
118
+
119
+ Naming/FileName:
120
+ Exclude:
121
+ - 'lib/dadata.rb'
122
+ - 'lib/dadata-rb.rb' # gem-name require shim; hyphen matches spec.name
123
+
124
+ Gemspec/RequiredRubyVersion:
125
+ Enabled: true
126
+
127
+ Style/RaiseArgs:
128
+ EnforcedStyle: exploded # Prefer raise ErrorClass, 'message' style
129
+
130
+ Style/GuardClause:
131
+ Enabled: false # Sometimes if/else is more readable than guard clauses
132
+
133
+ Style/IfUnlessModifier:
134
+ Enabled: false # Sometimes multi-line if statements are more readable
data/CHANGELOG.md ADDED
@@ -0,0 +1,129 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [3.0.0] - 2026-05-31
9
+
10
+ ### Added
11
+ - `config.log_request_bodies` option (default `false`) to opt into logging request payloads at `:debug`
12
+ - Granular API error classes are now actually raised: `BadRequestError` (400), `UnauthorizedError` (401), `NotFoundError` (404), in addition to `AuthenticationError` (403) and `RateLimitError` (429)
13
+ - `Dadata::TimeoutError` (subclass of `ConnectionError`), raised on request timeouts
14
+ - `ClientBase#close` to release persistent connections (previously `Client#close` raised `NoMethodError`)
15
+
16
+ ### Changed
17
+ - **BREAKING**: Published to RubyGems as `dadata-rb` (the `dadata` name was already taken). Installs from git must change `gem 'dadata'` to `gem 'dadata-rb'`; `require 'dadata'` is unchanged (a `dadata-rb` shim is also provided).
18
+ - **BREAKING**: Request bodies are no longer logged by default. They contain personal data (passports, names, phones, emails); set `config.log_request_bodies = true` to restore the previous debug behavior.
19
+ - **BREAKING**: Timeouts now raise `Dadata::TimeoutError` instead of `Dadata::ConnectionError`. `TimeoutError` subclasses `ConnectionError`, so existing `rescue ConnectionError` keeps working.
20
+ - **BREAKING**: `400`/`401`/`404` responses now raise `BadRequestError`/`UnauthorizedError`/`NotFoundError` instead of generic `ApiError`. All remain subclasses of `ApiError`.
21
+ - `SecureLogger` log lines now use the correct severity letter (`E`, `W`, …) instead of a hardcoded `I`
22
+ - Single request-logging path via `SensitiveDataMiddleware` (removed duplicate logging in `ClientBase`)
23
+ - Header/message sanitization consolidated into the shared `SensitiveData` module
24
+
25
+ ### Removed
26
+ - **BREAKING**: `config.connection_pool_size` and `config.connection_pool_timeout` — these were never wired into the HTTP layer. The gem still uses persistent connections via `net-http-persistent`.
27
+ - **BREAKING**: `zeitwerk` runtime dependency — it was declared but never used (loading is via `require_relative`).
28
+ - RBS signatures under `sig/` (were stale and shipped with the gem); will be regenerated once the API stabilizes.
29
+
30
+ ### Fixed
31
+ - Removed a bogus `'Error'` entry from the Faraday retry exception list
32
+ - `Client#close` now works instead of raising `NoMethodError`
33
+
34
+ ### Security
35
+ - Personal data in request payloads is no longer written to logs unless explicitly enabled via `config.log_request_bodies`
36
+
37
+ ## [2.0.0] - 2025-01-25
38
+
39
+ ### Added
40
+ - Secure logging system with automatic filtering of sensitive data
41
+ - `SecureLogger` class that extends Ruby's Logger to sanitize sensitive information
42
+ - `SensitiveData` module for handling sensitive data in logs and error messages
43
+ - Connection pooling for improved performance
44
+ - New configuration options:
45
+ - `connection_pool_size` for controlling concurrent connections
46
+ - `connection_pool_timeout` for connection pool timeout
47
+ - `log_level` for setting logging verbosity
48
+ - Custom logger support with automatic secure wrapping
49
+
50
+ ### Changed
51
+ - **BREAKING**: All loggers are now automatically wrapped in `SecureLogger`
52
+ - **BREAKING**: Configuration syntax changed from hash-style to method calls
53
+ - Improved HTTP connection handling with persistent connections
54
+ - Enhanced error handling with sanitized error messages
55
+ - Updated documentation with security best practices
56
+
57
+ ### Security
58
+ - Automatic filtering of sensitive headers (Authorization, X-Secret, API-Key)
59
+ - Secure handling of API keys and secrets in logs
60
+ - Protection against accidental exposure of sensitive data in error messages
61
+
62
+ ## [1.1.2] - 2024-01-26
63
+
64
+ ### Changed
65
+ - Updated Ruby version requirement to >= 3.3.0
66
+ - Updated development dependencies to their latest versions
67
+ - Improved code formatting and alignment in test files
68
+ - Enhanced RuboCop configuration with additional rules and extensions
69
+ - Added warning suppression for third-party gem warnings in test suite
70
+ - Replaced OpenStruct with Struct in tests for better performance
71
+
72
+ ### Fixed
73
+ - Fixed method redefinition warnings in generator tests
74
+ - Fixed API error handling in tests to use correct error message assertions
75
+ - Fixed connection error tests to properly test different network failure scenarios
76
+ - Fixed initializer generator tests to match actual template content
77
+ - Fixed test assertions to use proper configuration syntax
78
+ - Fixed test warnings related to Rails generator testing
79
+ - Fixed non-atomic file operations in generator tests
80
+ - Removed unnecessary access modifiers in tests
81
+
82
+ ## [1.1.1] - 2024-01-25
83
+
84
+ ### Fixed
85
+ - Fixed API error handling in tests to use correct error message assertions
86
+ - Fixed connection error tests to properly test different network failure scenarios
87
+ - Fixed initializer generator tests to match actual template content
88
+ - Fixed test assertions to use proper configuration syntax
89
+ - Fixed test warnings related to Rails generator testing
90
+
91
+ ## [1.1.0] - 2024-01-24
92
+
93
+ ### Added
94
+ - Comprehensive test suite for Rails generator
95
+ - Support for storing API keys in Rails credentials
96
+ - New generator options:
97
+ - `--use-credentials` (default: true) for secure API key storage
98
+ - `--timeout` for configuring request timeout
99
+ - `--suggestions-count` for setting default suggestions limit
100
+ - Improved documentation in generator templates
101
+ - Type definitions using RBS for all clients
102
+ - Bilingual documentation (Russian and English) in README
103
+ - Enhanced error handling in initializer templates
104
+ - Extended test coverage for initializer generator
105
+
106
+ ### Changed
107
+ - Replaced `http` gem with `faraday` for better HTTP handling
108
+ - Improved initializer template with better code organization and error handling
109
+ - Renamed initializer template to use `.rb.tt` extension for better Rails integration
110
+ - Updated Rakefile to include all test files including initializer tests
111
+ - Improved code style and fixed RuboCop warnings:
112
+ - Fixed string literals in Gemfile
113
+ - Improved file operations safety in tests
114
+ - Enhanced error handling in API exceptions
115
+ - Fixed code style issues across the codebase
116
+
117
+ ### Fixed
118
+ - Proper error classes in initializer templates
119
+ - Configuration validation in initializer templates
120
+ - Various code style issues and RuboCop warnings
121
+
122
+ ### Security
123
+ - Added secure credentials storage option for API keys
124
+ - Warning messages when storing API keys directly in initializer
125
+ - Improved file operations safety in tests
126
+
127
+ ## [1.0.0] - 2023-05-24
128
+
129
+ - Initial release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,153 @@
1
+ # Contributing Guidelines | Руководство по участию в разработке
2
+
3
+ [English](#english) | [Русский](#russian)
4
+
5
+ ---
6
+
7
+ <a name="russian"></a>
8
+ # Руководство по участию в разработке
9
+
10
+ ## Структура веток
11
+
12
+ Проект использует следующую структуру веток:
13
+
14
+ - `master` - основная ветка, содержащая только релизы с чистой историей коммитов
15
+ - `dev` - ветка разработки, интеграционная ветка для новых функций
16
+ - `vX.Y.Z` - ветки для поддержки предыдущих мажорных версий (например, `v1.0.0`)
17
+ - `feature/*` - ветки для разработки новых функций
18
+ - `fix/*` - ветки для исправления ошибок
19
+ - `refactor/*` - ветки для рефакторинга кода
20
+
21
+ ## Процесс разработки
22
+
23
+ 1. **Начало работы над новой функцией**:
24
+ ```bash
25
+ git checkout dev # Переключаемся на ветку dev
26
+ git pull # Получаем последние изменения
27
+ git checkout -b feature/X # Создаем новую ветку для функции
28
+ ```
29
+
30
+ 2. **Разработка**:
31
+ - Следуйте стилю кода проекта
32
+ - Добавляйте тесты для новой функциональности
33
+ - Используйте [Conventional Commits](https://www.conventionalcommits.org/) для сообщений коммитов
34
+
35
+ 3. **Интеграция**:
36
+ ```bash
37
+ git checkout dev # Переключаемся на dev
38
+ git pull # Получаем последние изменения
39
+ git merge feature/X # Интегрируем новую функцию
40
+ ```
41
+
42
+ 4. **Подготовка релиза**:
43
+ - Обновите CHANGELOG.md
44
+ - Обновите версию в lib/dadata/version.rb
45
+ - Обновите документацию
46
+
47
+ 5. **Релиз**:
48
+ ```bash
49
+ git checkout master # Переключаемся на master
50
+ git merge --squash dev # Сливаем изменения из dev с объединением коммитов
51
+ git commit -m "..." # Создаем релизный коммит
52
+ git tag vX.Y.Z # Создаем тег для версии
53
+ ```
54
+
55
+ 6. **После релиза**:
56
+ ```bash
57
+ git checkout dev # Переключаемся на dev
58
+ git reset --hard master # Синхронизируем dev с master
59
+ ```
60
+
61
+ ## Правила именования коммитов
62
+
63
+ Используйте [Conventional Commits](https://www.conventionalcommits.org/):
64
+
65
+ - `feat:` - новая функциональность
66
+ - `fix:` - исправление ошибок
67
+ - `docs:` - изменения в документации
68
+ - `style:` - форматирование, отступы и т.д.
69
+ - `refactor:` - рефакторинг кода
70
+ - `test:` - добавление или изменение тестов
71
+ - `chore:` - обслуживание кода
72
+
73
+ Для breaking changes добавляйте `!` и описание в теле коммита:
74
+ ```
75
+ feat!: изменение API клиента
76
+
77
+ BREAKING CHANGE: Изменен способ инициализации клиента
78
+ ```
79
+
80
+ ---
81
+
82
+ <a name="english"></a>
83
+ # Contributing Guidelines
84
+
85
+ ## Branch Structure
86
+
87
+ The project uses the following branch structure:
88
+
89
+ - `master` - release branch containing only releases with clean commit history
90
+ - `dev` - development branch, integration branch for new features
91
+ - `vX.Y.Z` - branches for supporting previous major versions (e.g., `v1.0.0`)
92
+ - `feature/*` - branches for new feature development
93
+ - `fix/*` - branches for bug fixes
94
+ - `refactor/*` - branches for code refactoring
95
+
96
+ ## Development Process
97
+
98
+ 1. **Starting a New Feature**:
99
+ ```bash
100
+ git checkout dev # Switch to dev branch
101
+ git pull # Get latest changes
102
+ git checkout -b feature/X # Create new feature branch
103
+ ```
104
+
105
+ 2. **Development**:
106
+ - Follow the project's code style
107
+ - Add tests for new functionality
108
+ - Use [Conventional Commits](https://www.conventionalcommits.org/) for commit messages
109
+
110
+ 3. **Integration**:
111
+ ```bash
112
+ git checkout dev # Switch to dev
113
+ git pull # Get latest changes
114
+ git merge feature/X # Integrate new feature
115
+ ```
116
+
117
+ 4. **Release Preparation**:
118
+ - Update CHANGELOG.md
119
+ - Update version in lib/dadata/version.rb
120
+ - Update documentation
121
+
122
+ 5. **Release**:
123
+ ```bash
124
+ git checkout master # Switch to master
125
+ git merge --squash dev # Merge changes from dev with squash
126
+ git commit -m "..." # Create release commit
127
+ git tag vX.Y.Z # Create version tag
128
+ ```
129
+
130
+ 6. **Post-Release**:
131
+ ```bash
132
+ git checkout dev # Switch to dev
133
+ git reset --hard master # Sync dev with master
134
+ ```
135
+
136
+ ## Commit Naming Rules
137
+
138
+ Use [Conventional Commits](https://www.conventionalcommits.org/):
139
+
140
+ - `feat:` - new feature
141
+ - `fix:` - bug fix
142
+ - `docs:` - documentation changes
143
+ - `style:` - formatting, indentation, etc.
144
+ - `refactor:` - code refactoring
145
+ - `test:` - adding or modifying tests
146
+ - `chore:` - code maintenance
147
+
148
+ For breaking changes, add `!` and description in commit body:
149
+ ```
150
+ feat!: change client API
151
+
152
+ BREAKING CHANGE: Changed client initialization method
153
+ ```
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 ad
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.