deepl-rb 3.9.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 (215) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -1
  3. data/CHANGELOG.md +741 -18
  4. data/Gemfile +4 -0
  5. data/README.md +1001 -327
  6. data/Rakefile +29 -7
  7. data/VERSION +1 -1
  8. data/deepl-rb.gemspec +75 -88
  9. data/lib/deepl/admin_client.rb +208 -0
  10. data/lib/deepl/api.rb +18 -8
  11. data/lib/deepl/app_info.rb +19 -0
  12. data/lib/deepl/client.rb +1284 -0
  13. data/lib/deepl/configuration.rb +27 -32
  14. data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
  15. data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
  16. data/lib/deepl/constants/document_status_code.rb +17 -0
  17. data/lib/deepl/constants/language_include.rb +17 -0
  18. data/lib/deepl/constants/language_resource_name.rb +21 -0
  19. data/lib/deepl/constants/tag_handling_version.rb +14 -0
  20. data/lib/deepl/exceptions/authorization_failed.rb +1 -1
  21. data/lib/deepl/exceptions/bad_request.rb +1 -3
  22. data/lib/deepl/exceptions/connection_error.rb +40 -0
  23. data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
  24. data/lib/deepl/exceptions/document_translation_error.rb +17 -1
  25. data/lib/deepl/exceptions/error.rb +13 -1
  26. data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
  27. data/lib/deepl/exceptions/not_found.rb +8 -3
  28. data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
  29. data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
  30. data/lib/deepl/exceptions/request_error.rb +26 -2
  31. data/lib/deepl/exceptions/server_error.rb +9 -2
  32. data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
  33. data/lib/deepl/exceptions/validation_error.rb +15 -0
  34. data/lib/deepl/requests/admin/base.rb +94 -0
  35. data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
  36. data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
  37. data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
  38. data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
  39. data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
  40. data/lib/deepl/requests/base.rb +313 -65
  41. data/lib/deepl/requests/correct.rb +51 -0
  42. data/lib/deepl/requests/document/download.rb +11 -3
  43. data/lib/deepl/requests/document/get_status.rb +2 -2
  44. data/lib/deepl/requests/document/upload.rb +56 -20
  45. data/lib/deepl/requests/glossary/base.rb +30 -0
  46. data/lib/deepl/requests/glossary/create.rb +18 -18
  47. data/lib/deepl/requests/glossary/destroy.rb +4 -16
  48. data/lib/deepl/requests/glossary/entries.rb +6 -14
  49. data/lib/deepl/requests/glossary/find.rb +3 -13
  50. data/lib/deepl/requests/glossary/language_pairs.rb +22 -6
  51. data/lib/deepl/requests/glossary/list.rb +2 -2
  52. data/lib/deepl/requests/language_resources.rb +41 -0
  53. data/lib/deepl/requests/languages.rb +25 -6
  54. data/lib/deepl/requests/languages_for_resource.rb +56 -0
  55. data/lib/deepl/requests/multilingual_glossary/create.rb +45 -0
  56. data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
  57. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +55 -0
  58. data/lib/deepl/requests/multilingual_glossary/entries.rb +68 -0
  59. data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
  60. data/lib/deepl/requests/multilingual_glossary/helpers.rb +71 -0
  61. data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
  62. data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
  63. data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
  64. data/lib/deepl/requests/rephrase.rb +8 -10
  65. data/lib/deepl/requests/spoken_terms/create.rb +42 -0
  66. data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
  67. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +42 -0
  68. data/lib/deepl/requests/spoken_terms/entries.rb +47 -0
  69. data/lib/deepl/requests/spoken_terms/find.rb +35 -0
  70. data/lib/deepl/requests/spoken_terms/helpers.rb +74 -0
  71. data/lib/deepl/requests/spoken_terms/list.rb +35 -0
  72. data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
  73. data/lib/deepl/requests/spoken_terms/update.rb +40 -0
  74. data/lib/deepl/requests/style_profile/base.rb +83 -0
  75. data/lib/deepl/requests/style_profile/create.rb +40 -0
  76. data/lib/deepl/requests/style_profile/destroy.rb +34 -0
  77. data/lib/deepl/requests/style_profile/find.rb +33 -0
  78. data/lib/deepl/requests/style_profile/list.rb +43 -0
  79. data/lib/deepl/requests/style_profile/update.rb +35 -0
  80. data/lib/deepl/requests/style_rule/create.rb +24 -0
  81. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +11 -2
  82. data/lib/deepl/requests/style_rule/destroy.rb +4 -2
  83. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
  84. data/lib/deepl/requests/style_rule/find.rb +4 -2
  85. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
  86. data/lib/deepl/requests/style_rule/helpers.rb +44 -0
  87. data/lib/deepl/requests/style_rule/list.rb +3 -1
  88. data/lib/deepl/requests/style_rule/update.rb +5 -2
  89. data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
  90. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +7 -3
  91. data/lib/deepl/requests/translate.rb +43 -27
  92. data/lib/deepl/requests/translation_memory/base.rb +1 -4
  93. data/lib/deepl/requests/translation_memory/create_export.rb +7 -2
  94. data/lib/deepl/requests/translation_memory/create_import.rb +11 -1
  95. data/lib/deepl/requests/translation_memory/destroy.rb +1 -1
  96. data/lib/deepl/requests/translation_memory/find.rb +1 -1
  97. data/lib/deepl/requests/translation_memory/find_job.rb +1 -1
  98. data/lib/deepl/requests/translation_memory/list.rb +4 -3
  99. data/lib/deepl/requests/translation_memory/segments.rb +5 -4
  100. data/lib/deepl/requests/translation_memory/storage_base.rb +37 -9
  101. data/lib/deepl/requests/translation_memory/upload_file.rb +1 -1
  102. data/lib/deepl/requests/usage.rb +28 -1
  103. data/lib/deepl/requests/write_improvements.rb +42 -0
  104. data/lib/deepl/resources/admin_usage_report.rb +73 -0
  105. data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
  106. data/lib/deepl/resources/developer_key.rb +57 -0
  107. data/lib/deepl/resources/document_handle.rb +8 -34
  108. data/lib/deepl/resources/document_translation_status.rb +14 -7
  109. data/lib/deepl/resources/language.rb +5 -3
  110. data/lib/deepl/resources/language_resource.rb +57 -0
  111. data/lib/deepl/resources/language_support.rb +56 -0
  112. data/lib/deepl/resources/multilingual_glossary.rb +112 -0
  113. data/lib/deepl/resources/spoken_terms.rb +61 -0
  114. data/lib/deepl/resources/style_profile.rb +44 -0
  115. data/lib/deepl/resources/style_rule.rb +4 -23
  116. data/lib/deepl/resources/text.rb +18 -2
  117. data/lib/deepl/resources/translation_memory.rb +8 -2
  118. data/lib/deepl/resources/translation_memory_import.rb +1 -1
  119. data/lib/deepl/resources/translation_memory_job.rb +26 -7
  120. data/lib/deepl/resources/translation_memory_segments.rb +8 -6
  121. data/lib/deepl/resources/usage.rb +61 -5
  122. data/lib/deepl/utils/client_builder.rb +89 -0
  123. data/lib/deepl/utils/document_poller.rb +70 -0
  124. data/lib/deepl/utils/exception_builder.rb +3 -2
  125. data/lib/deepl/utils/glossary_entries.rb +30 -0
  126. data/lib/deepl/utils/http_client_builder.rb +116 -0
  127. data/lib/deepl/utils/number_parser.rb +34 -0
  128. data/lib/deepl/utils/output_path.rb +25 -0
  129. data/lib/deepl/utils/term_validator.rb +33 -0
  130. data/lib/deepl/utils/time_parser.rb +14 -0
  131. data/lib/deepl/utils/translation_memory_operations.rb +230 -0
  132. data/lib/deepl.rb +68 -108
  133. data/lib/http_client_options.rb +21 -1
  134. data/lib/version.rb +1 -1
  135. data/upgrading_to_v4.md +374 -0
  136. metadata +84 -85
  137. data/.circleci/config.yml +0 -27
  138. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  139. data/.gitlab-ci.yml +0 -179
  140. data/lib/deepl/document_api.rb +0 -131
  141. data/lib/deepl/exceptions/not_supported.rb +0 -14
  142. data/lib/deepl/glossary_api.rb +0 -38
  143. data/lib/deepl/style_rule_api.rb +0 -61
  144. data/lib/deepl/translation_memory_api.rb +0 -309
  145. data/license_checker.sh +0 -8
  146. data/spec/api/api_spec.rb +0 -20
  147. data/spec/api/configuration_spec.rb +0 -122
  148. data/spec/api/deepl_spec.rb +0 -262
  149. data/spec/constants/constants_spec.rb +0 -158
  150. data/spec/integration_tests/document_api_spec.rb +0 -211
  151. data/spec/integration_tests/document_error_paths_spec.rb +0 -33
  152. data/spec/integration_tests/glossary_api_spec.rb +0 -114
  153. data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
  154. data/spec/integration_tests/integration_test_utils.rb +0 -178
  155. data/spec/integration_tests/languages_api_spec.rb +0 -54
  156. data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
  157. data/spec/integration_tests/rephrase_api_spec.rb +0 -90
  158. data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
  159. data/spec/integration_tests/smoke_test_spec.rb +0 -24
  160. data/spec/integration_tests/style_rule_api_spec.rb +0 -117
  161. data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
  162. data/spec/integration_tests/translate_api_spec.rb +0 -117
  163. data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
  164. data/spec/integration_tests/translation_memory_api_spec.rb +0 -244
  165. data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -87
  166. data/spec/integration_tests/usage_api_spec.rb +0 -29
  167. data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
  168. data/spec/requests/document/upload_spec.rb +0 -130
  169. data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
  170. data/spec/requests/glossary/create_spec.rb +0 -44
  171. data/spec/requests/glossary/destroy_spec.rb +0 -27
  172. data/spec/requests/glossary/entries_spec.rb +0 -27
  173. data/spec/requests/glossary/find_spec.rb +0 -28
  174. data/spec/requests/glossary/language_pairs_spec.rb +0 -27
  175. data/spec/requests/glossary/list_spec.rb +0 -27
  176. data/spec/requests/languages_spec.rb +0 -27
  177. data/spec/requests/rephrase_spec.rb +0 -46
  178. data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
  179. data/spec/requests/style_rule/create_spec.rb +0 -29
  180. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
  181. data/spec/requests/style_rule/destroy_spec.rb +0 -27
  182. data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
  183. data/spec/requests/style_rule/find_spec.rb +0 -28
  184. data/spec/requests/style_rule/list_spec.rb +0 -27
  185. data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
  186. data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
  187. data/spec/requests/style_rule/update_spec.rb +0 -29
  188. data/spec/requests/translate_spec.rb +0 -338
  189. data/spec/requests/translation_memory/create_export_spec.rb +0 -37
  190. data/spec/requests/translation_memory/create_import_spec.rb +0 -61
  191. data/spec/requests/translation_memory/destroy_spec.rb +0 -36
  192. data/spec/requests/translation_memory/download_export_spec.rb +0 -54
  193. data/spec/requests/translation_memory/find_job_spec.rb +0 -37
  194. data/spec/requests/translation_memory/find_spec.rb +0 -36
  195. data/spec/requests/translation_memory/list_spec.rb +0 -27
  196. data/spec/requests/translation_memory/segments_spec.rb +0 -58
  197. data/spec/requests/translation_memory/upload_file_spec.rb +0 -55
  198. data/spec/requests/usage_spec.rb +0 -27
  199. data/spec/resources/custom_instruction_spec.rb +0 -32
  200. data/spec/resources/glossary_spec.rb +0 -38
  201. data/spec/resources/language_pair_spec.rb +0 -23
  202. data/spec/resources/language_spec.rb +0 -45
  203. data/spec/resources/style_rule_spec.rb +0 -68
  204. data/spec/resources/text_spec.rb +0 -23
  205. data/spec/resources/translation_memory_export_spec.rb +0 -38
  206. data/spec/resources/translation_memory_import_spec.rb +0 -30
  207. data/spec/resources/translation_memory_job_spec.rb +0 -109
  208. data/spec/resources/translation_memory_segments_spec.rb +0 -78
  209. data/spec/resources/translation_memory_spec.rb +0 -52
  210. data/spec/resources/usage_spec.rb +0 -35
  211. data/spec/spec_helper.rb +0 -62
  212. data/spec/support/live_mock_server.rb +0 -12
  213. data/spec/support/managed_glossary.rb +0 -65
  214. data/spec/support/managed_style_rule.rb +0 -17
  215. data/spec/support/managed_translation_memory.rb +0 -55
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,11 +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 '.devcontainer/**/*'
38
- gem.files.exclude '.github'
39
- gem.files.exclude '.circleci'
40
- gem.files.exclude 'catalog-info.yaml'
52
+ gem.files.exclude(*GEM_FILES_EXCLUDE)
41
53
  end
