deepl-rb 3.10.0 → 4.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.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +313 -1
  4. data/README.md +225 -309
  5. data/Rakefile +17 -8
  6. data/VERSION +1 -1
  7. data/deepl-rb.gemspec +73 -86
  8. data/lib/deepl/admin_client.rb +39 -14
  9. data/lib/deepl/api.rb +3 -17
  10. data/lib/deepl/app_info.rb +0 -1
  11. data/lib/deepl/client.rb +399 -84
  12. data/lib/deepl/configuration.rb +19 -70
  13. data/lib/deepl/exceptions/authorization_failed.rb +1 -1
  14. data/lib/deepl/exceptions/connection_error.rb +10 -7
  15. data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
  16. data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
  17. data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
  18. data/lib/deepl/exceptions/request_error.rb +7 -0
  19. data/lib/deepl/exceptions/server_error.rb +2 -1
  20. data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
  21. data/lib/deepl/exceptions/validation_error.rb +3 -2
  22. data/lib/deepl/requests/base.rb +129 -51
  23. data/lib/deepl/requests/correct.rb +2 -8
  24. data/lib/deepl/requests/document/upload.rb +29 -26
  25. data/lib/deepl/requests/glossary/base.rb +30 -0
  26. data/lib/deepl/requests/glossary/create.rb +18 -22
  27. data/lib/deepl/requests/glossary/destroy.rb +4 -16
  28. data/lib/deepl/requests/glossary/entries.rb +6 -14
  29. data/lib/deepl/requests/glossary/find.rb +3 -13
  30. data/lib/deepl/requests/glossary/language_pairs.rb +2 -2
  31. data/lib/deepl/requests/glossary/list.rb +2 -2
  32. data/lib/deepl/requests/languages.rb +6 -11
  33. data/lib/deepl/requests/languages_for_resource.rb +2 -0
  34. data/lib/deepl/requests/multilingual_glossary/create.rb +8 -0
  35. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +4 -0
  36. data/lib/deepl/requests/multilingual_glossary/entries.rb +5 -3
  37. data/lib/deepl/requests/multilingual_glossary/helpers.rb +22 -14
  38. data/lib/deepl/requests/rephrase.rb +3 -1
  39. data/lib/deepl/requests/spoken_terms/create.rb +5 -0
  40. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +1 -0
  41. data/lib/deepl/requests/spoken_terms/entries.rb +1 -0
  42. data/lib/deepl/requests/spoken_terms/helpers.rb +9 -2
  43. data/lib/deepl/requests/style_profile/create.rb +5 -0
  44. data/lib/deepl/requests/style_profile/list.rb +2 -2
  45. data/lib/deepl/requests/style_rule/create.rb +25 -1
  46. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +7 -0
  47. data/lib/deepl/requests/style_rule/helpers.rb +13 -4
  48. data/lib/deepl/requests/style_rule/list.rb +2 -0
  49. data/lib/deepl/requests/style_rule/update.rb +1 -0
  50. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +2 -0
  51. data/lib/deepl/requests/translate.rb +20 -36
  52. data/lib/deepl/requests/translation_memory/create_export.rb +6 -1
  53. data/lib/deepl/requests/translation_memory/create_import.rb +10 -0
  54. data/lib/deepl/requests/translation_memory/download_export.rb +0 -4
  55. data/lib/deepl/requests/translation_memory/list.rb +2 -2
  56. data/lib/deepl/requests/translation_memory/segments.rb +2 -2
  57. data/lib/deepl/requests/translation_memory/storage_base.rb +5 -9
  58. data/lib/deepl/requests/write_improvements.rb +7 -0
  59. data/lib/deepl/resources/document_handle.rb +1 -26
  60. data/lib/deepl/resources/document_translation_status.rb +0 -12
  61. data/lib/deepl/resources/language.rb +4 -10
  62. data/lib/deepl/resources/multilingual_glossary.rb +4 -4
  63. data/lib/deepl/resources/style_rule.rb +1 -23
  64. data/lib/deepl/resources/translation_memory_job.rb +3 -4
  65. data/lib/deepl/resources/usage.rb +5 -38
  66. data/lib/deepl/utils/client_builder.rb +44 -9
  67. data/lib/deepl/utils/glossary_entries.rb +30 -0
  68. data/lib/deepl/utils/http_client_builder.rb +50 -13
  69. data/lib/deepl/utils/output_path.rb +25 -0
  70. data/lib/deepl/utils/term_validator.rb +3 -3
  71. data/lib/deepl/utils/translation_memory_operations.rb +230 -0
  72. data/lib/deepl.rb +6 -171
  73. data/lib/http_client_options.rb +2 -2
  74. data/lib/version.rb +1 -1
  75. data/upgrading_to_v4.md +374 -0
  76. metadata +9 -50
  77. data/.gitlab-ci.yml +0 -197
  78. data/lib/deepl/deprecation.rb +0 -42
  79. data/lib/deepl/document_api.rb +0 -150
  80. data/lib/deepl/exceptions/not_supported.rb +0 -20
  81. data/lib/deepl/glossary_api.rb +0 -38
  82. data/lib/deepl/style_rule_api.rb +0 -72
  83. data/lib/deepl/translation_memory_api.rb +0 -389
  84. data/license_checker.sh +0 -8
  85. data/spec/fixtures.rb +0 -33
  86. data/spec/offline/admin_client_spec.rb +0 -551
  87. data/spec/offline/client_spec.rb +0 -273
  88. data/spec/offline/configuration_spec.rb +0 -164
  89. data/spec/offline/constants_spec.rb +0 -180
  90. data/spec/offline/correct_text_spec.rb +0 -50
  91. data/spec/offline/deprecation_spec.rb +0 -32
  92. data/spec/offline/errors_spec.rb +0 -92
  93. data/spec/offline/glossaries_spec.rb +0 -98
  94. data/spec/offline/http_client_spec.rb +0 -319
  95. data/spec/offline/languages_spec.rb +0 -155
  96. data/spec/offline/module_methods_spec.rb +0 -13
  97. data/spec/offline/multilingual_glossaries_spec.rb +0 -358
  98. data/spec/offline/offline_helper.rb +0 -71
  99. data/spec/offline/rephrase_text_spec.rb +0 -73
  100. data/spec/offline/spoken_terms_spec.rb +0 -215
  101. data/spec/offline/style_profiles_spec.rb +0 -266
  102. data/spec/offline/style_rules_spec.rb +0 -318
  103. data/spec/offline/translate_document_spec.rb +0 -606
  104. data/spec/offline/translate_text_spec.rb +0 -286
  105. data/spec/offline/translation_memories_client_spec.rb +0 -256
  106. data/spec/offline/translation_memories_spec.rb +0 -463
  107. data/spec/offline/usage_spec.rb +0 -151
  108. data/spec/real_api/admin_client_spec.rb +0 -77
  109. data/spec/real_api/correct_text_spec.rb +0 -20
  110. data/spec/real_api/glossaries_spec.rb +0 -28
  111. data/spec/real_api/languages_spec.rb +0 -27
  112. data/spec/real_api/multilingual_glossaries_spec.rb +0 -53
  113. data/spec/real_api/proxy_spec.rb +0 -41
  114. data/spec/real_api/real_api_helper.rb +0 -65
  115. data/spec/real_api/rephrase_text_spec.rb +0 -16
  116. data/spec/real_api/spoken_terms_spec.rb +0 -56
  117. data/spec/real_api/style_profiles_spec.rb +0 -46
  118. data/spec/real_api/style_rules_spec.rb +0 -46
  119. data/spec/real_api/translate_document_spec.rb +0 -18
  120. data/spec/real_api/translate_text_spec.rb +0 -16
  121. data/spec/real_api/translation_memories_spec.rb +0 -56
  122. data/spec/real_api/usage_spec.rb +0 -20
  123. data/spec/spec_helper.rb +0 -13
