deepl-rb 3.8.0 → 3.10.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 (225) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +71 -53
  3. data/.rubocop.yml +26 -0
  4. data/CHANGELOG.md +450 -17
  5. data/Gemfile +4 -0
  6. data/README.md +1119 -152
  7. data/Rakefile +18 -5
  8. data/VERSION +1 -1
  9. data/deepl-rb.gemspec +31 -3
  10. data/lib/deepl/admin_client.rb +183 -0
  11. data/lib/deepl/api.rb +30 -6
  12. data/lib/deepl/app_info.rb +20 -0
  13. data/lib/deepl/client.rb +969 -0
  14. data/lib/deepl/configuration.rb +56 -10
  15. data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
  16. data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
  17. data/lib/deepl/constants/document_status_code.rb +17 -0
  18. data/lib/deepl/constants/language_include.rb +17 -0
  19. data/lib/deepl/constants/language_resource_name.rb +21 -0
  20. data/lib/deepl/constants/tag_handling_version.rb +14 -0
  21. data/lib/deepl/deprecation.rb +42 -0
  22. data/lib/deepl/document_api.rb +45 -16
  23. data/lib/deepl/exceptions/bad_request.rb +1 -3
  24. data/lib/deepl/exceptions/connection_error.rb +37 -0
  25. data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
  26. data/lib/deepl/exceptions/document_translation_error.rb +17 -1
  27. data/lib/deepl/exceptions/error.rb +13 -1
  28. data/lib/deepl/exceptions/not_found.rb +8 -3
  29. data/lib/deepl/exceptions/not_supported.rb +6 -0
  30. data/lib/deepl/exceptions/request_error.rb +19 -2
  31. data/lib/deepl/exceptions/server_error.rb +7 -1
  32. data/lib/deepl/exceptions/validation_error.rb +14 -0
  33. data/lib/deepl/requests/admin/base.rb +94 -0
  34. data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
  35. data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
  36. data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
  37. data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
  38. data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
  39. data/lib/deepl/requests/base.rb +265 -43
  40. data/lib/deepl/requests/correct.rb +57 -0
  41. data/lib/deepl/requests/document/download.rb +11 -3
  42. data/lib/deepl/requests/document/get_status.rb +2 -2
  43. data/lib/deepl/requests/document/upload.rb +92 -10
  44. data/lib/deepl/requests/glossary/create.rb +6 -2
  45. data/lib/deepl/requests/glossary/language_pairs.rb +20 -4
  46. data/lib/deepl/requests/language_resources.rb +41 -0
  47. data/lib/deepl/requests/languages.rb +28 -4
  48. data/lib/deepl/requests/languages_for_resource.rb +54 -0
  49. data/lib/deepl/requests/multilingual_glossary/create.rb +37 -0
  50. data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
  51. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +51 -0
  52. data/lib/deepl/requests/multilingual_glossary/entries.rb +66 -0
  53. data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
  54. data/lib/deepl/requests/multilingual_glossary/helpers.rb +63 -0
  55. data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
  56. data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
  57. data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
  58. data/lib/deepl/requests/rephrase.rb +5 -9
  59. data/lib/deepl/requests/spoken_terms/create.rb +37 -0
  60. data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
  61. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +41 -0
  62. data/lib/deepl/requests/spoken_terms/entries.rb +46 -0
  63. data/lib/deepl/requests/spoken_terms/find.rb +35 -0
  64. data/lib/deepl/requests/spoken_terms/helpers.rb +67 -0
  65. data/lib/deepl/requests/spoken_terms/list.rb +35 -0
  66. data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
  67. data/lib/deepl/requests/spoken_terms/update.rb +40 -0
  68. data/lib/deepl/requests/style_profile/base.rb +83 -0
  69. data/lib/deepl/requests/style_profile/create.rb +35 -0
  70. data/lib/deepl/requests/style_profile/destroy.rb +34 -0
  71. data/lib/deepl/requests/style_profile/find.rb +33 -0
  72. data/lib/deepl/requests/style_profile/list.rb +43 -0
  73. data/lib/deepl/requests/style_profile/update.rb +35 -0
  74. data/lib/deepl/requests/style_rule/create.rb +1 -1
  75. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +4 -2
  76. data/lib/deepl/requests/style_rule/destroy.rb +4 -2
  77. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
  78. data/lib/deepl/requests/style_rule/find.rb +4 -2
  79. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
  80. data/lib/deepl/requests/style_rule/helpers.rb +35 -0
  81. data/lib/deepl/requests/style_rule/list.rb +1 -1
  82. data/lib/deepl/requests/style_rule/update.rb +4 -2
  83. data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
  84. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +5 -3
  85. data/lib/deepl/requests/translate.rb +55 -20
  86. data/lib/deepl/requests/translation_memory/base.rb +44 -0
  87. data/lib/deepl/requests/translation_memory/create_export.rb +41 -0
  88. data/lib/deepl/requests/translation_memory/create_import.rb +53 -0
  89. data/lib/deepl/requests/translation_memory/destroy.rb +37 -0
  90. data/lib/deepl/requests/translation_memory/download_export.rb +39 -0
  91. data/lib/deepl/requests/translation_memory/find.rb +38 -0
  92. data/lib/deepl/requests/translation_memory/find_job.rb +38 -0
  93. data/lib/deepl/requests/translation_memory/list.rb +6 -18
  94. data/lib/deepl/requests/translation_memory/segments.rb +47 -0
  95. data/lib/deepl/requests/translation_memory/storage_base.rb +79 -0
  96. data/lib/deepl/requests/translation_memory/upload_file.rb +47 -0
  97. data/lib/deepl/requests/usage.rb +28 -1
  98. data/lib/deepl/requests/write_improvements.rb +35 -0
  99. data/lib/deepl/resources/admin_usage_report.rb +73 -0
  100. data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
  101. data/lib/deepl/resources/developer_key.rb +57 -0
  102. data/lib/deepl/resources/document_handle.rb +24 -25
  103. data/lib/deepl/resources/document_translation_status.rb +23 -4
  104. data/lib/deepl/resources/language.rb +10 -2
  105. data/lib/deepl/resources/language_resource.rb +57 -0
  106. data/lib/deepl/resources/language_support.rb +56 -0
  107. data/lib/deepl/resources/multilingual_glossary.rb +112 -0
  108. data/lib/deepl/resources/spoken_terms.rb +61 -0
  109. data/lib/deepl/resources/style_profile.rb +44 -0
  110. data/lib/deepl/resources/style_rule.rb +3 -0
  111. data/lib/deepl/resources/text.rb +18 -2
  112. data/lib/deepl/resources/translation_memory.rb +10 -1
  113. data/lib/deepl/resources/translation_memory_export.rb +37 -0
  114. data/lib/deepl/resources/translation_memory_import.rb +29 -0
  115. data/lib/deepl/resources/translation_memory_job.rb +162 -0
  116. data/lib/deepl/resources/translation_memory_segments.rb +80 -0
  117. data/lib/deepl/resources/usage.rb +93 -4
  118. data/lib/deepl/style_rule_api.rb +11 -0
  119. data/lib/deepl/translation_memory_api.rb +373 -1
  120. data/lib/deepl/utils/client_builder.rb +54 -0
  121. data/lib/deepl/utils/document_poller.rb +70 -0
  122. data/lib/deepl/utils/exception_builder.rb +3 -2
  123. data/lib/deepl/utils/http_client_builder.rb +79 -0
  124. data/lib/deepl/utils/number_parser.rb +34 -0
  125. data/lib/deepl/utils/term_validator.rb +33 -0
  126. data/lib/deepl/utils/time_parser.rb +40 -0
  127. data/lib/deepl.rb +190 -34
  128. data/lib/http_client_options.rb +21 -1
  129. data/lib/version.rb +1 -1
  130. data/spec/fixtures.rb +33 -0
  131. data/spec/offline/admin_client_spec.rb +551 -0
  132. data/spec/offline/client_spec.rb +273 -0
  133. data/spec/{api → offline}/configuration_spec.rb +45 -3
  134. data/spec/{constants → offline}/constants_spec.rb +23 -1
  135. data/spec/offline/correct_text_spec.rb +50 -0
  136. data/spec/offline/deprecation_spec.rb +32 -0
  137. data/spec/offline/errors_spec.rb +92 -0
  138. data/spec/offline/glossaries_spec.rb +98 -0
  139. data/spec/offline/http_client_spec.rb +319 -0
  140. data/spec/offline/languages_spec.rb +155 -0
  141. data/spec/offline/module_methods_spec.rb +13 -0
  142. data/spec/offline/multilingual_glossaries_spec.rb +358 -0
  143. data/spec/offline/offline_helper.rb +71 -0
  144. data/spec/offline/rephrase_text_spec.rb +73 -0
  145. data/spec/offline/spoken_terms_spec.rb +215 -0
  146. data/spec/offline/style_profiles_spec.rb +266 -0
  147. data/spec/offline/style_rules_spec.rb +318 -0
  148. data/spec/offline/translate_document_spec.rb +606 -0
  149. data/spec/offline/translate_text_spec.rb +286 -0
  150. data/spec/offline/translation_memories_client_spec.rb +256 -0
  151. data/spec/offline/translation_memories_spec.rb +463 -0
  152. data/spec/offline/usage_spec.rb +151 -0
  153. data/spec/real_api/admin_client_spec.rb +77 -0
  154. data/spec/real_api/correct_text_spec.rb +20 -0
  155. data/spec/real_api/glossaries_spec.rb +28 -0
  156. data/spec/real_api/languages_spec.rb +27 -0
  157. data/spec/real_api/multilingual_glossaries_spec.rb +53 -0
  158. data/spec/real_api/proxy_spec.rb +41 -0
  159. data/spec/real_api/real_api_helper.rb +65 -0
  160. data/spec/real_api/rephrase_text_spec.rb +16 -0
  161. data/spec/real_api/spoken_terms_spec.rb +56 -0
  162. data/spec/real_api/style_profiles_spec.rb +46 -0
  163. data/spec/real_api/style_rules_spec.rb +46 -0
  164. data/spec/real_api/translate_document_spec.rb +18 -0
  165. data/spec/real_api/translate_text_spec.rb +16 -0
  166. data/spec/real_api/translation_memories_spec.rb +56 -0
  167. data/spec/real_api/usage_spec.rb +20 -0
  168. data/spec/spec_helper.rb +1 -50
  169. metadata +134 -63
  170. data/.circleci/config.yml +0 -27
  171. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  172. data/spec/api/api_spec.rb +0 -20
  173. data/spec/api/deepl_spec.rb +0 -262
  174. data/spec/integration_tests/document_api_spec.rb +0 -164
  175. data/spec/integration_tests/document_error_paths_spec.rb +0 -33
  176. data/spec/integration_tests/glossary_api_spec.rb +0 -114
  177. data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
  178. data/spec/integration_tests/integration_test_utils.rb +0 -170
  179. data/spec/integration_tests/languages_api_spec.rb +0 -54
  180. data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
  181. data/spec/integration_tests/rephrase_api_spec.rb +0 -90
  182. data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
  183. data/spec/integration_tests/smoke_test_spec.rb +0 -24
  184. data/spec/integration_tests/style_rule_api_spec.rb +0 -117
  185. data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
  186. data/spec/integration_tests/translate_api_spec.rb +0 -98
  187. data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
  188. data/spec/integration_tests/translation_memory_api_spec.rb +0 -54
  189. data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -19
  190. data/spec/integration_tests/usage_api_spec.rb +0 -29
  191. data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
  192. data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
  193. data/spec/requests/glossary/create_spec.rb +0 -44
  194. data/spec/requests/glossary/destroy_spec.rb +0 -27
  195. data/spec/requests/glossary/entries_spec.rb +0 -27
  196. data/spec/requests/glossary/find_spec.rb +0 -28
  197. data/spec/requests/glossary/language_pairs_spec.rb +0 -27
  198. data/spec/requests/glossary/list_spec.rb +0 -27
  199. data/spec/requests/languages_spec.rb +0 -27
  200. data/spec/requests/rephrase_spec.rb +0 -46
  201. data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
  202. data/spec/requests/style_rule/create_spec.rb +0 -29
  203. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
  204. data/spec/requests/style_rule/destroy_spec.rb +0 -27
  205. data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
  206. data/spec/requests/style_rule/find_spec.rb +0 -28
  207. data/spec/requests/style_rule/list_spec.rb +0 -27
  208. data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
  209. data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
  210. data/spec/requests/style_rule/update_spec.rb +0 -29
  211. data/spec/requests/translate_spec.rb +0 -283
  212. data/spec/requests/translation_memory/list_spec.rb +0 -27
  213. data/spec/requests/usage_spec.rb +0 -27
  214. data/spec/resources/custom_instruction_spec.rb +0 -32
  215. data/spec/resources/glossary_spec.rb +0 -38
  216. data/spec/resources/language_pair_spec.rb +0 -23
  217. data/spec/resources/language_spec.rb +0 -45
  218. data/spec/resources/style_rule_spec.rb +0 -68
  219. data/spec/resources/text_spec.rb +0 -23
  220. data/spec/resources/translation_memory_spec.rb +0 -35
  221. data/spec/resources/usage_spec.rb +0 -35
  222. data/spec/support/live_mock_server.rb +0 -12
  223. data/spec/support/managed_glossary.rb +0 -17
  224. data/spec/support/managed_style_rule.rb +0 -17
  225. data/spec/support/managed_translation_memory.rb +0 -7