42
54
 
43
55
  Juwelier::RubygemsDotOrgTasks.new
@@ -47,9 +59,19 @@ require 'rspec/core/rake_task'
47
59
  require 'rubocop/rake_task'
48
60
 
49
61
  RuboCop::RakeTask.new
50
- RSpec::Core::RakeTask.new(:spec)
51
62
 
52
- desc 'Run all tests.'
63
+ namespace :spec do
64
+ desc 'Run the offline specs: no network, no key.'
65
+ RSpec::Core::RakeTask.new(:offline) { |task| task.pattern = 'spec/offline/**/*_spec.rb' }
66
+
67
+ desc 'Run the real-API specs: needs DEEPL_AUTH_KEY, sends real requests.'
68
+ RSpec::Core::RakeTask.new(:real_api) { |task| task.pattern = 'spec/real_api/**/*_spec.rb' }
69
+ end
70
+
71
+ desc 'Run the offline specs.'
72
+ task spec: 'spec:offline'
73
+
74
+ desc 'Run the offline specs and rubocop.'
53
75
  task :test do
54
76
  Rake::Task['spec'].invoke
55
77
  Rake::Task['rubocop'].invoke
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.9.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.9.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.9.0"
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-12"
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.4.10".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
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
198
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
183
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
184
+ s.add_development_dependency(%q<git>.freeze, ["< 6".freeze])
185
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
199
186
  end
