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,262 +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
- # rubocop:disable RSpec/StubbedMock
9
- describe DeepL do # rubocop:disable RSpec/SpecFilePathFormat
10
- subject(:deepl) { described_class.dup }
11
-
12
- around do |tests|
13
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
14
- tests.call
15
- ENV.replace(tmp_env)
16
- end
17
-
18
- describe '#configure' do
19
- context 'when providing no block' do
20
- let(:configuration) { DeepL::Configuration.new }
21
-
22
- before do
23
- deepl.configure
24
- end
25
-
26
- it 'uses default configuration' do
27
- expect(deepl.configuration).to eq(configuration)
28
- end
29
- end
30
-
31
- context 'when providing a valid configuration' do
32
- let(:configuration) do
33
- DeepL::Configuration.new({ auth_key: 'VALID', host: 'http://www.example.org',
34
- version: 'v1' })
35
- end
36
-
37
- before do
38
- deepl.configure do |config|
39
- config.auth_key = configuration.auth_key
40
- config.host = configuration.host
41
- config.version = configuration.version
42
- end
43
- end
44
-
45
- it 'uses the provided configuration' do
46
- expect(deepl.configuration).to eq(configuration)
47
- end
48
- end
49
-
50
- context 'when providing an invalid configuration' do
51
- it 'raises an error' do
52
- expect { deepl.configure { |c| c.auth_key = '' } }
53
- .to raise_error(DeepL::Exceptions::Error)
54
- end
55
- end
56
- end
57
-
58
- describe '#translate' do
59
- let(:request) { instance_double(DeepL::Requests::Translate, request: 'result') }
60
-
61
- before { deepl.configure }
62
-
63
- it 'delegates to DeepL::Requests::Translate with the given arguments' do
64
- options = { formality: 'more' }
65
- additional_headers = { 'X-DeepL-Reporting-Tag' => 'tag' }
66
- expect(DeepL::Requests::Translate).to receive(:new)
67
- .with(deepl.api, 'Sample', 'EN', 'ES', options, additional_headers)
68
- .and_return(request)
69
-
70
- expect(deepl.translate('Sample', 'EN', 'ES', options, additional_headers)).to eq('result')
71
- end
72
-
73
- it 'defaults options and additional_headers to empty hashes' do
74
- expect(DeepL::Requests::Translate).to receive(:new)
75
- .with(deepl.api, 'Sample', 'EN', 'ES', {}, {})
76
- .and_return(request)
77
-
78
- deepl.translate('Sample', 'EN', 'ES')
79
- end
80
- end
81
-
82
- describe '#rephrase' do
83
- let(:request) { instance_double(DeepL::Requests::Rephrase, request: 'result') }
84
-
85
- before { deepl.configure }
86
-
87
- it 'delegates to DeepL::Requests::Rephrase with the given arguments' do
88
- options = { foo: 'bar' }
89
- additional_headers = { 'X-DeepL-Reporting-Tag' => 'tag' }
90
- expect(DeepL::Requests::Rephrase).to receive(:new)
91
- .with(deepl.api, 'Sample', 'DE', 'business', 'friendly', options, additional_headers)
92
- .and_return(request)
93
-
94
- result = deepl.rephrase('Sample', 'DE', 'business', 'friendly', options, additional_headers)
95
- expect(result).to eq('result')
96
- end
97
-
98
- it 'defaults the optional arguments' do
99
- expect(DeepL::Requests::Rephrase).to receive(:new)
100
- .with(deepl.api, 'Sample', nil, nil, nil, {}, {})
101
- .and_return(request)
102
-
103
- deepl.rephrase('Sample')
104
- end
105
- end
106
-
107
- describe '#usage' do
108
- let(:request) { instance_double(DeepL::Requests::Usage, request: 'result') }
109
-
110
- before { deepl.configure }
111
-
112
- it 'delegates to DeepL::Requests::Usage with the given options' do
113
- options = { foo: 'bar' }
114
- expect(DeepL::Requests::Usage).to receive(:new).with(deepl.api, options).and_return(request)
115
-
116
- expect(deepl.usage(options)).to eq('result')
117
- end
118
-
119
- it 'defaults options to an empty hash' do
120
- expect(DeepL::Requests::Usage).to receive(:new).with(deepl.api, {}).and_return(request)
121
-
122
- deepl.usage
123
- end
124
- end
125
-
126
- describe '#languages' do
127
- let(:request) { instance_double(DeepL::Requests::Languages, request: 'result') }
128
-
129
- before { deepl.configure }
130
-
131
- it 'delegates to DeepL::Requests::Languages with the given options' do
132
- options = { type: :target }
133
- expect(DeepL::Requests::Languages).to receive(:new).with(deepl.api, options)
134
- .and_return(request)
135
-
136
- expect(deepl.languages(options)).to eq('result')
137
- end
138
-
139
- it 'defaults options to an empty hash' do
140
- expect(DeepL::Requests::Languages).to receive(:new).with(deepl.api, {}).and_return(request)
141
-
142
- deepl.languages
143
- end
144
- end
145
-
146
- describe '#glossaries' do
147
- before { deepl.configure }
148
-
149
- it 'returns a GlossaryApi instance built with the configured api' do
150
- expect(deepl.glossaries).to be_a(DeepL::GlossaryApi)
151
- end
152
-
153
- describe 'GlossaryApi#create' do
154
- it 'delegates to DeepL::Requests::Glossary::Create' do
155
- request = instance_double(DeepL::Requests::Glossary::Create, request: 'result')
156
- entries = [%w[Hello Hola]]
157
- expect(DeepL::Requests::Glossary::Create).to receive(:new)
158
- .with(deepl.api, 'Mi Glosario', 'EN', 'ES', entries, {})
159
- .and_return(request)
160
-
161
- deepl.glossaries.create('Mi Glosario', 'EN', 'ES', entries)
162
- end
163
- end
164
-
165
- describe 'GlossaryApi#find' do
166
- it 'delegates to DeepL::Requests::Glossary::Find' do
167
- request = instance_double(DeepL::Requests::Glossary::Find, request: 'result')
168
- expect(DeepL::Requests::Glossary::Find).to receive(:new)
169
- .with(deepl.api, 'glossary-id', {})
170
- .and_return(request)
171
-
172
- deepl.glossaries.find('glossary-id')
173
- end
174
- end
175
-
176
- describe 'GlossaryApi#list' do
177
- it 'delegates to DeepL::Requests::Glossary::List' do
178
- request = instance_double(DeepL::Requests::Glossary::List, request: 'result')
179
- expect(DeepL::Requests::Glossary::List).to receive(:new).with(deepl.api, {})
180
- .and_return(request)
181
-
182
- deepl.glossaries.list
183
- end
184
- end
185
-
186
- describe 'GlossaryApi#destroy' do
187
- it 'delegates to DeepL::Requests::Glossary::Destroy' do
188
- request = instance_double(DeepL::Requests::Glossary::Destroy, request: 'result')
189
- expect(DeepL::Requests::Glossary::Destroy).to receive(:new)
190
- .with(deepl.api, 'glossary-id', {})
191
- .and_return(request)
192
-
193
- deepl.glossaries.destroy('glossary-id')
194
- end
195
- end
196
-
197
- describe 'GlossaryApi#entries' do
198
- it 'delegates to DeepL::Requests::Glossary::Entries' do
199
- request = instance_double(DeepL::Requests::Glossary::Entries, request: 'result')
200
- expect(DeepL::Requests::Glossary::Entries).to receive(:new)
201
- .with(deepl.api, 'glossary-id', {})
202
- .and_return(request)
203
-
204
- deepl.glossaries.entries('glossary-id')
205
- end
206
- end
207
-
208
- describe 'GlossaryApi#language_pairs' do
209
- it 'delegates to DeepL::Requests::Glossary::LanguagePairs' do
210
- request = instance_double(DeepL::Requests::Glossary::LanguagePairs, request: 'result')
211
- expect(DeepL::Requests::Glossary::LanguagePairs).to receive(:new).with(deepl.api, {})
212
- .and_return(request)
213
-
214
- deepl.glossaries.language_pairs
215
- end
216
- end
217
- end
218
-
219
- describe '#document' do
220
- before { deepl.configure }
221
-
222
- it 'returns a DocumentApi instance built with the configured api' do
223
- expect(deepl.document).to be_a(DeepL::DocumentApi)
224
- end
225
-
226
- describe 'DocumentApi#upload' do
227
- it 'delegates to DeepL::Requests::Document::Upload' do
228
- request = instance_double(DeepL::Requests::Document::Upload, request: 'result')
229
- expect(DeepL::Requests::Document::Upload).to receive(:new)
230
- .with(deepl.api, 'path', 'EN', 'ES', 'file.txt', {}, {})
231
- .and_return(request)
232
-
233
- deepl.document.upload('path', 'EN', 'ES', 'file.txt')
234
- end
235
- end
236
-
237
- describe 'DocumentApi#get_status' do
238
- it 'delegates to DeepL::Requests::Document::GetStatus' do
239
- request = instance_double(DeepL::Requests::Document::GetStatus, request: 'result')
240
- handle = DeepL::Resources::DocumentHandle.new('doc-id', 'doc-key', nil, nil)
241
- expect(DeepL::Requests::Document::GetStatus).to receive(:new)
242
- .with(deepl.api, 'doc-id', 'doc-key', {}, {})
243
- .and_return(request)
244
-
245
- deepl.document.get_status(handle)
246
- end
247
- end
248
-
249
- describe 'DocumentApi#download' do
250
- it 'delegates to DeepL::Requests::Document::Download' do
251
- request = instance_double(DeepL::Requests::Document::Download, request: 'result')
252
- handle = DeepL::Resources::DocumentHandle.new('doc-id', 'doc-key', nil, nil)
253
- expect(DeepL::Requests::Document::Download).to receive(:new)
254
- .with(deepl.api, 'doc-id', 'doc-key', 'output-path')
255
- .and_return(request)
256
-
257
- deepl.document.download(handle, 'output-path')
258
- end
259
- end
260
- end
261
- end
262
- # rubocop:enable RSpec/StubbedMock
@@ -1,158 +0,0 @@
1
- # Copyright 2025 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::Constants' do
9
- describe DeepL::Constants::Tone do
10
- subject(:tone) { described_class }
11
-
12
- it 'includes all expected tone values' do # rubocop:disable RSpec/ExampleLength
13
- expect(tone.options).to contain_exactly(
14
- 'confident',
15
- 'default',
16
- 'diplomatic',
17
- 'enthusiastic',
18
- 'friendly',
19
- 'prefer_confident',
20
- 'prefer_diplomatic',
21
- 'prefer_enthusiastic',
22
- 'prefer_friendly'
23
- )
24
- end
25
-
26
- it 'validates correct tone values' do
27
- expect(tone.valid?('enthusiastic')).to be true
28
- expect(tone.valid?('friendly')).to be true
29
- expect(tone.valid?('confident')).to be true
30
- expect(tone.valid?('diplomatic')).to be true
31
- expect(tone.valid?('default')).to be true
32
- end
33
-
34
- it 'invalidates incorrect tone values' do
35
- expect(tone.valid?('angry')).to be false
36
- expect(tone.valid?('')).to be false
37
- expect(tone.valid?(nil)).to be false
38
- end
39
- end
40
-
41
- describe DeepL::Constants::WritingStyle do
42
- subject(:writing_style) { described_class }
43
-
44
- it 'includes all expected writing style values' do # rubocop:disable RSpec/ExampleLength
45
- expect(writing_style.options).to contain_exactly(
46
- 'default',
47
- 'simple',
48
- 'business',
49
- 'academic',
50
- 'casual',
51
- 'prefer_academic',
52
- 'prefer_business',
53
- 'prefer_casual',
54
- 'prefer_simple'
55
- )
56
- end
57
-
58
- it 'validates correct writing style values' do
59
- expect(writing_style.valid?('simple')).to be true
60
- expect(writing_style.valid?('business')).to be true
61
- expect(writing_style.valid?('academic')).to be true
62
- expect(writing_style.valid?('casual')).to be true
63
- expect(writing_style.valid?('default')).to be true
64
- end
65
-
66
- it 'invalidates incorrect writing style values' do
67
- expect(writing_style.valid?('wordy')).to be false
68
- expect(writing_style.valid?('')).to be false
69
- expect(writing_style.valid?(nil)).to be false
70
- end
71
- end
72
-
73
- describe DeepL::Constants::TagHandling do
74
- subject(:tag_handling) { described_class }
75
-
76
- it 'includes all expected tag handling values' do
77
- expect(tag_handling.options).to contain_exactly('xml', 'html')
78
- end
79
-
80
- it 'validates correct tag handling values' do
81
- expect(tag_handling.valid?('xml')).to be true
82
- expect(tag_handling.valid?('html')).to be true
83
- end
84
-
85
- it 'invalidates incorrect tag handling values' do
86
- expect(tag_handling.valid?('json')).to be false
87
- expect(tag_handling.valid?('')).to be false
88
- expect(tag_handling.valid?(nil)).to be false
89
- end
90
- end
91
-
92
- describe DeepL::Constants::SplitSentences do
93
- subject(:split_sentences) { described_class }
94
-
95
- it 'includes all expected split sentences values' do
96
- expect(split_sentences.options).to contain_exactly('0', '1', 'nonewlines')
97
- end
98
-
99
- it 'validates correct split sentences values' do
100
- expect(split_sentences.valid?('0')).to be true
101
- expect(split_sentences.valid?('1')).to be true
102
- expect(split_sentences.valid?('nonewlines')).to be true
103
- end
104
-
105
- it 'invalidates incorrect split sentences values' do
106
- expect(split_sentences.valid?('2')).to be false
107
- expect(split_sentences.valid?('')).to be false
108
- expect(split_sentences.valid?(nil)).to be false
109
- end
110
- end
111
-
112
- describe DeepL::Constants::ModelType do
113
- subject(:model_type) { described_class }
114
-
115
- it 'includes all expected model type values' do
116
- expect(model_type.options).to contain_exactly(
117
- 'quality_optimized',
118
- 'prefer_quality_optimized',
119
- 'latency_optimized'
120
- )
121
- end
122
-
123
- it 'validates correct model type values' do
124
- expect(model_type.valid?('quality_optimized')).to be true
125
- expect(model_type.valid?('prefer_quality_optimized')).to be true
126
- expect(model_type.valid?('latency_optimized')).to be true
127
- end
128
-
129
- it 'invalidates incorrect model type values' do
130
- expect(model_type.valid?('speed_optimized')).to be false
131
- expect(model_type.valid?('')).to be false
132
- expect(model_type.valid?(nil)).to be false
133
- end
134
- end
135
-
136
- describe DeepL::Constants::Formality do
137
- subject(:formality) { described_class }
138
-
139
- it 'includes all expected formality values' do
140
- expect(formality.options).to contain_exactly('default', 'more', 'less', 'prefer_more',
141
- 'prefer_less')
142
- end
143
-
144
- it 'validates correct formality values' do
145
- expect(formality.valid?('default')).to be true
146
- expect(formality.valid?('more')).to be true
147
- expect(formality.valid?('less')).to be true
148
- expect(formality.valid?('prefer_more')).to be true
149
- expect(formality.valid?('prefer_less')).to be true
150
- end
151
-
152
- it 'invalidates incorrect formality values' do
153
- expect(formality.valid?('neutral')).to be false
154
- expect(formality.valid?('')).to be false
155
- expect(formality.valid?(nil)).to be false
156
- end
157
- end
158
- end
@@ -1,211 +0,0 @@
1
- # Copyright 2024 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 file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::DocumentApi do
9
- include_context 'with temp dir'
10
-
11
- let(:default_lang_args) { { source_lang: 'EN', target_lang: 'DE' } }
12
-
13
- describe '#translate_document' do
14
- it 'Translates a document from a filepath' do
15
- File.unlink(output_document_path)
16
- source_lang = default_lang_args[:source_lang]
17
- target_lang = default_lang_args[:target_lang]
18
- example_doc_path = example_document_path(source_lang)
19
- DeepL.document.translate_document(example_doc_path, output_document_path,
20
- source_lang, target_lang, File.basename(example_doc_path),
21
- {})
22
- output_file_contents = File.read(output_document_path)
23
-
24
- expect(example_document_translation(target_lang)).to eq(output_file_contents)
25
- end
26
-
27
- it 'Translates a document from a filepath without a filename' do
28
- File.unlink(output_document_path)
29
- source_lang = default_lang_args[:source_lang]
30
- target_lang = default_lang_args[:target_lang]
31
- example_doc_path = example_document_path(source_lang)
32
- DeepL.document.translate_document(example_doc_path, output_document_path,
33
- source_lang, target_lang)
34
- output_file_contents = File.read(output_document_path)
35
-
36
- expect(example_document_translation(target_lang)).to eq(output_file_contents)
37
- end
38
-
39
- it 'Translates a document using the lower-level methods and returns the correct status' do # rubocop:disable RSpec/ExampleLength
40
- File.unlink(output_document_path)
41
- source_lang = default_lang_args[:source_lang]
42
- target_lang = default_lang_args[:target_lang]
43
- example_doc_path = example_document_path(source_lang)
44
-
45
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
46
- File.basename(example_doc_path), {})
47
- doc_status = handle.wait_until_document_translation_finished
48
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
49
- output_file_contents = File.read(output_document_path)
50
-
51
- expect(example_document_translation(target_lang)).to eq(output_file_contents)
52
- expect(doc_status.billed_characters).to eq(example_document_translation(source_lang).length)
53
- expect(doc_status.status).to eq('done')
54
- end
55
-
56
- it 'Translates a document after retrying the upload once', :mock_server_only do # rubocop:disable RSpec/ExampleLength
57
- File.unlink(output_document_path)
58
- source_lang = default_lang_args[:source_lang]
59
- target_lang = default_lang_args[:target_lang]
60
- example_doc_path = example_document_path(source_lang)
61
- doc_status = nil
62
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil, enable_ssl_verification: false,
63
- read_timeout: 1.0)) do |_session|
64
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
65
- File.basename(example_doc_path), {}, no_response_header(1))
66
- doc_status = handle.wait_until_document_translation_finished
67
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
68
- end
69
- output_file_contents = File.read(output_document_path)
70
-
71
- expect(output_file_contents).to eq(example_document_translation(target_lang))
72
- expect(doc_status.billed_characters).to eq(example_document_translation(source_lang).length)
73
- expect(doc_status.status).to eq('done')
74
- end
75
- end
76
-
77
- it 'Translates a document after waiting', :mock_server_only do # rubocop:disable RSpec/ExampleLength
78
- File.unlink(output_document_path)
79
- source_lang = default_lang_args[:source_lang]
80
- target_lang = default_lang_args[:target_lang]
81
- example_doc_path = example_document_path(source_lang)
82
- doc_status = nil
83
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil,
84
- enable_ssl_verification: false)) do |_session|
85
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
86
- File.basename(example_doc_path), {},
87
- doc_translation_queue_time_header(2000).merge(doc_translation_translation_time_header(2000))) # rubocop:disable Layout/LineLength
88
- doc_status = handle.wait_until_document_translation_finished
89
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
90
- end
91
- output_file_contents = File.read(output_document_path)
92
-
93
- expect(output_file_contents).to eq(example_document_translation(target_lang))
94
- expect(doc_status.billed_characters).to eq(example_document_translation(source_lang).length)
95
- expect(doc_status.status).to eq('done')
96
- end
97
-
98
- it 'Translates a large document', :mock_server_only do # rubocop:disable RSpec/ExampleLength
99
- File.unlink(output_document_path)
100
- source_lang = default_lang_args[:source_lang]
101
- target_lang = default_lang_args[:target_lang]
102
- example_doc_path = example_large_document_path(source_lang)
103
- doc_status = nil
104
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil,
105
- enable_ssl_verification: false)) do |_session|
106
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
107
- File.basename(example_doc_path), {})
108
- doc_status = handle.wait_until_document_translation_finished
109
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
110
- end
111
- output_file_contents = File.read(output_document_path)
112
-
113
- expect(output_file_contents).to eq(example_large_document_translation(target_lang))
114
- expect(doc_status.billed_characters).to eq(
115
- example_large_document_translation(source_lang).length
116
- )
117
- expect(doc_status.status).to eq('done')
118
- end
119
-
120
- it 'Translates a document with formality set', :mock_server_only do # rubocop:disable RSpec/ExampleLength
121
- File.unlink(output_document_path)
122
- source_lang = default_lang_args[:source_lang]
123
- target_lang = default_lang_args[:target_lang]
124
- example_doc_path = example_large_document_path(source_lang)
125
- doc_status = nil
126
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil,
127
- enable_ssl_verification: false)) do |_session|
128
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
129
- File.basename(example_doc_path),
130
- { 'formality' => 'prefer_more' })
131
- doc_status = handle.wait_until_document_translation_finished
132
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
133
- end
134
- output_file_contents = File.read(output_document_path)
135
-
136
- expect(output_file_contents).to eq(example_large_document_translation(target_lang))
137
- expect(doc_status.billed_characters).to eq(
138
- example_large_document_translation(source_lang).length
139
- )
140
- expect(doc_status.status).to eq('done')
141
- end
142
-
143
- it 'Translates a document with a style_id set', :mock_server_only do # rubocop:disable RSpec/ExampleLength
144
- File.unlink(output_document_path)
145
- # Mock's default style rule (dca2e053...) has language `en`, so the target
146
- # language must be English.
147
- source_lang = 'DE'
148
- target_lang = 'EN-US'
149
- example_doc_path = example_document_path(source_lang)
150
- style_id = 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4'
151
- doc_status = nil
152
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil,
153
- enable_ssl_verification: false)) do |_session|
154
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
155
- File.basename(example_doc_path),
156
- { style_rule: style_id })
157
- doc_status = handle.wait_until_document_translation_finished
158
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
159
- end
160
- output_file_contents = File.read(output_document_path)
161
-
162
- expect(example_document_translation(target_lang)).to eq(output_file_contents)
163
- expect(doc_status.status).to eq('done')
164
- end
165
-
166
- it 'Translates a document with a translation_memory_id set', :mock_server_only do # rubocop:disable RSpec/ExampleLength
167
- File.unlink(output_document_path)
168
- # Mock's default translation memory (a74d88fb...) has source `de` and
169
- # targets `en`/`es`/`fr`, so translate DE -> EN-US.
170
- source_lang = 'DE'
171
- target_lang = 'EN-US'
172
- example_doc_path = example_document_path(source_lang)
173
- translation_memory_id = 'a74d88fb-ed2a-4943-a664-a4512398b994'
174
- doc_status = nil
175
- DeepL.with_session(DeepL::HTTPClientOptions.new({}, nil,
176
- enable_ssl_verification: false)) do |_session|
177
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
178
- File.basename(example_doc_path),
179
- { translation_memory: translation_memory_id,
180
- translation_memory_threshold: 80 })
181
- doc_status = handle.wait_until_document_translation_finished
182
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
183
- end
184
- output_file_contents = File.read(output_document_path)
185
-
186
- expect(example_document_translation(target_lang)).to eq(output_file_contents)
187
- expect(doc_status.status).to eq('done')
188
- end
189
-
190
- it 'Translates a document with extra_body_parameters' do # rubocop:disable RSpec/ExampleLength
191
- File.unlink(output_document_path)
192
- source_lang = default_lang_args[:source_lang]
193
- target_lang = default_lang_args[:target_lang]
194
- example_doc_path = example_document_path(source_lang)
195
-
196
- handle = DeepL.document.upload(example_doc_path, source_lang, target_lang,
197
- File.basename(example_doc_path),
198
- {
199
- extra_body_parameters: {
200
- target_lang: 'FR',
201
- debug: '1'
202
- }
203
- })
204
- doc_status = handle.wait_until_document_translation_finished
205
- DeepL.document.download(handle, output_document_path) if doc_status.status != 'error'
206
- output_file_contents = File.read(output_document_path)
207
-
208
- expect(example_document_translation('FR')).to eq(output_file_contents)
209
- expect(doc_status.status).to eq('done')
210
- end
211
- end
@@ -1,33 +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 file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::DocumentApi do # rubocop:disable RSpec/SpecFilePathFormat
9
- include_context 'with a live mock server'
10
-
11
- let(:source_lang) { 'EN' }
12
- let(:target_lang) { 'DE' }
13
- let(:document_path) { example_document_path(source_lang) }
14
-
15
- describe 'authorization failures' do
16
- let(:unauthorized_documents) { described_class.new(unauthorized_api) }
17
-
18
- it 'raises AuthorizationFailed when uploading with an invalid auth key' do
19
- expect { unauthorized_documents.upload(document_path, source_lang, target_lang) }
20
- .to raise_error(DeepL::Exceptions::AuthorizationFailed)
21
- end
22
- end
23
-
24
- describe 'translation failures' do
25
- it 'reports an error status when the server fails the document', :mock_server_only do
26
- handle = DeepL.document.upload(document_path, source_lang, target_lang,
27
- File.basename(document_path), {}, fail_docs_header(1))
28
- status = handle.wait_until_document_translation_finished
29
-
30
- expect(status.status).to eq('error')
31
- end
32
- end
33
- end