data/Rakefile CHANGED
@@ -15,6 +15,21 @@ require 'rake'
15
15
  require 'juwelier'
16
16
  require_relative 'lib/version'
17
17
 
18
+ # Repository files that are not shipped in the gem.
19
+ GEM_FILES_EXCLUDE = %w[
20
+ .bumpversion.toml
21
+ .github/**/*
22
+ .circleci/**/*
23
+ catalog-info.yaml
24
+ .auto-approve.yaml
25
+ .gitar/**/*
26
+ .releaserc.mjs
27
+ renovate.json5
28
+ .gitlab-ci.yml
29
+ license_checker.sh
30
+ spec/**/*
31
+ ].freeze
32
+
18
33
  Juwelier::Tasks.new do |gem|
19
34
  gem.name = 'deepl-rb'
20
35
  gem.homepage = 'https://github.com/DeepLcom/deepl-rb'
@@ -24,6 +39,7 @@ Juwelier::Tasks.new do |gem|
24
39
  'Official Ruby library for the DeepL language translation API (v2). ' \
25
40
  'For more information, check this: https://www.deepl.com/docs/api-reference.html'
26
41
  gem.version = DeepL::VERSION
42
+ gem.required_ruby_version = '>= 3.0'
27
43
 
28
44
  gem.email = 'open-source@deepl.com'
