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
@@ -0,0 +1,36 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class Destroy < Base
10
+ include Helpers
11
+
12
+ attr_reader :id
13
+
14
+ def initialize(api, id, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ end
18
+
19
+ def request
20
+ execute_request_with_retries(delete_request)
21
+ nil
22
+ end
23
+
24
+ def to_s
25
+ "DELETE #{uri.request_uri}"
26
+ end
27
+
28
+ private
29
+
30
+ def path
31
+ glossary_path(id)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,55 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class DestroyDictionary < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :source_lang, :target_lang
13
+
14
+ def initialize(api, id, source_lang, target_lang, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ if source_lang.to_s.empty? || target_lang.to_s.empty?
18
+ raise ArgumentError, 'source_lang and target_lang must not be empty'
19
+ end
20
+
21
+ @source_lang = source_lang
22
+ @target_lang = target_lang
23
+ end
24
+
25
+ def request
26
+ execute_request_with_retries(delete_request)
27
+ nil
28
+ end
29
+
30
+ def to_s
31
+ "DELETE #{uri.request_uri}"
32
+ end
33
+
34
+ private
35
+
36
+ def delete_request
37
+ http_headers = add_json_content_type(headers)
38
+ Net::HTTP::Delete.new(uri.request_uri, http_headers)
39
+ end
40
+
41
+ def uri
42
+ @uri ||= begin
43
+ base_uri = URI("#{host}/v3/#{path}")
44
+ base_uri.query = encode_query(source_lang: source_lang, target_lang: target_lang)
45
+ base_uri
46
+ end
47
+ end
48
+
49
+ def path
50
+ glossary_path(id, 'dictionaries')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,68 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class Entries < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :source_lang, :target_lang
13
+
14
+ def initialize(api, id, source_lang, target_lang, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ validate_dictionary_languages!(source_lang, target_lang)
18
+ @source_lang = source_lang
19
+ @target_lang = target_lang
20
+ end
21
+
22
+ def request
23
+ build_entries(*execute_request_with_retries(get_request))
24
+ end
25
+
26
+ def to_s
27
+ "GET #{uri.request_uri}"
28
+ end
29
+
30
+ private
31
+
32
+ def get_request # rubocop:disable Naming/AccessorMethodName
33
+ http_headers = add_json_content_type(headers)
34
+ Net::HTTP::Get.new(uri.request_uri, http_headers)
35
+ end
36
+
37
+ # The API wraps the dictionary in a list and answers a missing dictionary with 404. If it
38
+ # answers 200 with an empty list instead, that is no failed response, so the NotFound
39
+ # carries none and has no HTTP status.
40
+ def build_entries(request, response)
41
+ dictionary = (JSON.parse(response.body)['dictionaries'] || []).first
42
+ if dictionary.nil?
43
+ raise Exceptions::NotFound.new(
44
+ nil, request,
45
+ "Glossary #{id} has no dictionary for #{source_lang} -> #{target_lang}"
46
+ )
47
+ end
48
+
49
+ Resources::MultilingualGlossaryDictionaryEntries.from_response(
50
+ dictionary, request, response
51
+ )
52
+ end
53
+
54
+ def uri
55
+ @uri ||= begin
56
+ base_uri = URI("#{host}/v3/#{path}")
57
+ base_uri.query = encode_query(source_lang: source_lang, target_lang: target_lang)
58
+ base_uri
59
+ end
60
+ end
61
+
62
+ def path
63
+ glossary_path(id, 'entries')
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,35 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class Find < Base
10
+ include Helpers
11
+
12
+ attr_reader :id
13
+
14
+ def initialize(api, id, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ end
18
+
19
+ def request
20
+ build_glossary(*execute_request_with_retries(get_request))
21
+ end
22
+
23
+ def to_s
24
+ "GET #{uri.request_uri}"
25
+ end
26
+
27
+ private
28
+
29
+ def path
30
+ glossary_path(id)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,71 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ # Encoding shared by the v3 glossary requests.
10
+ module Helpers
11
+ private
12
+
13
+ def glossary_id(glossary)
14
+ id = glossary.is_a?(DeepL::Resources::MultilingualGlossary) ? glossary.id : glossary
15
+ raise ArgumentError, 'Glossary ID must not be empty' if id.to_s.empty?
16
+
17
+ id.to_s
18
+ end
19
+
20
+ # The path of a glossary, with its ID URL-encoded.
21
+ def glossary_path(id, suffix = nil)
22
+ ["glossaries/#{escape_path_segment(id)}", suffix].compact.join('/')
23
+ end
24
+
25
+ # Accepts a MultilingualGlossaryDictionaryEntries object or a hash with +:source_lang+,
26
+ # +:target_lang+, +:entries+ and optionally +:entries_format+ (default +tsv+). Only a CSV
27
+ # string is sent as CSV; all other entries are converted and sent as TSV.
28
+ def dictionary_payload(dictionary)
29
+ if dictionary.is_a?(DeepL::Resources::MultilingualGlossaryDictionaryEntries)
30
+ return entries_object_payload(dictionary)
31
+ end
32
+
33
+ value = ->(key) { dictionary[key] || dictionary[key.to_s] }
34
+ validate_dictionary_languages!(value.call(:source_lang), value.call(:target_lang))
35
+ entries = value.call(:entries)
36
+ # CSV content is sent as given; TSV content is parsed so its terms are checked too.
37
+ csv = value.call(:entries_format) == 'csv' && entries.is_a?(String)
38
+ { source_lang: value.call(:source_lang), target_lang: value.call(:target_lang),
39
+ entries: csv ? entries : non_empty_tsv(entries),
40
+ entries_format: csv ? 'csv' : 'tsv' }
41
+ end
42
+
43
+ def entries_object_payload(dictionary)
44
+ validate_dictionary_languages!(dictionary.source_lang, dictionary.target_lang)
45
+ { source_lang: dictionary.source_lang, target_lang: dictionary.target_lang,
46
+ entries: non_empty_tsv(dictionary.entries), entries_format: 'tsv' }
47
+ end
48
+
49
+ def validate_dictionary_languages!(source_lang, target_lang)
50
+ validate_language!('source_lang', source_lang)
51
+ validate_language!('target_lang', target_lang)
52
+ end
53
+
54
+ def non_empty_tsv(entries)
55
+ tsv = Utils::GlossaryEntries.to_tsv(entries || [])
56
+ raise ArgumentError, 'Glossary dictionary entries must not be empty' if tsv.empty?
57
+
58
+ tsv
59
+ end
60
+
61
+ def build_glossary(request, response)
62
+ Resources::MultilingualGlossary.new(JSON.parse(response.body), request, response)
63
+ end
64
+
65
+ def uri
66
+ @uri ||= URI("#{host}/v3/#{path}")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,39 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class List < Base
10
+ include Helpers
11
+
12
+ def initialize(api, options = {})
13
+ super
14
+ end
15
+
16
+ def request
17
+ build_glossary_list(*execute_request_with_retries(get_request))
18
+ end
19
+
20
+ def to_s
21
+ "GET #{uri.request_uri}"
22
+ end
23
+
24
+ private
25
+
26
+ def build_glossary_list(request, response)
27
+ data = JSON.parse(response.body)
28
+ data['glossaries'].map do |glossary|
29
+ Resources::MultilingualGlossary.new(glossary, request, response)
30
+ end
31
+ end
32
+
33
+ def path
34
+ 'glossaries'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class ReplaceDictionary < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :dictionary
13
+
14
+ def initialize(api, id, dictionary, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ @dictionary = dictionary_payload(dictionary)
18
+ end
19
+
20
+ def request
21
+ build_dictionary(*execute_request_with_retries(put_request(dictionary)))
22
+ end
23
+
24
+ def to_s
25
+ "PUT #{uri.request_uri}"
26
+ end
27
+
28
+ private
29
+
30
+ def build_dictionary(request, response)
31
+ data = JSON.parse(response.body)
32
+ Resources::MultilingualGlossaryDictionary.new(data, request, response)
33
+ end
34
+
35
+ def path
36
+ glossary_path(id, 'dictionaries')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
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
+ module Requests
8
+ module MultilingualGlossary
9
+ class Update < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :name, :dictionaries
13
+
14
+ def initialize(api, id, name, dictionaries, options = {})
15
+ super(api, options)
16
+ @id = glossary_id(id)
17
+ @name = name
18
+ @dictionaries = dictionaries&.map { |dictionary| dictionary_payload(dictionary) }
19
+ end
20
+
21
+ def request
22
+ payload = {}
23
+ payload[:name] = name unless name.nil?
24
+ payload[:dictionaries] = dictionaries unless dictionaries.nil?
25
+ build_glossary(*execute_request_with_retries(patch_request(payload)))
26
+ end
27
+
28
+ def to_s
29
+ "PATCH #{uri.request_uri}"
30
+ end
31
+
32
+ private
33
+
34
+ def path
35
+ glossary_path(id)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -6,6 +6,8 @@
6
6
  module DeepL
7
7
  module Requests
8
8
  class Rephrase < Base
9
+ include WriteImprovements
10
+
9
11
  attr_reader :text, :target_lang, :writing_style, :tone
10
12
 
11
13
  def initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}, # rubocop:disable Metrics/ParameterLists
@@ -15,6 +17,8 @@ module DeepL
15
17
  @target_lang = target_lang
16
18
  @writing_style = writing_style
17
19
  @tone = tone
20
+ validate_text!(text)
21
+ validate_optional_target_lang!(target_lang)
18
22
  end
19
23
 
20
24
  def request # rubocop:disable Metrics/AbcSize
@@ -27,8 +31,8 @@ module DeepL
27
31
  end
28
32
 
29
33
  def details
30
- "HTTP Headers: #{headers}\nPayload #{{ text: text, target_lang: target_lang,
31
- writing_style: writing_style, tone: tone }}"
34
+ "HTTP Headers: #{loggable_headers}\nPayload #{{ text: text, target_lang: target_lang,
35
+ writing_style: writing_style, tone: tone }}"
32
36
  end
