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
@@ -1,37 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::TranslationMemory::FindJob do
9
- subject(:translation_memory_find_job) { described_class.new(api, job_id, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:job_id) { '5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d' }
19
- let(:options) { {} }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(translation_memory_find_job).to be_a(described_class)
25
- end
26
- end
27
- end
28
-
29
- describe '#to_s' do
30
- context 'when building a request' do
31
- it 'requests the job below the v3 prefix' do
32
- expect(translation_memory_find_job.to_s)
33
- .to eq("GET /v3/translation_memories/jobs/#{job_id}")
34
- end
35
- end
36
- end
37
- end
@@ -1,36 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::TranslationMemory::Find do
9
- subject(:translation_memory_find) { described_class.new(api, id, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
19
- let(:options) { {} }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(translation_memory_find).to be_a(described_class)
25
- end
26
- end
27
- end
28
-
29
- describe '#to_s' do
30
- context 'when building a request' do
31
- it 'requests the translation memory below the v3 prefix' do
32
- expect(translation_memory_find.to_s).to eq("GET /v3/translation_memories/#{id}")
33
- end
34
- end
35
- end
36
- end
@@ -1,27 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::TranslationMemory::List do
9
- subject(:translation_memory_list) { described_class.new(api, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:options) { {} }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(translation_memory_list).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,58 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::TranslationMemory::Segments do
9
- subject(:translation_memory_segments) { described_class.new(api, id, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
19
- let(:options) { {} }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(translation_memory_segments).to be_a(described_class)
25
- end
26
- end
27
- end
28
-
29
- describe '#to_s' do
30
- context 'when no options are given' do
31
- it 'requests the segments below the v3 prefix without a query string' do
32
- expect(translation_memory_segments.to_s)
33
- .to eq("GET /v3/translation_memories/#{id}/segments")
34
- end
35
- end
36
-
37
- context 'when the supported options are given' do
38
- let(:options) { { page_size: 10, page_cursor: 'NQ', filter_case_sensitive: true } }
39
-
40
- it 'adds the options to the query string' do
41
- expect(translation_memory_segments.to_s)
42
- .to eq("GET /v3/translation_memories/#{id}/segments" \
43
- '?page_size=10&page_cursor=NQ&filter_case_sensitive=true')
44
- end
45
- end
46
-
47
- context 'when the text filter contains characters that must be escaped' do
48
- let(:options) { { filter_text: 'a b+c' } }
49
-
50
- # A space must be percent-encoded in a URI query string; `+` only means a space in a form
51
- # body, and a literal `+` has to survive as %2B.
52
- it 'percent-encodes the spaces instead of writing them as a plus' do
53
- expect(translation_memory_segments.to_s)
54
- .to eq("GET /v3/translation_memories/#{id}/segments?filter_text=a%20b%2Bc")
55
- end
56
- end
57
- end
58
- end
@@ -1,55 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::TranslationMemory::UploadFile do
9
- subject(:upload_file) { described_class.new(api, upload_url, file_content) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:upload_url) { 'https://storage.example.com/upload/tm?signature=abc' }
19
- let(:file_content) { '<tmx version="1.4"/>' }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(upload_file).to be_a(described_class)
25
- expect(upload_file.content_type).to eq(described_class::DEFAULT_CONTENT_TYPE)
26
- end
27
- end
28
-
29
- context 'when no upload URL is given' do
30
- let(:upload_url) { '' }
31
-
32
- it 'raises an error' do
33
- expect { upload_file }.to raise_error(DeepL::Exceptions::Error, /must not be empty/)
34
- end
35
- end
36
- end
37
-
38
- describe '#to_s' do
39
- context 'when building a request' do
40
- it 'puts to the pre-signed storage URL' do
41
- expect(upload_file.to_s).to eq('PUT /upload/tm?signature=abc')
42
- end
43
- end
44
- end
45
-
46
- describe '#details' do
47
- context 'when building a request' do
48
- # The upload URL points outside of the DeepL API, so the auth key must not be sent there.
49
- it 'does not send the DeepL authorization header' do
50
- expect(upload_file.details).not_to include('Authorization')
51
- expect(upload_file.details).to include('User-Agent')
52
- end
53
- end
54
- end
55
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Usage do
9
- subject(:usage_req) { described_class.new(api, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:options) { {} }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(usage_req).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,32 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::CustomInstruction do
9
- subject(:custom_instruction) do
10
- described_class.new({
11
- 'id' => 'ci-1',
12
- 'label' => 'Formal',
13
- 'prompt' => 'Always use formal language',
14
- 'source_language' => 'en'
15
- })
16
- end
17
-
18
- describe '#initialize' do
19
- context 'when building a basic object' do
20
- it 'creates a resource' do
21
- expect(custom_instruction).to be_a(described_class)
22
- end
23
-
24
- it 'assigns the attributes' do
25
- expect(custom_instruction.id).to eq('ci-1')
26
- expect(custom_instruction.label).to eq('Formal')
27
- expect(custom_instruction.prompt).to eq('Always use formal language')
28
- expect(custom_instruction.source_language).to eq('en')
29
- end
30
- end
31
- end
32
- end
@@ -1,38 +0,0 @@
1
- # Copyright 2022 Daniel Herzog
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::Glossary do
9
- subject(:glossary) do
10
- described_class.new({
11
- 'glossary_id' => 'def3a26b-3e84-45b3-84ae-0c0aaf3525f7',
12
- 'name' => 'Mein Glossar',
13
- 'ready' => true,
14
- 'source_lang' => 'EN',
15
- 'target_lang' => 'DE',
16
- 'creation_time' => '2021-08-03T14:16:18.329Z',
17
- 'entry_count' => 1
18
- }, nil, nil)
19
- end
20
-
21
- describe '#initialize' do
22
- context 'when building a basic object' do
23
- it 'creates a resource' do
24
- expect(glossary).to be_a(described_class)
25
- end
26
-
27
- it 'assigns the attributes' do
28
- expect(glossary.id).to eq('def3a26b-3e84-45b3-84ae-0c0aaf3525f7')
29
- expect(glossary.name).to eq('Mein Glossar')
30
- expect(glossary.ready).to be(true)
31
- expect(glossary.source_lang).to eq('EN')
32
- expect(glossary.target_lang).to eq('DE')
33
- expect(glossary.creation_time).to eq('2021-08-03T14:16:18.329Z')
34
- expect(glossary.entry_count).to eq(1)
35
- end
36
- end
37
- end
38
- end
@@ -1,23 +0,0 @@
1
- # Copyright 2022 Daniel Herzog
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::LanguagePair do
9
- subject(:language_pair) { described_class.new('en', 'de', nil, nil) }
10
-
11
- describe '#initialize' do
12
- context 'when building a basic object' do
13
- it 'creates a resource' do
14
- expect(language_pair).to be_a(described_class)
15
- end
16
-
17
- it 'assigns the attributes' do
18
- expect(language_pair.source_lang).to eq('en')
19
- expect(language_pair.target_lang).to eq('de')
20
- end
21
- end
22
- end
23
- end
@@ -1,45 +0,0 @@
1
- # Copyright 2021 Daniel Herzog
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::Language do
9
- subject(:language) { described_class.new('EN', 'English', nil, nil, nil) }
10
-
11
- describe '#initialize' do
12
- context 'when building a basic object' do
13
- it 'creates a resource' do
14
- expect(language).to be_a(described_class)
15
- end
16
-
17
- it 'assigns the attributes' do
18
- expect(language.code).to eq('EN')
19
- expect(language.name).to eq('English')
20
- end
21
-
22
- it 'does not define the supports formality method' do
23
- expect { language.supports_formality? }.to raise_error(DeepL::Exceptions::NotSupported)
24
- end
25
- end
26
-
27
- context 'when building a target language object' do
28
- subject(:language) { described_class.new('EN', 'English', true, nil, nil) }
29
-
30
- it 'creates a resource' do
31
- expect(language).to be_a(described_class)
32
- end
33
-
34
- it 'assigns the attributes' do
35
- expect(language.code).to eq('EN')
36
- expect(language.name).to eq('English')
37
- end
38
-
39
- it 'includes the supports formality method' do
40
- expect { language.supports_formality? }.not_to raise_error
41
- expect(language).to be_supports_formality
42
- end
43
- end
44
- end
45
- end
@@ -1,68 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::StyleRule do
9
- subject(:style_rule) do
10
- described_class.new({
11
- 'style_id' => 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4',
12
- 'name' => 'Default Style Rule',
13
- 'creation_time' => '2025-01-01T00:00:00Z',
14
- 'updated_time' => '2025-01-02T00:00:00Z',
15
- 'language' => 'en',
16
- 'version' => 1
17
- }, nil, nil)
18
- end
19
-
20
- describe '#initialize' do
21
- context 'when building a basic object' do
22
- it 'creates a resource' do
23
- expect(style_rule).to be_a(described_class)
24
- end
25
-
26
- it 'assigns the attributes' do
27
- expect(style_rule.style_id).to eq('dca2e053-8ae5-45e6-a0d2-881156e7f4e4')
28
- expect(style_rule.name).to eq('Default Style Rule')
29
- expect(style_rule.language).to eq('en')
30
- expect(style_rule.version).to eq(1)
31
- expect(style_rule.creation_time).to eq(Time.parse('2025-01-01T00:00:00Z'))
32
- expect(style_rule.updated_time).to eq(Time.parse('2025-01-02T00:00:00Z'))
33
- expect(style_rule.configured_rules).to be_nil
34
- expect(style_rule.custom_instructions).to be_nil
35
- end
36
- end
37
-
38
- context 'when building an object with configured rules and custom instructions' do
39
- subject(:style_rule) do
40
- described_class.new({
41
- 'style_id' => 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4',
42
- 'name' => 'Detailed Style Rule',
43
- 'language' => 'en',
44
- 'version' => 1,
45
- 'configured_rules' => {
46
- 'dates_and_times' => { 'calendar_era' => 'use_bc_and_ad' }
47
- },
48
- 'custom_instructions' => [
49
- { 'id' => 'ci-1', 'label' => 'Test', 'prompt' => 'Be formal' }
50
- ]
51
- }, nil, nil)
52
- end
53
-
54
- it 'maps configured_rules into a ConfiguredRules resource' do
55
- expect(style_rule.configured_rules).to be_a(DeepL::Resources::ConfiguredRules)
56
- expect(style_rule.configured_rules.dates_and_times)
57
- .to eq({ 'calendar_era' => 'use_bc_and_ad' })
58
- end
59
-
60
- it 'maps custom_instructions into an array of CustomInstruction resources' do
61
- expect(style_rule.custom_instructions).to all(be_a(DeepL::Resources::CustomInstruction))
62
- expect(style_rule.custom_instructions.first.id).to eq('ci-1')
63
- expect(style_rule.custom_instructions.first.label).to eq('Test')
64
- expect(style_rule.custom_instructions.first.prompt).to eq('Be formal')
65
- end
66
- end
67
- end
68
- end
@@ -1,23 +0,0 @@
1
- # Copyright 2018 Daniel Herzog
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::Text do
9
- subject(:text) { described_class.new('Target', 'es', nil, nil, nil) }
10
-
11
- describe '#initialize' do
12
- context 'when building a basic object' do
13
- it 'creates a resource' do
14
- expect(text).to be_a(described_class)
15
- end
16
-
17
- it 'assigns the attributes' do
18
- expect(text.text).to eq('Target')
19
- expect(text.detected_source_language).to eq('es')
20
- end
21
- end
22
- end
23
- end
@@ -1,38 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::TranslationMemoryExport do
9
- subject(:translation_memory_export) { described_class.new(response, false, nil, nil) }
10
-
11
- let(:response) do
12
- {
13
- 'job_id' => '5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d',
14
- 'parameters' => { 'translation_memory_id' => 'a74d88fb-ed2a-4943-a664-a4512398b994' }
15
- }
16
- end
17
-
18
- describe '#initialize' do
19
- it 'creates a resource' do
20
- expect(translation_memory_export).to be_a(described_class)
21
- end
22
-
23
- it 'assigns the attributes of a newly created export' do
24
- expect(translation_memory_export.job_id).to eq('5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d')
25
- expect(translation_memory_export.translation_memory_id)
26
- .to eq('a74d88fb-ed2a-4943-a664-a4512398b994')
27
- expect(translation_memory_export.reused_existing?).to be(false)
28
- end
29
-
30
- context 'when the API reused a previously completed export' do
31
- subject(:translation_memory_export) { described_class.new(response, true, nil, nil) }
32
-
33
- it 'reports the export as reused' do
34
- expect(translation_memory_export.reused_existing?).to be(true)
35
- end
36
- end
37
- end
38
- end
@@ -1,30 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::TranslationMemoryImport do
9
- subject(:translation_memory_import) do
10
- described_class.new({
11
- 'job_id' => '5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d',
12
- 'upload_url' => 'https://storage.example.com/upload',
13
- 'expires_at' => '2026-01-01T00:00:00Z'
14
- }, nil, nil)
15
- end
16
-
17
- describe '#initialize' do
18
- it 'creates a resource' do
19
- expect(translation_memory_import).to be_a(described_class)
20
- end
21
-
22
- it 'assigns the attributes' do
23
- expect(translation_memory_import.job_id).to eq('5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d')
24
- expect(translation_memory_import.upload_url).to eq('https://storage.example.com/upload')
25
- expect(translation_memory_import.expires_at).to eq(Time.parse('2026-01-01T00:00:00Z'))
26
- expect(translation_memory_import.to_s)
27
- .to eq('TranslationMemoryImport: ID: 5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d')
28
- end
29
- end
30
- end
@@ -1,109 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Resources::TranslationMemoryJob do
9
- subject(:job) { described_class.new(response, nil, nil) }
10
-
11
- let(:response) do
12
- {
13
- 'job_id' => '5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d',
14
- 'product' => 'translation_memory',
15
- 'operation' => 'import',
16
- 'creation_time' => '2026-01-01T00:00:00Z',
17
- 'updated_time' => '2026-01-02T00:00:00Z',
18
- 'source_file' => { 'content_type' => 'application/xml', 'content_length' => 128 },
19
- 'parameters' => { 'display_name' => 'Legal' },
20
- 'results' => [
21
- { 'status' => 'completed', 'translation_memory_id' => 'tm-1',
22
- 'skipped_segment_count' => 2 }
23
- ]
24
- }
25
- end
26
-
27
- describe '#initialize' do
28
- it 'creates a resource' do
29
- expect(job).to be_a(described_class)
30
- end
31
-
32
- it 'assigns the job level attributes' do
33
- expect(job.job_id).to eq('5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d')
34
- expect(job.product).to eq('translation_memory')
35
- expect(job.operation).to eq('import')
36
- expect(job.creation_time).to eq(Time.parse('2026-01-01T00:00:00Z'))
37
- expect(job.updated_time).to eq(Time.parse('2026-01-02T00:00:00Z'))
38
- expect(job.display_name).to eq('Legal')
39
- expect(job.source_content_type).to eq('application/xml')
40
- expect(job.source_content_length).to eq(128)
41
- end
42
-
43
- it 'maps the single result and delegates the status helpers to it' do
44
- expect(job.result).to be_a(DeepL::Resources::TranslationMemoryJobResult)
45
- expect(job.status).to eq('completed')
46
- expect(job.finished?).to be(true)
47
- expect(job.awaiting_input?).to be(false)
48
- expect(job.error?).to be(false)
49
- expect(job.result.translation_memory_id).to eq('tm-1')
50
- expect(job.result.skipped_segment_count).to eq(2)
51
- end
52
- end
53
-
54
- context 'when the job is awaiting its file upload' do
55
- let(:response) do
56
- { 'job_id' => 'job-1', 'operation' => 'import',
57
- 'results' => [{ 'status' => 'awaiting_input',
58
- 'status_metadata' => { 'required_action' => 'Waiting for upload' } }] }
59
- end
60
-
61
- it 'exposes the required action and does not report the job as finished' do
62
- expect(job.awaiting_input?).to be(true)
63
- expect(job.finished?).to be(false)
64
- expect(job.result.required_action).to eq('Waiting for upload')
65
- end
66
- end
67
-
68
- context 'when the export job completed' do
69
- let(:response) do
70
- { 'job_id' => 'job-2', 'operation' => 'export',
71
- 'parameters' => { 'translation_memory_id' => 'tm-1' },
72
- 'results' => [{ 'status' => 'completed', 'download_url' => 'https://example.com/tmx',
73
- 'expires_at' => '2026-01-03T00:00:00Z' }] }
74
- end
75
-
76
- it 'exposes the download URL and its expiry' do
77
- expect(job.translation_memory_id).to eq('tm-1')
78
- expect(job.result.download_url).to eq('https://example.com/tmx')
79
- expect(job.result.expires_at).to eq(Time.parse('2026-01-03T00:00:00Z'))
80
- expect(job.to_s).to eq('TranslationMemoryJob: export - ID: job-2 - Status: completed')
81
- end
82
- end
83
-
84
- context 'when the job failed' do
85
- let(:response) do
86
- { 'job_id' => 'job-3', 'operation' => 'import',
87
- 'results' => [{ 'status' => 'failed', 'error' => { 'message' => 'Invalid TMX' } }] }
88
- end
89
-
90
- it 'reports the error and treats the job as finished' do
91
- expect(job.error?).to be(true)
92
- expect(job.finished?).to be(true)
93
- expect(job.error_message).to eq('Invalid TMX')
94
- end
95
- end
96
-
97
- context 'when the API returned no result' do
98
- let(:response) { { 'job_id' => 'job-4', 'operation' => 'import' } }
99
-
100
- it 'reports neither a status nor an error' do
101
- expect(job.result).to be_nil
102
- expect(job.status).to be_nil
103
- expect(job.finished?).to be(false)
104
- expect(job.awaiting_input?).to be(false)
105
- expect(job.error?).to be(false)
106
- expect(job.error_message).to be_nil
107
- end
108
- end
109
- end