29
45
  gem.authors = ['DeepL SE']
@@ -33,14 +49,7 @@ Juwelier::Tasks.new do |gem|
33
49
  'documentation_uri' => 'https://github.com/DeepLcom/deepl-rb/blob/main/README.md',
34
50
  'homepage_uri' => 'https://github.com/DeepLcom/deepl-rb'
35
51
  }
36
- gem.files.exclude '.bumpversion.toml'
37
- gem.files.exclude '.github/**/*'
38
- gem.files.exclude '.circleci/**/*'
39
- gem.files.exclude 'catalog-info.yaml'
40
- gem.files.exclude '.auto-approve.yaml'
41
- gem.files.exclude '.gitar/**/*'
42
- gem.files.exclude '.releaserc.mjs'
43
- gem.files.exclude 'renovate.json5'
52
+ gem.files.exclude(*GEM_FILES_EXCLUDE)
44
53
  end
45
54
 
46
55
  Juwelier::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.10.0
1
+ 4.0.0
data/deepl-rb.gemspec CHANGED
@@ -2,29 +2,24 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: deepl-rb 3.10.0 ruby lib
5
+ # stub: deepl-rb 4.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "3.10.0".freeze
9
+ s.version = "4.0.0".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.metadata = { "bug_tracker_uri" => "https://github.com/DeepLcom/deepl-rb/issues", "changelog_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md", "documentation_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/README.md", "homepage_uri" => "https://github.com/DeepLcom/deepl-rb" } if s.respond_to? :metadata=
13
13
  s.require_paths = ["lib".freeze]
14
14
  s.authors = ["DeepL SE".freeze]
15
- s.date = "2026-08-11"
15
+ s.date = "2026-11-18"
16
16
  s.description = "Official Ruby library for the DeepL language translation API (v2). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
17
17
  s.email = "open-source@deepl.com".freeze
18
18
  s.extra_rdoc_files = [
19
- "CHANGELOG.md",
20
19
  "LICENSE.md",
21
- "README.md",
22
- "license_checker.sh"
20
+ "README.md"
23
21
  ]