33
37
 
34
38
  def to_s
@@ -38,14 +42,8 @@ module DeepL
38
42
  private
39
43
 
40
44
  def build_texts(request, response)
41
- data = JSON.parse(response.body)
42
-
43
- texts = data['improvements'].map do |improvement|
44
- Resources::Text.new(improvement['text'], improvement['detected_source_language'], nil,
45
- request, response)
46
- end
47
-
48
- texts.size == 1 ? texts.first : texts
45
+ texts = build_improvements(text.is_a?(Array) ? text.size : 1, request, response)
46
+ text.is_a?(Array) ? texts : texts.first
49
47
  end
50
48
 
51
49
  def path
@@ -0,0 +1,42 @@
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
+ module Requests
8
+ module SpokenTerms
9
+ class Create < Base
10
+ include Helpers
11
+
12
+ attr_reader :name, :term_lists
13
+
14
+ def initialize(api, name, term_lists, options = {})
15
+ super(api, options)
16
+ @name = name
17
+ @term_lists = term_lists
18
+ end
19
+
20
+ def request
21
+ payload = { name: name, term_lists: term_lists_payload(term_lists) }
22
+ build_spoken_terms(*execute_request_with_retries(post_request(payload)))
23
+ end
24
+
25
+ def to_s
26
+ "POST #{uri.request_uri}"
27
+ end
28
+
29
+ private
30
+
31
+ # A repeated creation request could create a second resource.
32
+ def retry_only_unprocessed?
33
+ true
34
+ end
35
+
36
+ def path
37
+ 'spoken-terms'
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
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
+ module Requests
8
+ module SpokenTerms
9
+ class Destroy < Base
10
+ include Helpers
11
+
12
+ attr_reader :id
13
+
14
+ def initialize(api, id)
15
+ super(api)
16
+ @id = spoken_terms_id(id)
17
+ end
18
+
19
+ def request
20
+ execute_request_with_retries(delete_request)
21
+ nil
22
+ end
23
+
24
+ def to_s
25
+ "DELETE #{uri.request_uri}"
26
+ end
27
+
28
+ private
29
+
30
+ def path
31
+ spoken_terms_path(id)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,42 @@
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
+ module Requests
8
+ module SpokenTerms
9
+ class DestroyTermList < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :lang
13
+
14
+ def initialize(api, id, lang)
15
+ super(api)
16
+ @id = spoken_terms_id(id)
17
+ validate_language!('lang', lang)
18
+ @lang = lang
19
+ end
20
+
21
+ def request
22
+ execute_request_with_retries(delete_request)
23
+ nil
24
+ end
25
+
26
+ def to_s
27
+ "DELETE #{uri.request_uri}"
28
+ end
29
+
30
+ private
31
+
32
+ def uri
33
+ @uri ||= URI("#{host}/v3/#{path}?#{encode_query(lang: lang)}")
34
+ end
35
+
36
+ def path
37
+ spoken_terms_path(id, 'term-lists')
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,47 @@
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
+ module Requests
8
+ module SpokenTerms
9
+ class Entries < Base
10
+ include Helpers
11
+
12
+ attr_reader :id, :lang
13
+
14
+ def initialize(api, id, lang)
15
+ super(api)
16
+ @id = spoken_terms_id(id)
17
+ validate_language!('lang', lang)
18
+ @lang = lang
19
+ end
20
+
21
+ def request
22
+ build_entries(*execute_request_with_retries(get_request))
23
+ end
24
+
25
+ def to_s
26
+ "GET #{uri.request_uri}"
27
+ end
28
+
29
+ private
30
+
31
+ def build_entries(request, response)
32
+ data = JSON.parse(response.body)
33
+ Resources::SpokenTermsEntries.new(data['lang'], entries_from_string(data['entries']),
34
+ request, response)
35
+ end
36
+
37
+ def uri
38
+ @uri ||= URI("#{host}/v3/#{path}?#{encode_query(lang: lang)}")
39
+ end
40
+
41
+ def path
42
+ spoken_terms_path(id, 'entries')
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
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
+ module Requests
8
+ module SpokenTerms
9
+ class Find < Base
10
+ include Helpers
11
+
12
+ attr_reader :id
13
+
14
+ def initialize(api, id)
15
+ super(api)
16
+ @id = spoken_terms_id(id)
17
+ end
18
+
19
+ def request
20
+ build_spoken_terms(*execute_request_with_retries(get_request))
21
+ end
22
+
23
+ def to_s
24
+ "GET #{uri.request_uri}"
25
+ end
26
+
27
+ private
28
+
29
+ def path
30
+ spoken_terms_path(id)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end