200
187
 
@@ -0,0 +1,208 @@
1
+ # Copyright 2026 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ ##
8
+ # Client for the DeepL Admin API, used to manage the developer keys of your organization and
9
+ # to retrieve usage analytics. It owns its configuration and reads no environment variables.
10
+ #
11
+ # All methods may raise a +DeepL::Exceptions::Error+ or a subclass, for example
12
+ # +DeepL::Exceptions::AuthorizationFailed+ if the admin key is not accepted.
13
+ class AdminClient
14
+ DEEPL_SERVER_URL = 'https://api.deepl.com'
15
+ private_constant :DEEPL_SERVER_URL
16
+
17
+ USAGE_LIMITS = %i[characters speech_to_text_milliseconds speech_to_speech_milliseconds].freeze
18
+ private_constant :USAGE_LIMITS
19
+
20
+ ##
21
+ # A keyword argument given as +nil+ takes its default, like an omitted one.
22
+ # @param [String] admin_key Admin API key, surrounding whitespace is removed.
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
25
+ # +https://api.deepl.com+ (also for keys ending in +:fx+).
26
+ # @param [Hash] headers HTTP headers sent with every request. A header of the same name in
27
+ # any casing replaces the library's, +Authorization+ and +User-Agent+ included, except the
28
+ # technical headers +Content-Type+, +Content-Length+, +Transfer-Encoding+ and +Host+.
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.
37
+ # @param [DeepL::AppInfo, Hash, nil] app_info Your application's +app_name+ and
38
+ # +app_version+, added to the +User-Agent+.
39
+ # @param [DeepL::HTTPClientOptions, nil] http_client_options Proxy, SSL and timeout options.
40
+ # @param [Logger, nil] logger Logger for requests and retries.
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+).
45
+ def initialize(admin_key, server_url: nil, headers: {}, max_retries: 5, timeout: 10, # rubocop:disable Metrics/ParameterLists
46
+ proxy: nil, send_platform_info: true, app_info: nil, http_client_options: nil,
47
+ logger: nil)
48
+ @api = Utils::ClientBuilder.build_api(
49
+ admin_key, key_name: 'admin_key', server_url: server_url,
50
+ default_server_url: DEEPL_SERVER_URL, headers: headers,
51
+ max_retries: max_retries, timeout: timeout, proxy: proxy,
52
+ send_platform_info: send_platform_info, app_info: app_info,
53
+ http_client_options: http_client_options, logger: logger
54
+ )
55
+ end
56
+
57
+ def inspect
58
+ "#<#{self.class.name} server_url=#{configuration.host}>"
59
+ end
60
+
61
+ ##
62
+ # Retrieves the usage of the organization within a date range. The API requires the start date
63
+ # to be before the end date (a report covers at least two days) and the range to be at most
64
+ # 366 days.
65
+ #
66
+ # @param [Date, Time, DateTime, String] start_date Start date, as a +Date+, a +Time+, a
67
+ # +DateTime+ or a +YYYY-MM-DD+ string. Dates are UTC calendar days and both the start and
68
+ # the end day are included. For +Time+ and +DateTime+ values the UTC date of that moment is
69
+ # sent: +2026-10-20 00:00 +02:00+ is sent as +2026-10-19+.
70
+ # @param [Date, Time, DateTime, String] end_date End date, in the same format as +start_date+.
71
+ # @param [String, Symbol, nil] group_by Group the usage by key or by key and day, see
72
+ # +DeepL::Constants::AdminUsageGroupBy+ for the accepted values. It is sent as is, and the
73
+ # +group_by+ of the report is the raw string the API returns.
74
+ # @return [DeepL::Resources::AdminUsageReport]
75
+ # @raise [ArgumentError] If a date is invalid.
76
+ # @raise [DeepL::Exceptions::BadRequest] If the API rejects the date range.
77
+ def get_usage_analytics(start_date, end_date, group_by: nil)
78
+ Requests::Admin::UsageAnalytics.new(api, start_date, end_date, group_by).request
79
+ end
80
+
81
+ ##
82
+ # Retrieves the usage per custom tag within a date range, with the same limits as
83
+ # +get_usage_analytics+. Results are paginated: pass the +next_page+ of a report as +page+ to
84
+ # retrieve the following page.
85
+ #
86
+ # @param [Date, Time, DateTime, String] start_date Start date, as a +Date+, a +Time+, a
87
+ # +DateTime+ or a +YYYY-MM-DD+ string. Dates are UTC calendar days and both the start and
88
+ # the end day are included. For +Time+ and +DateTime+ values the UTC date of that moment is
89
+ # sent: +2026-10-20 00:00 +02:00+ is sent as +2026-10-19+.
90
+ # @param [Date, Time, DateTime, String] end_date End date, in the same format as +start_date+.
91
+ # @param [String, Symbol, nil] aggregate_by Aggregate the usage over the whole period or by
92
+ # day, see +DeepL::Constants::CustomTagUsageAggregateBy+. It is sent as is, and the
93
+ # +aggregate_by+ of the report is the raw string the API returns.
94
+ # @param [Integer, nil] page Page number to retrieve.
95
+ # @return [DeepL::Resources::CustomTagUsageReport]
96
+ # @raise [ArgumentError] If a date is invalid.
97
+ # @raise [DeepL::Exceptions::BadRequest] If the API rejects the date range.
98
+ def get_custom_tag_usage_analytics(start_date, end_date, aggregate_by: nil, page: nil)
99
+ Requests::Admin::CustomTagUsageAnalytics.new(api, start_date, end_date, aggregate_by,
100
+ page).request
101
+ end
102
+
103
+ ##
104
+ # Creates a developer key. The API uses "DeepL API Key" as label if none is given.
105
+ #
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.
111
+ #
112
+ # @param [String, nil] label Label for the new key, not sent if +nil+.
113
+ # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
114
+ # of the same name. Values are sent as given.
115
+ # @return [DeepL::Resources::DeveloperKey]
116
+ def create_developer_key(label: nil, extra_body_parameters: nil)
117
+ Requests::Admin::CreateDeveloperKey.new(api, label, extra_body_parameters).request
118
+ end
119
+
120
+ ##
121
+ # Retrieves all developer keys of the organization, including deactivated ones.
122
+ #
123
+ # @return [Array<DeepL::Resources::DeveloperKey>]
124
+ def list_developer_keys
125
+ Requests::Admin::ListDeveloperKeys.new(api).request
126
+ end
127
+
128
+ ##
129
+ # Deactivates a developer key. Deactivation is permanent.
130
+ #
131
+ # @param [String, DeepL::Resources::DeveloperKey] key Key ID or developer key.
132
+ # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
133
+ # of the same name. Values are sent as given.
134
+ # @return [DeepL::Resources::DeveloperKey]
135
+ # @raise [ArgumentError] If the key ID is empty.
136
+ def deactivate_developer_key(key, extra_body_parameters: nil)
137
+ update_developer_key('deactivate', { key_id: key_id(key) }, extra_body_parameters)
138
+ end
139
+
140
+ ##
141
+ # Changes the label of a developer key.
142
+ #
143
+ # @param [String, DeepL::Resources::DeveloperKey] key Key ID or developer key.
144
+ # @param [String] label New label for the key.
145
+ # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
146
+ # of the same name. Values are sent as given.
147
+ # @return [DeepL::Resources::DeveloperKey]
148
+ # @raise [ArgumentError] If the key ID is empty.
149
+ def rename_developer_key(key, label, extra_body_parameters: nil)
150
+ update_developer_key('label', { key_id: key_id(key), label: label }, extra_body_parameters)
151
+ end
152
+
153
+ ##
154
+ # Changes the usage limits of a developer key. Only the given limits are changed; omitted
155
+ # limits keep their current value. A +nil+ limit means unlimited and +0+ blocks that usage.
156
+ #
157
+ # admin_client.set_developer_key_usage_limits(key, characters: 0)
158
+ # admin_client.set_developer_key_usage_limits(key, speech_to_text_milliseconds: nil)
159
+ #
160
+ # @param [String, DeepL::Resources::DeveloperKey] key Key ID or developer key.
161
+ # @param [Hash] limits Limits to change: +:characters+ (characters per usage period across
162
+ # text translation, document translation and text improvement),
163
+ # +:speech_to_text_milliseconds+ and +:speech_to_speech_milliseconds+, each an +Integer+ or
164
+ # +nil+. The values are sent as given and validated by the API.
165
+ # @param [Hash, nil] extra_body_parameters Added to the request body last; replaces fields
166
+ # of the same name. Values are sent as given.
167
+ # @return [DeepL::Resources::DeveloperKey]
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+.
170
+ def set_developer_key_usage_limits(key, extra_body_parameters: nil, **limits)
171
+ id = key_id(key)
172
+ validate_usage_limits!(limits)
173
+ update_developer_key('limits', limits.merge(key_id: id), extra_body_parameters)
174
+ end
175
+
176
+ private
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
+
187
+ attr_reader :api
188
+
189
+ def configuration
190
+ api.configuration
191
+ end
192
+
193
+ def update_developer_key(action, payload, extra_body_parameters)
194
+ Requests::Admin::UpdateDeveloperKey.new(api, action, payload, extra_body_parameters).request
195
+ end
196
+
197
+ def key_id(key)
198
+ id = key.is_a?(Resources::DeveloperKey) ? key.key_id : key
199
+ raise ArgumentError, 'key ID must not be empty' if blank?(id)
200
+
201
+ id
202
+ end
203
+
204
+ def blank?(value)
205
+ value.nil? || value.to_s.strip.empty?
206
+ end
207
+ end
208
+ end
data/lib/deepl/api.rb CHANGED
@@ -4,19 +4,29 @@
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
- attr_reader :configuration, :http_client
10
+ attr_reader :configuration, :http_client, :http_client_options
9
11
 