24
22
  s.files = [
25
- ".circleci/config.yml",
26
- ".github/workflows/add_issues_to_kanban.yml",
27
- ".gitlab-ci.yml",
28
23
  ".rubocop.yml",
29
24
  "CHANGELOG.md",
30
25
  "CODE_OF_CONDUCT.md",
@@ -37,46 +32,91 @@ Gem::Specification.new do |s|
37
32
  "VERSION",
38
33
  "deepl-rb.gemspec",
39
34
  "lib/deepl.rb",
35
+ "lib/deepl/admin_client.rb",
40
36
  "lib/deepl/api.rb",
37
+ "lib/deepl/app_info.rb",
38
+ "lib/deepl/client.rb",
41
39
  "lib/deepl/configuration.rb",
40
+ "lib/deepl/constants/admin_usage_group_by.rb",
42
41
  "lib/deepl/constants/base_constant.rb",
42
+ "lib/deepl/constants/custom_tag_usage_aggregate_by.rb",
43
+ "lib/deepl/constants/document_status_code.rb",
43
44
  "lib/deepl/constants/formality.rb",
45
+ "lib/deepl/constants/language_include.rb",
46
+ "lib/deepl/constants/language_resource_name.rb",
44
47
  "lib/deepl/constants/model_type.rb",
45
48
  "lib/deepl/constants/split_sentences.rb",
46
49
  "lib/deepl/constants/tag_handling.rb",
50
+ "lib/deepl/constants/tag_handling_version.rb",
47
51
  "lib/deepl/constants/tone.rb",
48
52
  "lib/deepl/constants/writing_style.rb",
49
- "lib/deepl/document_api.rb",
50
53
  "lib/deepl/exceptions/authorization_failed.rb",
51
54
  "lib/deepl/exceptions/bad_request.rb",
55
+ "lib/deepl/exceptions/connection_error.rb",
56
+ "lib/deepl/exceptions/document_not_ready_error.rb",
52
57
  "lib/deepl/exceptions/document_translation_error.rb",
53
58
  "lib/deepl/exceptions/error.rb",
54
59
  "lib/deepl/exceptions/limit_exceeded.rb",
55
60
  "lib/deepl/exceptions/not_found.rb",
56
- "lib/deepl/exceptions/not_supported.rb",
57
61
  "lib/deepl/exceptions/quota_exceeded.rb",
58
62
  "lib/deepl/exceptions/request_entity_too_large.rb",
59
63
  "lib/deepl/exceptions/request_error.rb",
60
64
  "lib/deepl/exceptions/server_error.rb",
61
- "lib/deepl/glossary_api.rb",
65
+ "lib/deepl/exceptions/translation_memory_job_error.rb",
66
+ "lib/deepl/exceptions/validation_error.rb",
67
+ "lib/deepl/requests/admin/base.rb",
68
+ "lib/deepl/requests/admin/create_developer_key.rb",
69
+ "lib/deepl/requests/admin/custom_tag_usage_analytics.rb",
70
+ "lib/deepl/requests/admin/list_developer_keys.rb",
71
+ "lib/deepl/requests/admin/update_developer_key.rb",
72
+ "lib/deepl/requests/admin/usage_analytics.rb",
62
73
  "lib/deepl/requests/base.rb",
74
+ "lib/deepl/requests/correct.rb",
63
75
  "lib/deepl/requests/document/download.rb",
64
76
  "lib/deepl/requests/document/get_status.rb",
65
77
  "lib/deepl/requests/document/upload.rb",
78
+ "lib/deepl/requests/glossary/base.rb",
66
79
  "lib/deepl/requests/glossary/create.rb",
67
80
  "lib/deepl/requests/glossary/destroy.rb",
68
81
  "lib/deepl/requests/glossary/entries.rb",
69
82
  "lib/deepl/requests/glossary/find.rb",
70
83
  "lib/deepl/requests/glossary/language_pairs.rb",
71
84
  "lib/deepl/requests/glossary/list.rb",
85
+ "lib/deepl/requests/language_resources.rb",
72
86
  "lib/deepl/requests/languages.rb",
87
+ "lib/deepl/requests/languages_for_resource.rb",
88
+ "lib/deepl/requests/multilingual_glossary/create.rb",
89
+ "lib/deepl/requests/multilingual_glossary/destroy.rb",
90
+ "lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb",
91
+ "lib/deepl/requests/multilingual_glossary/entries.rb",
92
+ "lib/deepl/requests/multilingual_glossary/find.rb",
93
+ "lib/deepl/requests/multilingual_glossary/helpers.rb",
94
+ "lib/deepl/requests/multilingual_glossary/list.rb",
95
+ "lib/deepl/requests/multilingual_glossary/replace_dictionary.rb",
96
+ "lib/deepl/requests/multilingual_glossary/update.rb",
73
97
  "lib/deepl/requests/rephrase.rb",
98
+ "lib/deepl/requests/spoken_terms/create.rb",
99
+ "lib/deepl/requests/spoken_terms/destroy.rb",
100
+ "lib/deepl/requests/spoken_terms/destroy_term_list.rb",
101
+ "lib/deepl/requests/spoken_terms/entries.rb",
102
+ "lib/deepl/requests/spoken_terms/find.rb",
103
+ "lib/deepl/requests/spoken_terms/helpers.rb",
104
+ "lib/deepl/requests/spoken_terms/list.rb",
105
+ "lib/deepl/requests/spoken_terms/replace_term_list.rb",
106
+ "lib/deepl/requests/spoken_terms/update.rb",
107
+ "lib/deepl/requests/style_profile/base.rb",
108
+ "lib/deepl/requests/style_profile/create.rb",
109
+ "lib/deepl/requests/style_profile/destroy.rb",
110
+ "lib/deepl/requests/style_profile/find.rb",
111
+ "lib/deepl/requests/style_profile/list.rb",
112
+ "lib/deepl/requests/style_profile/update.rb",
74
113
  "lib/deepl/requests/style_rule/create.rb",
75
114
  "lib/deepl/requests/style_rule/create_custom_instruction.rb",
76
115
  "lib/deepl/requests/style_rule/destroy.rb",
77
116
  "lib/deepl/requests/style_rule/destroy_custom_instruction.rb",
78
117
  "lib/deepl/requests/style_rule/find.rb",
79
118
  "lib/deepl/requests/style_rule/find_custom_instruction.rb",
119
+ "lib/deepl/requests/style_rule/helpers.rb",
80
120
  "lib/deepl/requests/style_rule/list.rb",
81
121
  "lib/deepl/requests/style_rule/update.rb",
82
122
  "lib/deepl/requests/style_rule/update_configured_rules.rb",
@@ -94,12 +134,21 @@ Gem::Specification.new do |s|
94
134
  "lib/deepl/requests/translation_memory/storage_base.rb",
95
135
  "lib/deepl/requests/translation_memory/upload_file.rb",
96
136
  "lib/deepl/requests/usage.rb",
137
+ "lib/deepl/requests/write_improvements.rb",
138
+ "lib/deepl/resources/admin_usage_report.rb",
97
139
  "lib/deepl/resources/base.rb",
140
+ "lib/deepl/resources/custom_tag_usage_report.rb",
141
+ "lib/deepl/resources/developer_key.rb",
98
142
  "lib/deepl/resources/document_handle.rb",
99
143
  "lib/deepl/resources/document_translation_status.rb",
100
144
  "lib/deepl/resources/glossary.rb",
101
145
  "lib/deepl/resources/language.rb",
102
146
  "lib/deepl/resources/language_pair.rb",
147
+ "lib/deepl/resources/language_resource.rb",
148
+ "lib/deepl/resources/language_support.rb",
149
+ "lib/deepl/resources/multilingual_glossary.rb",
150
+ "lib/deepl/resources/spoken_terms.rb",
151
+ "lib/deepl/resources/style_profile.rb",
103
152
  "lib/deepl/resources/style_rule.rb",
104
153
  "lib/deepl/resources/text.rb",
105
154
  "lib/deepl/resources/translation_memory.rb",
@@ -108,93 +157,31 @@ Gem::Specification.new do |s|
108
157
  "lib/deepl/resources/translation_memory_job.rb",
109
158
  "lib/deepl/resources/translation_memory_segments.rb",
110
159
  "lib/deepl/resources/usage.rb",
111
- "lib/deepl/style_rule_api.rb",
112
- "lib/deepl/translation_memory_api.rb",
113
160
  "lib/deepl/utils/backoff_timer.rb",
161
+ "lib/deepl/utils/client_builder.rb",
162
+ "lib/deepl/utils/document_poller.rb",
114
163
  "lib/deepl/utils/exception_builder.rb",
164
+ "lib/deepl/utils/glossary_entries.rb",
165
+ "lib/deepl/utils/http_client_builder.rb",
166
+ "lib/deepl/utils/number_parser.rb",
167
+ "lib/deepl/utils/output_path.rb",
168
+ "lib/deepl/utils/term_validator.rb",
115
169
  "lib/deepl/utils/time_parser.rb",
170
+ "lib/deepl/utils/translation_memory_operations.rb",
116
171
  "lib/http_client_options.rb",
117
172
  "lib/version.rb",
118
- "license_checker.sh",
119
- "spec/api/api_spec.rb",
120
- "spec/api/configuration_spec.rb",
121
- "spec/api/deepl_spec.rb",
122
- "spec/constants/constants_spec.rb",
123
- "spec/integration_tests/document_api_spec.rb",
124
- "spec/integration_tests/document_error_paths_spec.rb",
125
- "spec/integration_tests/glossary_api_spec.rb",
126
- "spec/integration_tests/glossary_error_paths_spec.rb",
127
- "spec/integration_tests/integration_test_utils.rb",
128
- "spec/integration_tests/languages_api_spec.rb",
129
- "spec/integration_tests/languages_error_paths_spec.rb",
130
- "spec/integration_tests/rephrase_api_spec.rb",
131
- "spec/integration_tests/rephrase_error_paths_spec.rb",
132
- "spec/integration_tests/smoke_test_spec.rb",
133
- "spec/integration_tests/style_rule_api_spec.rb",
134
- "spec/integration_tests/style_rule_error_paths_spec.rb",
135
- "spec/integration_tests/translate_api_spec.rb",
136
- "spec/integration_tests/translate_error_paths_spec.rb",
137
- "spec/integration_tests/translation_memory_api_spec.rb",
138
- "spec/integration_tests/translation_memory_error_paths_spec.rb",
139
- "spec/integration_tests/usage_api_spec.rb",
140
- "spec/integration_tests/usage_error_paths_spec.rb",
141
- "spec/requests/document/upload_spec.rb",
142
- "spec/requests/extra_body_parameters_types_spec.rb",
143
- "spec/requests/glossary/create_spec.rb",
144
- "spec/requests/glossary/destroy_spec.rb",
145
- "spec/requests/glossary/entries_spec.rb",
146
- "spec/requests/glossary/find_spec.rb",
147
- "spec/requests/glossary/language_pairs_spec.rb",
148
- "spec/requests/glossary/list_spec.rb",
149
- "spec/requests/languages_spec.rb",
150
- "spec/requests/rephrase_spec.rb",
151
- "spec/requests/style_rule/create_custom_instruction_spec.rb",
152
- "spec/requests/style_rule/create_spec.rb",
153
- "spec/requests/style_rule/destroy_custom_instruction_spec.rb",
154
- "spec/requests/style_rule/destroy_spec.rb",
155
- "spec/requests/style_rule/find_custom_instruction_spec.rb",
156
- "spec/requests/style_rule/find_spec.rb",
157
- "spec/requests/style_rule/list_spec.rb",
158
- "spec/requests/style_rule/update_configured_rules_spec.rb",
159
- "spec/requests/style_rule/update_custom_instruction_spec.rb",
160
- "spec/requests/style_rule/update_spec.rb",
161
- "spec/requests/translate_spec.rb",
162
- "spec/requests/translation_memory/create_export_spec.rb",
163
- "spec/requests/translation_memory/create_import_spec.rb",
164
- "spec/requests/translation_memory/destroy_spec.rb",
165
- "spec/requests/translation_memory/download_export_spec.rb",
166
- "spec/requests/translation_memory/find_job_spec.rb",
167
- "spec/requests/translation_memory/find_spec.rb",
168
- "spec/requests/translation_memory/list_spec.rb",
169
- "spec/requests/translation_memory/segments_spec.rb",
170
- "spec/requests/translation_memory/upload_file_spec.rb",
171
- "spec/requests/usage_spec.rb",
172
- "spec/resources/custom_instruction_spec.rb",
173
- "spec/resources/glossary_spec.rb",
174
- "spec/resources/language_pair_spec.rb",
175
- "spec/resources/language_spec.rb",
176
- "spec/resources/style_rule_spec.rb",
177
- "spec/resources/text_spec.rb",
178
- "spec/resources/translation_memory_export_spec.rb",
179
- "spec/resources/translation_memory_import_spec.rb",
180
- "spec/resources/translation_memory_job_spec.rb",
181
- "spec/resources/translation_memory_segments_spec.rb",
182
- "spec/resources/translation_memory_spec.rb",
183
- "spec/resources/usage_spec.rb",
184
- "spec/spec_helper.rb",
185
- "spec/support/live_mock_server.rb",
186
- "spec/support/managed_glossary.rb",
187
- "spec/support/managed_style_rule.rb",
188
- "spec/support/managed_translation_memory.rb"
173
+ "upgrading_to_v4.md"
189
174
  ]
