deepl-rb 2.5.2 → 3.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.
- checksums.yaml +4 -4
- data/.github/workflows/add_issues_to_kanban.yml +16 -0
- data/.gitlab-ci.yml +135 -0
- data/.rubocop.yml +27 -0
- data/CHANGELOG.md +34 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +3 -1
- data/LICENSE.md +1 -0
- data/README.md +115 -5
- data/Rakefile +7 -5
- data/SECURITY.md +58 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +36 -20
- data/lib/deepl/api.rb +11 -1
- data/lib/deepl/configuration.rb +34 -3
- data/lib/deepl/document_api.rb +120 -0
- data/lib/deepl/exceptions/authorization_failed.rb +3 -0
- data/lib/deepl/exceptions/bad_request.rb +3 -0
- data/lib/deepl/exceptions/document_translation_error.rb +15 -0
- data/lib/deepl/exceptions/error.rb +6 -0
- data/lib/deepl/exceptions/limit_exceeded.rb +7 -0
- data/lib/deepl/exceptions/not_found.rb +3 -0
- data/lib/deepl/exceptions/not_supported.rb +3 -0
- data/lib/deepl/exceptions/quota_exceeded.rb +3 -0
- data/lib/deepl/exceptions/request_entity_too_large.rb +4 -1
- data/lib/deepl/exceptions/request_error.rb +4 -2
- data/lib/deepl/exceptions/server_error.rb +18 -0
- data/lib/deepl/glossary_api.rb +3 -0
- data/lib/deepl/requests/base.rb +89 -34
- data/lib/deepl/requests/document/download.rb +44 -0
- data/lib/deepl/requests/document/get_status.rb +44 -0
- data/lib/deepl/requests/document/upload.rb +64 -0
- data/lib/deepl/requests/glossary/create.rb +15 -1
- data/lib/deepl/requests/glossary/destroy.rb +8 -1
- data/lib/deepl/requests/glossary/entries.rb +8 -1
- data/lib/deepl/requests/glossary/find.rb +8 -1
- data/lib/deepl/requests/glossary/language_pairs.rb +9 -2
- data/lib/deepl/requests/glossary/list.rb +9 -2
- data/lib/deepl/requests/languages.rb +9 -2
- data/lib/deepl/requests/translate.rb +33 -11
- data/lib/deepl/requests/usage.rb +9 -2
- data/lib/deepl/resources/base.rb +3 -0
- data/lib/deepl/resources/document_handle.rb +57 -0
- data/lib/deepl/resources/document_translation_status.rb +54 -0
- data/lib/deepl/resources/glossary.rb +3 -0
- data/lib/deepl/resources/language.rb +3 -0
- data/lib/deepl/resources/language_pair.rb +3 -0
- data/lib/deepl/resources/text.rb +3 -0
- data/lib/deepl/resources/usage.rb +3 -0
- data/lib/deepl/utils/backoff_timer.rb +46 -0
- data/lib/deepl/utils/exception_builder.rb +18 -13
- data/lib/deepl.rb +47 -0
- data/lib/http_client_options.rb +22 -0
- data/license_checker.sh +8 -0
- data/spec/api/api_spec.rb +8 -4
- data/spec/api/configuration_spec.rb +92 -18
- data/spec/api/deepl_spec.rb +225 -86
- data/spec/fixtures/vcr_cassettes/deepl_document.yml +95 -0
- data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +1214 -0
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +812 -23
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +28 -17
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +161 -53
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +93 -3
- data/spec/fixtures/vcr_cassettes/glossaries.yml +1237 -15
- data/spec/fixtures/vcr_cassettes/languages.yml +159 -44
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +9742 -12
- data/spec/fixtures/vcr_cassettes/usage.yml +134 -2
- data/spec/integration_tests/document_api_spec.rb +143 -0
- data/spec/integration_tests/integration_test_utils.rb +170 -0
- data/spec/requests/glossary/create_spec.rb +23 -13
- data/spec/requests/glossary/destroy_spec.rb +33 -17
- data/spec/requests/glossary/entries_spec.rb +31 -17
- data/spec/requests/glossary/find_spec.rb +31 -17
- data/spec/requests/glossary/language_pairs_spec.rb +17 -7
- data/spec/requests/glossary/list_spec.rb +21 -11
- data/spec/requests/languages_spec.rb +31 -21
- data/spec/requests/translate_spec.rb +125 -131
- data/spec/requests/usage_spec.rb +17 -7
- data/spec/resources/glossary_spec.rb +15 -12
- data/spec/resources/language_pair_spec.rb +10 -7
- data/spec/resources/language_spec.rb +21 -18
- data/spec/resources/text_spec.rb +10 -7
- data/spec/resources/usage_spec.rb +16 -13
- data/spec/spec_helper.rb +63 -6
- metadata +32 -9
@@ -1,8 +1,19 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
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
|
+
|
6
17
|
let(:tags_str) { 'p,strong,span' }
|
7
18
|
let(:tags_array) { %w[p strong span] }
|
8
19
|
|
@@ -12,187 +23,170 @@ describe DeepL::Requests::Translate do
|
|
12
23
|
let(:target_lang) { 'ES' }
|
13
24
|
let(:options) { {} }
|
14
25
|
|
15
|
-
subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
|
16
|
-
|
17
26
|
describe '#initialize' do
|
18
|
-
context '
|
19
|
-
it '
|
20
|
-
expect(
|
27
|
+
context 'when building a request' do
|
28
|
+
it 'creates a request object' do
|
29
|
+
expect(translate).to be_a(described_class)
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
33
|
context 'when using `splitting_tags` options' do
|
25
|
-
it '
|
26
|
-
request =
|
27
|
-
expect(request.options[:splitting_tags]).to
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should work with a blank list' do
|
31
|
-
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: '')
|
32
|
-
expect(request.options[:splitting_tags]).to eq('')
|
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
|
33
37
|
end
|
34
38
|
|
35
|
-
it '
|
36
|
-
request =
|
37
|
-
expect(request.options[:splitting_tags]).to eq(
|
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([])
|
38
42
|
end
|
39
43
|
|
40
|
-
it '
|
41
|
-
request =
|
42
|
-
expect(request.options[:splitting_tags]).to eq(
|
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)
|
43
47
|
end
|
44
48
|
|
45
|
-
it '
|
46
|
-
request =
|
47
|
-
expect(request.options[:splitting_tags]).to eq(
|
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)
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
55
|
context 'when using `non_splitting_tags` options' do
|
52
|
-
it '
|
53
|
-
request =
|
54
|
-
expect(request.options[:non_splitting_tags]).to
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'should work with a blank list' do
|
58
|
-
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: '')
|
59
|
-
expect(request.options[:non_splitting_tags]).to eq('')
|
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
|
60
59
|
end
|
61
60
|
|
62
|
-
it '
|
63
|
-
request =
|
64
|
-
expect(request.options[:non_splitting_tags]).to eq(
|
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([])
|
65
64
|
end
|
66
65
|
|
67
|
-
it '
|
68
|
-
request =
|
69
|
-
expect(request.options[:non_splitting_tags]).to eq(
|
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)
|
70
69
|
end
|
71
70
|
|
72
|
-
it '
|
73
|
-
request =
|
74
|
-
expect(request.options[:non_splitting_tags]).to eq(
|
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)
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
78
77
|
context 'when using `ignore_tags` options' do
|
79
|
-
it '
|
80
|
-
request =
|
81
|
-
expect(request.options[:ignore_tags]).to
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should work with a blank list' do
|
85
|
-
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: '')
|
86
|
-
expect(request.options[:ignore_tags]).to eq('')
|
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
|
87
81
|
end
|
88
82
|
|
89
|
-
it '
|
90
|
-
request =
|
91
|
-
expect(request.options[:ignore_tags]).to eq(
|
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([])
|
92
86
|
end
|
93
87
|
|
94
|
-
it '
|
95
|
-
request =
|
96
|
-
expect(request.options[:ignore_tags]).to eq(
|
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)
|
97
91
|
end
|
98
92
|
|
99
|
-
it '
|
100
|
-
request =
|
101
|
-
expect(request.options[:ignore_tags]).to eq(
|
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)
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
105
99
|
context 'when using `split_sentences` options' do
|
106
|
-
it '
|
107
|
-
request =
|
100
|
+
it 'converts `true` to `1`' do
|
101
|
+
request = described_class.new(api, nil, nil, nil, split_sentences: true)
|
108
102
|
expect(request.options[:split_sentences]).to eq('1')
|
109
103
|
end
|
110
104
|
|
111
|
-
it '
|
112
|
-
request =
|
105
|
+
it 'converts `false` to `0`' do
|
106
|
+
request = described_class.new(api, nil, nil, nil, split_sentences: false)
|
113
107
|
expect(request.options[:split_sentences]).to eq('0')
|
114
108
|
end
|
115
109
|
|
116
|
-
it '
|
117
|
-
request =
|
110
|
+
it 'leaves `0` as is' do
|
111
|
+
request = described_class.new(api, nil, nil, nil, split_sentences: '0')
|
118
112
|
expect(request.options[:split_sentences]).to eq('0')
|
119
113
|
end
|
120
114
|
|
121
|
-
it '
|
122
|
-
request =
|
115
|
+
it 'leaves `nonewlines` as is' do
|
116
|
+
request = described_class.new(api, nil, nil, nil, split_sentences: 'nonewlines')
|
123
117
|
expect(request.options[:split_sentences]).to eq('nonewlines')
|
124
118
|
end
|
125
119
|
|
126
|
-
it '
|
127
|
-
request =
|
120
|
+
it 'leaves `1` as is' do
|
121
|
+
request = described_class.new(api, nil, nil, nil, split_sentences: '1')
|
128
122
|
expect(request.options[:split_sentences]).to eq('1')
|
129
123
|
end
|
130
124
|
end
|
131
125
|
|
132
126
|
context 'when using `preserve_formatting` options' do
|
133
|
-
it '
|
134
|
-
request =
|
135
|
-
expect(request.options[:preserve_formatting]).to
|
127
|
+
it 'leaves `true` as is' do
|
128
|
+
request = described_class.new(api, nil, nil, nil, preserve_formatting: true)
|
129
|
+
expect(request.options[:preserve_formatting]).to be(true)
|
136
130
|
end
|
137
131
|
|
138
|
-
it '
|
139
|
-
request =
|
140
|
-
expect(request.options[:preserve_formatting]).to
|
132
|
+
it 'leaves `false` as is' do
|
133
|
+
request = described_class.new(api, nil, nil, nil, preserve_formatting: false)
|
134
|
+
expect(request.options[:preserve_formatting]).to be(false)
|
141
135
|
end
|
142
136
|
|
143
|
-
it '
|
144
|
-
request =
|
145
|
-
expect(request.options[:preserve_formatting]).to
|
137
|
+
it 'converts `0` to `false`' do
|
138
|
+
request = described_class.new(api, nil, nil, nil, preserve_formatting: '0')
|
139
|
+
expect(request.options[:preserve_formatting]).to be(false)
|
146
140
|
end
|
147
141
|
|
148
|
-
it '
|
149
|
-
request =
|
150
|
-
expect(request.options[:preserve_formatting]).to
|
142
|
+
it 'converts `1` to `true`' do
|
143
|
+
request = described_class.new(api, nil, nil, nil, preserve_formatting: '1')
|
144
|
+
expect(request.options[:preserve_formatting]).to be(true)
|
151
145
|
end
|
152
146
|
end
|
153
147
|
|
154
148
|
context 'when using `outline_detection` options' do
|
155
|
-
it '
|
156
|
-
request =
|
157
|
-
expect(request.options[:outline_detection]).to
|
149
|
+
it 'leaves `true` as is' do
|
150
|
+
request = described_class.new(api, nil, nil, nil, outline_detection: true)
|
151
|
+
expect(request.options[:outline_detection]).to be(true)
|
158
152
|
end
|
159
153
|
|
160
|
-
it '
|
161
|
-
request =
|
162
|
-
expect(request.options[:outline_detection]).to
|
154
|
+
it 'leaves `false` as is' do
|
155
|
+
request = described_class.new(api, nil, nil, nil, outline_detection: false)
|
156
|
+
expect(request.options[:outline_detection]).to be(false)
|
163
157
|
end
|
164
158
|
|
165
|
-
it '
|
166
|
-
request =
|
167
|
-
expect(request.options[:outline_detection]).to
|
159
|
+
it 'converts `0` to `false`' do
|
160
|
+
request = described_class.new(api, nil, nil, nil, outline_detection: '0')
|
161
|
+
expect(request.options[:outline_detection]).to be(false)
|
168
162
|
end
|
169
163
|
|
170
|
-
it '
|
171
|
-
request =
|
172
|
-
expect(request.options[:outline_detection]).to
|
164
|
+
it 'converts `1` to `true`' do
|
165
|
+
request = described_class.new(api, nil, nil, nil, outline_detection: '1')
|
166
|
+
expect(request.options[:outline_detection]).to be(true)
|
173
167
|
end
|
174
168
|
end
|
175
169
|
|
176
170
|
context 'when using `glossary_id` options' do
|
177
|
-
it '
|
178
|
-
request =
|
179
|
-
expect(request.options[:glossary_id]).to
|
171
|
+
it 'works with a nil values' do
|
172
|
+
request = described_class.new(api, nil, nil, nil, glossary_id: nil)
|
173
|
+
expect(request.options[:glossary_id]).to be_nil
|
180
174
|
end
|
181
175
|
|
182
|
-
it '
|
183
|
-
request =
|
176
|
+
it 'works with a string' do
|
177
|
+
request = described_class.new(api, nil, nil, nil, glossary_id: 'sample_id')
|
184
178
|
expect(request.options[:glossary_id]).to eq('sample_id')
|
185
179
|
end
|
186
180
|
end
|
187
181
|
|
188
182
|
context 'when using `formality` options' do
|
189
|
-
it '
|
190
|
-
request =
|
191
|
-
expect(request.options[:formality]).to
|
183
|
+
it 'works with a nil values' do
|
184
|
+
request = described_class.new(api, nil, nil, nil, formality: nil)
|
185
|
+
expect(request.options[:formality]).to be_nil
|
192
186
|
end
|
193
187
|
|
194
|
-
it '
|
195
|
-
request =
|
188
|
+
it 'works with a string' do
|
189
|
+
request = described_class.new(api, nil, nil, nil, formality: 'more')
|
196
190
|
expect(request.options[:formality]).to eq('more')
|
197
191
|
end
|
198
192
|
end
|
@@ -203,9 +197,9 @@ describe DeepL::Requests::Translate do
|
|
203
197
|
VCR.use_cassette('translate_texts') { example.call }
|
204
198
|
end
|
205
199
|
|
206
|
-
context '
|
207
|
-
it '
|
208
|
-
text =
|
200
|
+
context 'when performing a valid request with one text' do
|
201
|
+
it 'returns a text object' do
|
202
|
+
text = translate.request
|
209
203
|
|
210
204
|
expect(text).to be_a(DeepL::Resources::Text)
|
211
205
|
expect(text.text).to eq('Texto de muestra')
|
@@ -213,11 +207,11 @@ describe DeepL::Requests::Translate do
|
|
213
207
|
end
|
214
208
|
end
|
215
209
|
|
216
|
-
context '
|
210
|
+
context 'when performing a valid request with multiple texts' do
|
217
211
|
let(:text) { %w[Sample Word] }
|
218
212
|
|
219
|
-
it '
|
220
|
-
texts =
|
213
|
+
it 'returns a text object' do
|
214
|
+
texts = translate.request
|
221
215
|
|
222
216
|
expect(texts).to be_a(Array)
|
223
217
|
expect(texts.first.text).to eq('Muestra')
|
@@ -228,12 +222,12 @@ describe DeepL::Requests::Translate do
|
|
228
222
|
end
|
229
223
|
end
|
230
224
|
|
231
|
-
context '
|
225
|
+
context 'when performing a valid request with tag handling' do
|
232
226
|
let(:text) { '<p>Sample text</p>' }
|
233
227
|
let(:options) { { tag_handling: 'xml' } }
|
234
228
|
|
235
|
-
it '
|
236
|
-
text =
|
229
|
+
it 'returns a text object' do
|
230
|
+
text = translate.request
|
237
231
|
|
238
232
|
expect(text).to be_a(DeepL::Resources::Text)
|
239
233
|
expect(text.text).to eq('<p>Texto de muestra</p>')
|
@@ -241,12 +235,12 @@ describe DeepL::Requests::Translate do
|
|
241
235
|
end
|
242
236
|
end
|
243
237
|
|
244
|
-
context '
|
238
|
+
context 'when performing a valid request and passing a variable' do
|
245
239
|
let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
|
246
240
|
let(:options) { { tag_handling: 'xml', ignore_tags: %w[code span] } }
|
247
241
|
|
248
|
-
it '
|
249
|
-
text =
|
242
|
+
it 'returns a text object' do
|
243
|
+
text = translate.request
|
250
244
|
|
251
245
|
expect(text).to be_a(DeepL::Resources::Text)
|
252
246
|
expect(text.text).to eq('Bienvenido y <code>Hello great World</code> ¡Buenos días!')
|
@@ -254,7 +248,7 @@ describe DeepL::Requests::Translate do
|
|
254
248
|
end
|
255
249
|
end
|
256
250
|
|
257
|
-
context '
|
251
|
+
context 'when performing a valid request with an HTML document' do
|
258
252
|
let(:text) do
|
259
253
|
<<~XML
|
260
254
|
<document>
|
@@ -277,15 +271,15 @@ describe DeepL::Requests::Translate do
|
|
277
271
|
}
|
278
272
|
end
|
279
273
|
|
280
|
-
it '
|
281
|
-
text =
|
274
|
+
it 'returns a text object' do
|
275
|
+
text = translate.request
|
282
276
|
|
283
277
|
expect(text).to be_a(DeepL::Resources::Text)
|
284
278
|
expect(text.text).to eq(
|
285
279
|
<<~XML
|
286
280
|
<document>
|
287
281
|
<meta>
|
288
|
-
<title>
|
282
|
+
<title>Título de un documento</title>
|
289
283
|
</meta>
|
290
284
|
<content>
|
291
285
|
<par>Es la primera frase. Seguido de una segunda.</par>
|
@@ -298,44 +292,44 @@ describe DeepL::Requests::Translate do
|
|
298
292
|
end
|
299
293
|
end
|
300
294
|
|
301
|
-
context '
|
302
|
-
context '
|
295
|
+
context 'when performing a bad request' do
|
296
|
+
context 'when using an invalid token' do
|
303
297
|
let(:api) do
|
304
298
|
api = build_deepl_api
|
305
299
|
api.configuration.auth_key = 'invalid'
|
306
300
|
api
|
307
301
|
end
|
308
302
|
|
309
|
-
it '
|
310
|
-
expect {
|
303
|
+
it 'raises an unauthorized error' do
|
304
|
+
expect { translate.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
311
305
|
end
|
312
306
|
end
|
313
307
|
|
314
|
-
context '
|
308
|
+
context 'when using an invalid text' do
|
315
309
|
let(:text) { nil }
|
316
310
|
|
317
|
-
it '
|
318
|
-
message = "
|
319
|
-
expect {
|
311
|
+
it 'raises a bad request error' do
|
312
|
+
message = "Invalid request: Expected 'text' parameter to be an array of strings"
|
313
|
+
expect { translate.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
320
314
|
end
|
321
315
|
end
|
322
316
|
|
323
|
-
context '
|
317
|
+
context 'when using an invalid target language' do
|
324
318
|
let(:target_lang) { nil }
|
325
319
|
|
326
|
-
it '
|
320
|
+
it 'raises a bad request error' do
|
327
321
|
message = "Value for 'target_lang' not supported."
|
328
|
-
expect {
|
322
|
+
expect { translate.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
329
323
|
end
|
330
324
|
end
|
331
325
|
end
|
332
326
|
|
333
|
-
context '
|
327
|
+
context 'when performing a request with too many texts' do
|
334
328
|
let(:text) { Array.new(10_000) { |i| "This is the sentence number #{i}" } }
|
335
329
|
|
336
|
-
it '
|
337
|
-
expect {
|
338
|
-
|
330
|
+
it 'raises a request entity too large error' do
|
331
|
+
expect { translate.request }.to raise_error(DeepL::Exceptions::RequestEntityTooLarge,
|
332
|
+
/request size has reached the supported limit/)
|
339
333
|
end
|
340
334
|
end
|
341
335
|
end
|
data/spec/requests/usage_spec.rb
CHANGED
@@ -1,16 +1,26 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
18
|
let(:options) { {} }
|
8
|
-
subject { DeepL::Requests::Usage.new(api, options) }
|
9
19
|
|
10
20
|
describe '#initialize' do
|
11
|
-
context '
|
12
|
-
it '
|
13
|
-
expect(
|
21
|
+
context 'when building a request' do
|
22
|
+
it 'creates a request object' do
|
23
|
+
expect(usage_req).to be_a(described_class)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -20,9 +30,9 @@ describe DeepL::Requests::Usage do
|
|
20
30
|
VCR.use_cassette('usage') { example.call }
|
21
31
|
end
|
22
32
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
usage =
|
33
|
+
context 'when performing a valid request' do
|
34
|
+
it 'returns an usage object' do
|
35
|
+
usage = usage_req.request
|
26
36
|
|
27
37
|
expect(usage).to be_a(DeepL::Resources::Usage)
|
28
38
|
expect(usage.character_count).to be_a(Numeric)
|
@@ -1,9 +1,12 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::Resources::Glossary do
|
6
|
-
subject do
|
9
|
+
subject(:glossary) do
|
7
10
|
described_class.new({
|
8
11
|
'glossary_id' => 'def3a26b-3e84-45b3-84ae-0c0aaf3525f7',
|
9
12
|
'name' => 'Mein Glossar',
|
@@ -16,19 +19,19 @@ describe DeepL::Resources::Glossary do
|
|
16
19
|
end
|
17
20
|
|
18
21
|
describe '#initialize' do
|
19
|
-
context '
|
20
|
-
it '
|
21
|
-
expect(
|
22
|
+
context 'when building a basic object' do
|
23
|
+
it 'creates a resource' do
|
24
|
+
expect(glossary).to be_a(described_class)
|
22
25
|
end
|
23
26
|
|
24
|
-
it '
|
25
|
-
expect(
|
26
|
-
expect(
|
27
|
-
expect(
|
28
|
-
expect(
|
29
|
-
expect(
|
30
|
-
expect(
|
31
|
-
expect(
|
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)
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
@@ -1,19 +1,22 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::Resources::LanguagePair do
|
6
|
-
subject { described_class.new('en', 'de', nil, nil) }
|
9
|
+
subject(:language_pair) { described_class.new('en', 'de', nil, nil) }
|
7
10
|
|
8
11
|
describe '#initialize' do
|
9
|
-
context '
|
10
|
-
it '
|
11
|
-
expect(
|
12
|
+
context 'when building a basic object' do
|
13
|
+
it 'creates a resource' do
|
14
|
+
expect(language_pair).to be_a(described_class)
|
12
15
|
end
|
13
16
|
|
14
|
-
it '
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
+
it 'assigns the attributes' do
|
18
|
+
expect(language_pair.source_lang).to eq('en')
|
19
|
+
expect(language_pair.target_lang).to eq('de')
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -1,41 +1,44 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::Resources::Language do
|
6
|
-
subject { described_class.new('EN', 'English', nil, nil, nil) }
|
9
|
+
subject(:language) { described_class.new('EN', 'English', nil, nil, nil) }
|
7
10
|
|
8
11
|
describe '#initialize' do
|
9
|
-
context '
|
10
|
-
it '
|
11
|
-
expect(
|
12
|
+
context 'when building a basic object' do
|
13
|
+
it 'creates a resource' do
|
14
|
+
expect(language).to be_a(described_class)
|
12
15
|
end
|
13
16
|
|
14
|
-
it '
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
+
it 'assigns the attributes' do
|
18
|
+
expect(language.code).to eq('EN')
|
19
|
+
expect(language.name).to eq('English')
|
17
20
|
end
|
18
21
|
|
19
|
-
it '
|
20
|
-
expect {
|
22
|
+
it 'does not define the supports formality method' do
|
23
|
+
expect { language.supports_formality? }.to raise_error(DeepL::Exceptions::NotSupported)
|
21
24
|
end
|
22
25
|
end
|
23
26
|
|
24
27
|
context 'when building a target language object' do
|
25
|
-
subject { described_class.new('EN', 'English', true, nil, nil) }
|
28
|
+
subject(:language) { described_class.new('EN', 'English', true, nil, nil) }
|
26
29
|
|
27
|
-
it '
|
28
|
-
expect(
|
30
|
+
it 'creates a resource' do
|
31
|
+
expect(language).to be_a(described_class)
|
29
32
|
end
|
30
33
|
|
31
|
-
it '
|
32
|
-
expect(
|
33
|
-
expect(
|
34
|
+
it 'assigns the attributes' do
|
35
|
+
expect(language.code).to eq('EN')
|
36
|
+
expect(language.name).to eq('English')
|
34
37
|
end
|
35
38
|
|
36
|
-
it '
|
37
|
-
expect {
|
38
|
-
expect(
|
39
|
+
it 'includes the supports formality method' do
|
40
|
+
expect { language.supports_formality? }.not_to raise_error
|
41
|
+
expect(language).to be_supports_formality
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
data/spec/resources/text_spec.rb
CHANGED
@@ -1,19 +1,22 @@
|
|
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.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::Resources::Text do
|
6
|
-
subject { described_class.new('Target', 'es', nil, nil) }
|
9
|
+
subject(:text) { described_class.new('Target', 'es', nil, nil) }
|
7
10
|
|
8
11
|
describe '#initialize' do
|
9
|
-
context '
|
10
|
-
it '
|
11
|
-
expect(
|
12
|
+
context 'when building a basic object' do
|
13
|
+
it 'creates a resource' do
|
14
|
+
expect(text).to be_a(described_class)
|
12
15
|
end
|
13
16
|
|
14
|
-
it '
|
15
|
-
expect(
|
16
|
-
expect(
|
17
|
+
it 'assigns the attributes' do
|
18
|
+
expect(text.text).to eq('Target')
|
19
|
+
expect(text.detected_source_language).to eq('es')
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|