10
- def initialize(configuration)
12
+ def initialize(configuration, http_client_options = nil)
11
13
  @configuration = configuration
12
- configuration.validate!
13
- uri = URI(configuration.host)
14
- @http_client = Net::HTTP.new(uri.host, uri.port)
15
- @http_client.use_ssl = uri.scheme == 'https'
14
+ @http_client_options = http_client_options
15
+ @http_client = if http_client_options
16
+ Utils::HTTPClientBuilder.build(configuration.host, http_client_options)
17
+ else
18
+ default_http_client(configuration.host)
19
+ end
16
20
  end
17
21
 
18
- def update_http_client(client)
19
- @http_client = client
22
+ private
23
+
24
+ # Without explicit options Net::HTTP applies the proxy from the environment (+http_proxy+).
25
+ def default_http_client(host)
26
+ uri = URI(host)
27
+ client = Net::HTTP.new(uri.host, uri.port)
28
+ client.use_ssl = uri.scheme == 'https'
29
+ Utils::HTTPClientBuilder.disable_lenient_defaults(client)
20
30
  end
21
31
  end
22
32
  end
@@ -0,0 +1,19 @@
1
+ # Copyright 2026 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ ##
8
+ # Identifies your application in the +User-Agent+ header as +<app_name>/<app_version>+.
9
+ AppInfo = Struct.new(:app_name, :app_version, keyword_init: true) do
10
+ # Accepts an AppInfo or a hash with +:app_name+ and +:app_version+.
11
+ def self.from(value)
12
+ return nil if value.nil?
13
+ return value if value.is_a?(AppInfo)
14
+
15
+ new(app_name: value[:app_name] || value['app_name'],
16
+ app_version: value[:app_version] || value['app_version'])
17
+ end
18
+ end
19
+ end