190
175
  s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
191
176
  s.licenses = ["MIT".freeze]
192
- s.rubygems_version = "3.6.2".freeze
177
+ s.required_ruby_version = Gem::Requirement.new(">= 3.0".freeze)
178
+ s.rubygems_version = "3.5.22".freeze
193
179
  s.summary = "Official Ruby library for the DeepL language translation API.".freeze
194
180
 
195
181
  s.specification_version = 4
196
182
 
197
183
  s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
184
+ s.add_development_dependency(%q<git>.freeze, ["< 6".freeze])
198
185
  s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
199
186
  end
200
187
 
@@ -6,8 +6,7 @@
6
6
  module DeepL
7
7
  ##
8
8
  # Client for the DeepL Admin API, used to manage the developer keys of your organization and
9
- # to retrieve usage analytics. It is independent of +DeepL.configure+ and never reads the
10
- # +DEEPL_AUTH_KEY+ or +DEEPL_SERVER_URL+ environment variables.
9
+ # to retrieve usage analytics. It owns its configuration and reads no environment variables.
11
10
  #
12
11
  # All methods may raise a +DeepL::Exceptions::Error+ or a subclass, for example
13
12
  # +DeepL::Exceptions::AuthorizationFailed+ if the admin key is not accepted.
@@ -15,22 +14,34 @@ module DeepL
15
14
  DEEPL_SERVER_URL = 'https://api.deepl.com'