@@ -1,283 +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::Translate do
9
- subject(:translate) { described_class.new(api, text, source_lang, target_lang, 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(:tags_str) { 'p,strong,span' }
18
- let(:tags_array) { %w[p strong span] }
19
-
20
- let(:api) { build_deepl_api }
21
- let(:text) { 'Sample text' }
22
- let(:source_lang) { 'EN' }
23
- let(:target_lang) { 'ES' }
24
- let(:options) { {} }
25
-
26
- describe '#initialize' do
27
- context 'when building a request' do
28
- it 'creates a request object' do
29
- expect(translate).to be_a(described_class)
30
- end
31
- end
32
-
33
- context 'when using `splitting_tags` options' do
34
- it 'works with a nil values' do
35
- request = described_class.new(api, nil, nil, nil, splitting_tags: nil)
36
- expect(request.options[:splitting_tags]).to be_nil
37
- end
38
-
39
- it 'works with a blank list' do
40
- request = described_class.new(api, nil, nil, nil, splitting_tags: '')
41
- expect(request.options[:splitting_tags]).to eq([])
42
- end
43
-
44
- it 'works with a comma-separated list and converts strings to an array' do
45
- request = described_class.new(api, nil, nil, nil, splitting_tags: tags_str)
46
- expect(request.options[:splitting_tags]).to eq(tags_array)
47
- end
48
-
49
- it 'works with an array of tags and leaves it as is' do
50
- request = described_class.new(api, nil, nil, nil, splitting_tags: tags_array)
51
- expect(request.options[:splitting_tags]).to eq(tags_array)
52
- end
53
- end
54
-
55
- context 'when using `non_splitting_tags` options' do
56
- it 'works with a nil values' do
57
- request = described_class.new(api, nil, nil, nil, non_splitting_tags: nil)
58
- expect(request.options[:non_splitting_tags]).to be_nil
59
- end
60
-
61
- it 'works with a blank list' do
62
- request = described_class.new(api, nil, nil, nil, non_splitting_tags: '')
63
- expect(request.options[:non_splitting_tags]).to eq([])
64
- end
65
-
66
- it 'works with a comma-separated list and converts strings to an array' do
67
- request = described_class.new(api, nil, nil, nil, non_splitting_tags: tags_str)
68
- expect(request.options[:non_splitting_tags]).to eq(tags_array)
69
- end
70
-
71
- it 'works with an array and leaves it as it is' do
72
- request = described_class.new(api, nil, nil, nil, non_splitting_tags: tags_array)
73
- expect(request.options[:non_splitting_tags]).to eq(tags_array)
74
- end
75
- end
76
-
77
- context 'when using `ignore_tags` options' do
78
- it 'works with a nil values' do
79
- request = described_class.new(api, nil, nil, nil, ignore_tags: nil)
80
- expect(request.options[:ignore_tags]).to be_nil
81
- end
82
-
83
- it 'works with a blank list' do
84
- request = described_class.new(api, nil, nil, nil, ignore_tags: '')
85
- expect(request.options[:ignore_tags]).to eq([])
86
- end
87
-
88
- it 'works with a comma-separated list and converts a string to an array' do
89
- request = described_class.new(api, nil, nil, nil, ignore_tags: tags_str)
90
- expect(request.options[:ignore_tags]).to eq(tags_array)
91
- end
92
-
93
- it 'works with an array and leaves it as it is' do
94
- request = described_class.new(api, nil, nil, nil, ignore_tags: tags_array)
95
- expect(request.options[:ignore_tags]).to eq(tags_array)
96
- end
97
- end
98
-
99
- context 'when using `split_sentences` options' do
100
- it 'converts `true` to `1`' do
101
- request = described_class.new(api, nil, nil, nil, split_sentences: true)
102
- expect(request.options[:split_sentences]).to eq('1')
103
- end
104
-
105
- it 'converts `false` to `0`' do
106
- request = described_class.new(api, nil, nil, nil, split_sentences: false)
107
- expect(request.options[:split_sentences]).to eq('0')
108
- end
109
-
110
- it 'leaves `0` as is' do
111
- request = described_class.new(api, nil, nil, nil, split_sentences: '0')
112
- expect(request.options[:split_sentences]).to eq('0')
113
- end
114
-
115
- it 'leaves `nonewlines` as is' do
116
- request = described_class.new(api, nil, nil, nil, split_sentences: 'nonewlines')
117
- expect(request.options[:split_sentences]).to eq('nonewlines')
118
- end
119
-
120
- it 'leaves `1` as is' do
121
- request = described_class.new(api, nil, nil, nil, split_sentences: '1')
122
- expect(request.options[:split_sentences]).to eq('1')
123
- end
124
-
125
- it 'works with provided constants' do
126
- request = described_class.new(
127
- api,
128
- nil,
129
- nil,
130
- nil,
131
- split_sentences: DeepL::Constants::SplitSentences::SPLIT_ON_PUNCTUATION_AND_NEWLINES
132
- )
133
- expect(request.options[:split_sentences]).to eq('1')
134
- end
135
- end
136
-
137
- context 'when using `preserve_formatting` options' do
138
- it 'leaves `true` as is' do
139
- request = described_class.new(api, nil, nil, nil, preserve_formatting: true)
140
- expect(request.options[:preserve_formatting]).to be(true)
141
- end
142
-
143
- it 'leaves `false` as is' do
144
- request = described_class.new(api, nil, nil, nil, preserve_formatting: false)
145
- expect(request.options[:preserve_formatting]).to be(false)
146
- end
147
-
148
- it 'converts `0` to `false`' do
149
- request = described_class.new(api, nil, nil, nil, preserve_formatting: '0')
150
- expect(request.options[:preserve_formatting]).to be(false)
151
- end
152
-
153
- it 'converts `1` to `true`' do
154
- request = described_class.new(api, nil, nil, nil, preserve_formatting: '1')
155
- expect(request.options[:preserve_formatting]).to be(true)
156
- end
157
- end
158
-
159
- context 'when using `outline_detection` options' do
160
- it 'leaves `true` as is' do
161
- request = described_class.new(api, nil, nil, nil, outline_detection: true)
162
- expect(request.options[:outline_detection]).to be(true)
163
- end
164
-
165
- it 'leaves `false` as is' do
166
- request = described_class.new(api, nil, nil, nil, outline_detection: false)
167
- expect(request.options[:outline_detection]).to be(false)
168
- end
169
-
170
- it 'converts `0` to `false`' do
171
- request = described_class.new(api, nil, nil, nil, outline_detection: '0')
172
- expect(request.options[:outline_detection]).to be(false)
173
- end
174
-
175
- it 'converts `1` to `true`' do
176
- request = described_class.new(api, nil, nil, nil, outline_detection: '1')
177
- expect(request.options[:outline_detection]).to be(true)
178
- end
179
- end
180
-
181
- context 'when using `glossary_id` options' do
182
- it 'works with a nil values' do
183
- request = described_class.new(api, nil, nil, nil, glossary_id: nil)
184
- expect(request.options[:glossary_id]).to be_nil
185
- end
186
-
187
- it 'works with a string' do
188
- request = described_class.new(api, nil, nil, nil, glossary_id: 'sample_id')
189
- expect(request.options[:glossary_id]).to eq('sample_id')
190
- end
191
- end
192
-
193
- context 'when using `formality` options' do
194
- it 'works with a nil values' do
195
- request = described_class.new(api, nil, nil, nil, formality: nil)
196
- expect(request.options[:formality]).to be_nil
197
- end
198
-
199
- it 'works with a string' do
200
- request = described_class.new(api, nil, nil, nil, formality: 'more')
201
- expect(request.options[:formality]).to eq('more')
202
- end
203
-
204
- it 'works with provided constants' do
205
- request = described_class.new(api, nil, nil, nil,
206
- formality: DeepL::Constants::Formality::MORE)
207
- expect(request.options[:formality]).to eq('more')
208
- end
209
- end
210
-
211
- context 'when using `tag_handling_version` options' do
212
- it 'works with a nil value' do
213
- request = described_class.new(api, nil, nil, nil, tag_handling_version: nil)
214
- expect(request.options[:tag_handling_version]).to be_nil
215
- end
216
-
217
- it 'works with v1' do
218
- request = described_class.new(api, nil, nil, nil, tag_handling_version: 'v1')
219
- expect(request.options[:tag_handling_version]).to eq('v1')
220
- end
221
-
222
- it 'works with v2' do
223
- request = described_class.new(api, nil, nil, nil, tag_handling_version: 'v2')
224
- expect(request.options[:tag_handling_version]).to eq('v2')
225
- end
226
- end
227
-
228
- context 'when using `model_type` options' do
229
- it 'works with a nil value' do
230
- request = described_class.new(api, nil, nil, nil, model_type: nil)
231
- expect(request.options[:model_type]).to be_nil
232
- end
233
-
234
- it 'works with a string' do
235
- request = described_class.new(api, nil, nil, nil, model_type: 'latency_optimized')
236
- expect(request.options[:model_type]).to eq('latency_optimized')
237
- end
238
-
239
- it 'works with provided constants' do
240
- request = described_class.new(api, nil, nil, nil,
241
- model_type: DeepL::Constants::ModelType::LATENCY_OPTIMIZED)
242
- expect(request.options[:model_type]).to eq('latency_optimized')
243
- end
244
- end
245
-
246
- context 'when using `custom_instructions` options' do
247
- it 'works with a nil value' do
248
- request = described_class.new(api, nil, nil, nil, custom_instructions: nil)
249
- expect(request.options[:custom_instructions]).to be_nil
250
- end
251
-
252
- it 'works with an array of strings' do
253
- instructions = ['Use informal language', 'Be concise']
254
- request = described_class.new(api, nil, nil, nil, custom_instructions: instructions)
255
- expect(request.options[:custom_instructions]).to eq(instructions)
256
- end
257
-
258
- it 'works with a single string' do
259
- request = described_class.new(api, nil, nil, nil, custom_instructions: ['Be concise'])
260
- expect(request.options[:custom_instructions]).to eq(['Be concise'])
261
- end
262
-
263
- it 'works with a single string and converts it to an array' do
264
- instructions = 'Use informal language,Be concise'
265
- request = described_class.new(api, nil, nil, nil, custom_instructions: instructions)
266
- expect(request.options[:custom_instructions]).to eq(['Use informal language', 'Be concise'])
267
- end
268
- end
269
-
270
- context 'when passing additional headers' do
271
- it 'merges the headers into the request headers' do
272
- request = described_class.new(api, nil, nil, nil, {},
273
- { 'X-DeepL-Reporting-Tag' => 'my-tag' })
274
- expect(request.send(:headers)).to include('X-DeepL-Reporting-Tag' => 'my-tag')
275
- end
276
-
277
- it 'defaults to no additional headers' do
278
- request = described_class.new(api, nil, nil, nil)
279
- expect(request.send(:headers).keys).to contain_exactly('Authorization', 'User-Agent')
280
- end
281
- end
282
- end
283
- 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,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,35 +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::TranslationMemory do
9
- subject(:translation_memory) do
10
- described_class.new({
11
- 'translation_memory_id' => 'a74d88fb-ed2a-4943-a664-a4512398b994',
12
- 'name' => 'Legal',
13
- 'source_language' => 'en',
14
- 'target_languages' => %w[es de],
15
- 'segment_count' => 3542
16
- }, nil, nil)
17
- end
18
-
19
- describe '#initialize' do
20
- context 'when building a basic object' do
21
- it 'creates a resource' do
22
- expect(translation_memory).to be_a(described_class)
23
- end
24
-
25
- it 'assigns the attributes' do
26
- expect(translation_memory.translation_memory_id)
27
- .to eq('a74d88fb-ed2a-4943-a664-a4512398b994')
28
- expect(translation_memory.name).to eq('Legal')
29
- expect(translation_memory.source_language).to eq('en')
30
- expect(translation_memory.target_languages).to eq(%w[es de])
31
- expect(translation_memory.segment_count).to eq(3542)
32
- end
33
- end
34
- end
35
- end
@@ -1,35 +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::Usage do
9
- subject(:usage) { described_class.new(3, 5, nil, nil) }
10
-
11
- describe '#initialize' do
12
- context 'when building a basic object' do
13
- it 'creates a resource' do
14
- expect(usage).to be_a(described_class)
15
- end
16
-
17
- it 'assigns the attributes' do
18
- expect(usage.character_count).to eq(3)
19
- expect(usage.character_limit).to eq(5)
20
- end
21
-
22
- it 'does not exceed the quota' do
23
- expect(usage).not_to be_quota_exceeded
24
- end
25
- end
26
-
27
- context 'when building a quota exceeded object' do
28
- subject(:usage) { described_class.new(5, 5, nil, nil) }
29
-
30
- it 'exceeds the quota' do
31
- expect(usage).to be_quota_exceeded
32
- end
33
- end
34
- end
35
- end
@@ -1,12 +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
- # Shared setup for integration specs that hit the live mock server: expose an
7
- # API the server rejects as unauthorized without mutating global DeepL state.
8
- RSpec.shared_context 'with a live mock server' do
9
- let(:unauthorized_api) do
10
- DeepL::API.new(DeepL::Configuration.new(auth_key: 'invalid'))
11
- end
12
- end
@@ -1,17 +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 file.
4
- # frozen_string_literal: true
5
-
6
- module ManagedGlossary
7
- def with_managed_glossary(name:, source_lang:, target_lang:, entries:, options: {})
8
- glossary = DeepL.glossaries.create(name, source_lang, target_lang, entries, options)
9
- yield glossary
10
- ensure
11
- begin
12
- DeepL.glossaries.destroy(glossary.id) if glossary
13
- rescue StandardError
14
- nil
15
- end
16
- end
17
- end