16
15
  private_constant :DEEPL_SERVER_URL
17
16
 
17
+ USAGE_LIMITS = %i[characters speech_to_text_milliseconds speech_to_speech_milliseconds].freeze
18
+ private_constant :USAGE_LIMITS
19
+
18
20
  ##
21
+ # A keyword argument given as +nil+ takes its default, like an omitted one.
19
22
  # @param [String] admin_key Admin API key, surrounding whitespace is removed.
20
- # @param [String, nil] server_url Base URL of the DeepL API, defaults to
23
+ # @param [String, nil] server_url Base URL of the DeepL API, an absolute +http+ or +https+
24
+ # URL with a host; trailing slashes are removed. Defaults to
21
25
  # +https://api.deepl.com+ (also for keys ending in +:fx+).
22
26
  # @param [Hash] headers HTTP headers sent with every request. A header of the same name in
23
27
  # any casing replaces the library's, +Authorization+ and +User-Agent+ included, except the
24
28
  # technical headers +Content-Type+, +Content-Length+, +Transfer-Encoding+ and +Host+.
25
- # @param [Integer] max_retries Number of retries after the first attempt.
26
- # @param [Numeric] timeout Timeout of each attempt in seconds.
27
- # @param [String, nil] proxy Proxy URL, e.g. +http://user:password@proxy.example:8080+.
28
- # @param [Boolean] send_platform_info Whether to send basic platform information.
29
+ # @param [Integer, nil] max_retries Number of retries after the first attempt.
30
+ # @param [Numeric, nil] timeout Timeout of each attempt in seconds.
31
+ # @param [String, URI, Hash, nil] proxy Proxy URL (+http+ or +https+ scheme) as a String or
32
+ # +URI+, e.g. +http://user:password@proxy.example:8080+, or a hash with +proxy_addr+ and
33
+ # +proxy_port+ (string or symbol keys, both required), which is a plain HTTP proxy. An
34
+ # +https+ proxy is connected to over TLS and needs net-http 0.5.0 or later (bundled from
35
+ # Ruby 3.4) and an +https+ server URL.
36
+ # @param [Boolean, nil] send_platform_info Whether to send basic platform information.
29
37
  # @param [DeepL::AppInfo, Hash, nil] app_info Your application's +app_name+ and
30
38
  # +app_version+, added to the +User-Agent+.
31
39
  # @param [DeepL::HTTPClientOptions, nil] http_client_options Proxy, SSL and timeout options.
32
40
  # @param [Logger, nil] logger Logger for requests and retries.
33
- # @raise [ArgumentError] If +admin_key+ is empty.
41
+ # @raise [ArgumentError] If +admin_key+ is empty, +server_url+ is not an absolute +http+ or
42
+ # +https+ URL with a host, or +proxy+ is not a valid proxy URL, +URI+ or proxy hash (an empty
43
+ # host or blank +proxy_addr+ is not valid), has a proxy URL scheme other than +http+ or
44
+ # +https+, or is an +https+ proxy that cannot be used (see +proxy+).
34
45
  def initialize(admin_key, server_url: nil, headers: {}, max_retries: 5, timeout: 10, # rubocop:disable Metrics/ParameterLists
35
46
  proxy: nil, send_platform_info: true, app_info: nil, http_client_options: nil,
36
47
  logger: nil)
@@ -92,9 +103,11 @@ module DeepL
92
103
  ##
93
104
  # Creates a developer key. The API uses "DeepL API Key" as label if none is given.
94
105
  #
95
- # Creation is retried only after failures that show the request was not processed (HTTP 429,
96
- # DNS resolution errors, refused connections and connection timeouts), so that a retry
97
- # cannot create a second key. The raised error has +should_retry?+ true only for these.
106
+ # Creation is retried only after failures that show the request was not processed (HTTP 429 and
107
+ # transient network failures while connecting, such as DNS resolution errors, refused
108
+ # connections, unreachable hosts or networks, connection timeouts and resets during the TLS or
109
+ # proxy handshake), so that a retry cannot create a second key. The raised error has
110
+ # +should_retry?+ true for these and for a response body cut off mid-read, which is not retried.
98
111
  #
99
112
  # @param [String, nil] label Label for the new key, not sent if +nil+.
100
113
  # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
@@ -148,17 +161,29 @@ module DeepL
148
161
  # @param [Hash] limits Limits to change: +:characters+ (characters per usage period across
149
162
  # text translation, document translation and text improvement),
150
163
  # +:speech_to_text_milliseconds+ and +:speech_to_speech_milliseconds+, each an +Integer+ or
151
- # +nil+. They are sent as is and validated by the API.
164
+ # +nil+. The values are sent as given and validated by the API.
152
165
  # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
153
166
  # of the same name. Values are sent as given.
154
167
  # @return [DeepL::Resources::DeveloperKey]
155
- # @raise [ArgumentError] If the key ID is empty.
168
+ # @raise [ArgumentError] If the key ID is empty, or +limits+ has a keyword other than
169
+ # +:characters+, +:speech_to_text_milliseconds+ and +:speech_to_speech_milliseconds+.
156
170
  def set_developer_key_usage_limits(key, extra_body_parameters: nil, **limits)
157
- update_developer_key('limits', limits.merge(key_id: key_id(key)), extra_body_parameters)
171
+ id = key_id(key)
172
+ validate_usage_limits!(limits)
173
+ update_developer_key('limits', limits.merge(key_id: id), extra_body_parameters)
158
174
  end
159
175
 
160
176
  private
161
177
 
178
+ def validate_usage_limits!(limits)
179
+ unknown = limits.keys - USAGE_LIMITS
180
+ return if unknown.empty?
181
+
182
+ names = unknown.map { |name| "`#{name}`" }.join(', ')
183
+ raise ArgumentError, "Unknown usage limit#{'s' if unknown.size > 1} #{names}; use " \
184
+ '`extra_body_parameters` to send fields the SDK does not model'
185
+ end
186
+
162
187
  attr_reader :api
163
188
 
164
189
  def configuration
data/lib/deepl/api.rb CHANGED
@@ -4,15 +4,13 @@
4
4
  # frozen_string_literal: true
5
5
 
6
6
  module DeepL
7
+ # The configuration and HTTP connection of one DeepL::Client or DeepL::AdminClient.
8
+ # @api private
7
9
  class API
8
10
  attr_reader :configuration, :http_client, :http_client_options
9
11
 
10
- # +client:+ is true for the API of a DeepL::Client or DeepL::AdminClient, whose errors differ
11
- # from those of the module-level API until the next major version. @api private
12
- def initialize(configuration, http_client_options = nil, client: false)
12
+ def initialize(configuration, http_client_options = nil)
13
13
  @configuration = configuration
14
- @client = client
15
- configuration.validate!
16
14
  @http_client_options = http_client_options
17
15
  @http_client = if http_client_options
18
16
  Utils::HTTPClientBuilder.build(configuration.host, http_client_options)
@@ -21,18 +19,6 @@ module DeepL
21
19
  end
22
20
  end
23
21
 
24
- # @api private
25
- def client?
26
- @client
27
- end
28
-
29
- # +options+ are the HTTPClientOptions the client was built with; their timeouts take
30
- # precedence over the per-attempt timeout.
31
- def update_http_client(client, options = nil)
32
- @http_client = client
33
- @http_client_options = options
34
- end
35
-
36
22
  private
37
23
 
38
24
  # Without explicit options Net::HTTP applies the proxy from the environment (+http_proxy+).
@@ -11,7 +11,6 @@ module DeepL
11
11
  def self.from(value)
12
12
  return nil if value.nil?
13
13
  return value if value.is_a?(AppInfo)
14
- raise ArgumentError, 'app_info must be a DeepL::AppInfo or a Hash' unless value.is_a?(Hash)
15
14
 
16
15
  new(app_name: value[:app_name] || value['app_name'],
17
16
  app_version: value[:app_version] || value['app_version'])