deepl-rb 2.5.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +3 -0
- 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
data/spec/api/deepl_spec.rb
CHANGED
@@ -1,40 +1,55 @@
|
|
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'
|
7
|
+
require 'tempfile'
|
4
8
|
|
5
9
|
describe DeepL do
|
6
|
-
subject {
|
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
|
7
17
|
|
8
18
|
describe '#configure' do
|
9
|
-
context '
|
19
|
+
context 'when providing no block' do
|
10
20
|
let(:configuration) { DeepL::Configuration.new }
|
11
|
-
before { subject.configure }
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
before do
|
23
|
+
deepl.configure
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'uses default configuration' do
|
27
|
+
expect(deepl.configuration).to eq(configuration)
|
15
28
|
end
|
16
29
|
end
|
17
30
|
|
18
|
-
context '
|
31
|
+
context 'when providing a valid configuration' do
|
19
32
|
let(:configuration) do
|
20
|
-
DeepL::Configuration.new(auth_key: 'VALID', host: 'http://www.example.org',
|
33
|
+
DeepL::Configuration.new({ auth_key: 'VALID', host: 'http://www.example.org',
|
34
|
+
version: 'v1' })
|
21
35
|
end
|
36
|
+
|
22
37
|
before do
|
23
|
-
|
38
|
+
deepl.configure do |config|
|
24
39
|
config.auth_key = configuration.auth_key
|
25
40
|
config.host = configuration.host
|
26
41
|
config.version = configuration.version
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
30
|
-
it '
|
31
|
-
expect(
|
45
|
+
it 'uses the provided configuration' do
|
46
|
+
expect(deepl.configuration).to eq(configuration)
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
35
|
-
context '
|
36
|
-
it '
|
37
|
-
expect {
|
50
|
+
context 'when providing an invalid configuration' do
|
51
|
+
it 'raises an error' do
|
52
|
+
expect { deepl.configure { |c| c.auth_key = '' } }
|
38
53
|
.to raise_error(DeepL::Exceptions::Error)
|
39
54
|
end
|
40
55
|
end
|
@@ -47,37 +62,40 @@ describe DeepL do
|
|
47
62
|
let(:options) { { param: 'fake' } }
|
48
63
|
|
49
64
|
around do |example|
|
50
|
-
|
65
|
+
deepl.configure
|
51
66
|
VCR.use_cassette('deepl_translate') { example.call }
|
52
67
|
end
|
53
68
|
|
54
|
-
context '
|
55
|
-
it '
|
69
|
+
context 'when translating a text' do
|
70
|
+
it 'creates and call a request object' do
|
56
71
|
expect(DeepL::Requests::Translate).to receive(:new)
|
57
|
-
.with(
|
72
|
+
.with(deepl.api, input, source_lang, target_lang, options).and_call_original
|
58
73
|
|
59
|
-
text =
|
74
|
+
text = deepl.translate(input, source_lang, target_lang, options)
|
60
75
|
expect(text).to be_a(DeepL::Resources::Text)
|
61
76
|
end
|
62
77
|
end
|
63
78
|
|
64
|
-
context '
|
65
|
-
before
|
66
|
-
@glossary =
|
79
|
+
context 'when translating a text using a glossary' do
|
80
|
+
before do
|
81
|
+
@glossary = deepl.glossaries.create('fixture', 'EN', 'ES', [%w[car auto]])
|
67
82
|
end
|
83
|
+
|
68
84
|
let(:input) { 'I wish we had a car.' }
|
85
|
+
# rubocop:disable RSpec/InstanceVariable
|
69
86
|
let(:options) { { glossary_id: @glossary.id } }
|
70
87
|
|
71
|
-
|
72
|
-
|
73
|
-
.with(subject.api, input, source_lang, target_lang, options).and_call_original
|
74
|
-
text = subject.translate(input, source_lang, target_lang, options)
|
75
|
-
expect(text).to be_a(DeepL::Resources::Text)
|
76
|
-
expect(text.text).to eq('Ojalá tuviéramos un auto.')
|
88
|
+
after do
|
89
|
+
deepl.glossaries.destroy(@glossary.id)
|
77
90
|
end
|
91
|
+
# rubocop:enable RSpec/InstanceVariable
|
78
92
|
|
79
|
-
|
80
|
-
|
93
|
+
it 'creates and call a request object' do
|
94
|
+
expect(DeepL::Requests::Translate).to receive(:new)
|
95
|
+
.with(deepl.api, input, source_lang, target_lang, options).and_call_original
|
96
|
+
text = deepl.translate(input, source_lang, target_lang, options)
|
97
|
+
expect(text).to be_a(DeepL::Resources::Text)
|
98
|
+
expect(text.text).to eq('Ojalá tuviéramos auto.')
|
81
99
|
end
|
82
100
|
end
|
83
101
|
end
|
@@ -86,37 +104,157 @@ describe DeepL do
|
|
86
104
|
let(:options) { {} }
|
87
105
|
|
88
106
|
around do |example|
|
89
|
-
|
107
|
+
deepl.configure
|
90
108
|
VCR.use_cassette('deepl_usage') { example.call }
|
91
109
|
end
|
92
110
|
|
93
|
-
context '
|
94
|
-
it '
|
111
|
+
context 'when checking usage' do
|
112
|
+
it 'creates and call a request object' do
|
95
113
|
expect(DeepL::Requests::Usage).to receive(:new)
|
96
|
-
.with(
|
114
|
+
.with(deepl.api, options).and_call_original
|
97
115
|
|
98
|
-
usage =
|
116
|
+
usage = deepl.usage(options)
|
99
117
|
expect(usage).to be_a(DeepL::Resources::Usage)
|
100
118
|
end
|
101
119
|
end
|
102
120
|
end
|
103
121
|
|
122
|
+
# rubocop:disable RSpec/InstanceVariable
|
123
|
+
describe '#document' do
|
124
|
+
describe '#document.upload' do
|
125
|
+
before do
|
126
|
+
@tmpfile = Tempfile.new('foo')
|
127
|
+
@tmpfile.write("Geology for Beginners Report
|
128
|
+
A test report for the DeepL API
|
129
|
+
It is with great pleasure, that I, Urna Semper, write this fake document on geology.
|
130
|
+
Geology is an excellent field that deals with how to extract oil from the earth.")
|
131
|
+
@tmpfile.close
|
132
|
+
end
|
133
|
+
|
134
|
+
after do
|
135
|
+
@tmpfile.unlink
|
136
|
+
end
|
137
|
+
|
138
|
+
let(:input_file) { @tmpfile.path }
|
139
|
+
let(:source_lang) { 'EN' }
|
140
|
+
let(:target_lang) { 'ES' }
|
141
|
+
let(:output_file) { 'test_translated_doc.txt' }
|
142
|
+
let(:options) { { param: 'fake' } }
|
143
|
+
let(:additional_headers) { { 'Fake-Header': 'fake_value' } }
|
144
|
+
|
145
|
+
around do |example|
|
146
|
+
deepl.configure
|
147
|
+
VCR.use_cassette('deepl_document') { example.call }
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when uploading a document' do
|
151
|
+
it 'creates an upload object' do
|
152
|
+
expect(DeepL::Requests::Document::Upload).to receive(:new)
|
153
|
+
.with(deepl.api, input_file, source_lang, target_lang,
|
154
|
+
"#{File.basename(@tmpfile.path)}.txt", options,
|
155
|
+
additional_headers).and_call_original
|
156
|
+
doc_handle = deepl.document.upload(input_file, source_lang, target_lang,
|
157
|
+
"#{File.basename(@tmpfile.path)}.txt", options,
|
158
|
+
additional_headers)
|
159
|
+
expect(doc_handle).to be_a(DeepL::Resources::DocumentHandle)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
# rubocop:enable RSpec/InstanceVariable
|
164
|
+
|
165
|
+
describe '#document.get_status' do
|
166
|
+
let(:document_handle) do
|
167
|
+
DeepL::Resources::DocumentHandle.new('9B7CB9418DCDEBF2C4C519F65A32B99F',
|
168
|
+
'EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815', # rubocop:disable Layout/LineLength
|
169
|
+
nil,
|
170
|
+
nil)
|
171
|
+
end
|
172
|
+
let(:options) { { param: 'fake' } }
|
173
|
+
let(:additional_headers) { { 'Fake-Header': 'fake_value' } }
|
174
|
+
|
175
|
+
around do |example|
|
176
|
+
deepl.configure
|
177
|
+
VCR.use_cassette('deepl_document') { example.call }
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when querying the status of a document' do
|
181
|
+
it 'creates a GetStatus object' do
|
182
|
+
expect(DeepL::Requests::Document::GetStatus).to receive(:new)
|
183
|
+
.with(
|
184
|
+
deepl.api,
|
185
|
+
document_handle.document_id,
|
186
|
+
document_handle.document_key,
|
187
|
+
options,
|
188
|
+
additional_headers
|
189
|
+
).and_call_original
|
190
|
+
status = deepl.document.get_status(document_handle, options, additional_headers)
|
191
|
+
expect(status).to be_a(DeepL::Resources::DocumentTranslationStatus)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
# rubocop:disable RSpec/InstanceVariable
|
197
|
+
describe '#document.download' do
|
198
|
+
before do
|
199
|
+
@tmpfile = Tempfile.new('bar')
|
200
|
+
end
|
201
|
+
|
202
|
+
after do
|
203
|
+
@tmpfile.close
|
204
|
+
@tmpfile.unlink
|
205
|
+
end
|
206
|
+
|
207
|
+
let(:document_handle) do
|
208
|
+
DeepL::Resources::DocumentHandle.new('9B7CB9418DCDEBF2C4C519F65A32B99F',
|
209
|
+
'EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815', # rubocop:disable Layout/LineLength
|
210
|
+
nil,
|
211
|
+
nil)
|
212
|
+
end
|
213
|
+
let(:output_file_path) { @tmpfile.path }
|
214
|
+
let(:options) { { param: 'fake' } }
|
215
|
+
|
216
|
+
around do |example|
|
217
|
+
deepl.configure
|
218
|
+
VCR.use_cassette('deepl_document_download', preserve_exact_body_bytes: true) do
|
219
|
+
example.call
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'when downloading a document' do
|
224
|
+
it 'creates an downloading object and writes to the output file' do # rubocop:disable RSpec/ExampleLength
|
225
|
+
expect(DeepL::Requests::Document::Download).to receive(:new)
|
226
|
+
.with(
|
227
|
+
deepl.api,
|
228
|
+
document_handle.document_id,
|
229
|
+
document_handle.document_key,
|
230
|
+
output_file_path
|
231
|
+
).and_call_original
|
232
|
+
deepl.document.download(document_handle, output_file_path)
|
233
|
+
file_contents = File.read(output_file_path)
|
234
|
+
expect(file_contents).to be_a(String)
|
235
|
+
expect(file_contents.length).to be > 200
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
# rubocop:enable RSpec/InstanceVariable
|
241
|
+
|
104
242
|
describe '#languages' do
|
105
243
|
let(:options) { { type: :target } }
|
106
244
|
|
107
245
|
around do |example|
|
108
|
-
|
246
|
+
deepl.configure
|
109
247
|
VCR.use_cassette('deepl_languages') { example.call }
|
110
248
|
end
|
111
249
|
|
112
|
-
context '
|
113
|
-
it '
|
250
|
+
context 'when checking languages' do
|
251
|
+
it 'creates and call a request object' do
|
114
252
|
expect(DeepL::Requests::Languages).to receive(:new)
|
115
|
-
.with(
|
253
|
+
.with(deepl.api, options).and_call_original
|
116
254
|
|
117
|
-
languages =
|
255
|
+
languages = deepl.languages(options)
|
118
256
|
expect(languages).to be_an(Array)
|
119
|
-
expect(languages.
|
257
|
+
expect(languages).to(be_all { |l| l.is_a?(DeepL::Resources::Language) })
|
120
258
|
end
|
121
259
|
end
|
122
260
|
end
|
@@ -135,47 +273,47 @@ describe DeepL do
|
|
135
273
|
let(:options) { { param: 'fake', entries_format: 'tsv' } }
|
136
274
|
|
137
275
|
around do |example|
|
138
|
-
|
276
|
+
deepl.configure
|
139
277
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
140
278
|
end
|
141
279
|
|
142
|
-
context '
|
143
|
-
it '
|
280
|
+
context 'when creating a glossary' do
|
281
|
+
it 'creates and call a request object' do
|
144
282
|
expect(DeepL::Requests::Glossary::Create).to receive(:new)
|
145
|
-
.with(
|
283
|
+
.with(deepl.api, name, source_lang, target_lang, entries, options).and_call_original
|
146
284
|
|
147
|
-
glossary =
|
285
|
+
glossary = deepl.glossaries.create(name, source_lang, target_lang, entries, options)
|
148
286
|
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
149
287
|
end
|
150
288
|
end
|
151
289
|
end
|
152
290
|
|
153
291
|
describe '#glossaries.find' do
|
154
|
-
let(:id) { '
|
292
|
+
let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
|
155
293
|
let(:options) { {} }
|
156
294
|
|
157
295
|
around do |example|
|
158
|
-
|
296
|
+
deepl.configure
|
159
297
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
160
298
|
end
|
161
299
|
|
162
|
-
context '
|
163
|
-
it '
|
300
|
+
context 'when fetching a glossary' do
|
301
|
+
it 'creates and call a request object' do
|
164
302
|
expect(DeepL::Requests::Glossary::Find).to receive(:new)
|
165
|
-
.with(
|
303
|
+
.with(deepl.api, id, options).and_call_original
|
166
304
|
|
167
|
-
glossary =
|
305
|
+
glossary = deepl.glossaries.find(id, options)
|
168
306
|
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
169
307
|
end
|
170
308
|
end
|
171
309
|
|
172
|
-
context '
|
310
|
+
context 'when fetching a non existing glossary' do
|
173
311
|
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
174
312
|
|
175
|
-
it '
|
313
|
+
it 'raises an exception when the glossary does not exist' do
|
176
314
|
expect(DeepL::Requests::Glossary::Find).to receive(:new)
|
177
|
-
.with(
|
178
|
-
expect {
|
315
|
+
.with(deepl.api, id, options).and_call_original
|
316
|
+
expect { deepl.glossaries.find(id, options) }
|
179
317
|
.to raise_error(DeepL::Exceptions::NotFound)
|
180
318
|
end
|
181
319
|
end
|
@@ -185,70 +323,71 @@ describe DeepL do
|
|
185
323
|
let(:options) { {} }
|
186
324
|
|
187
325
|
around do |example|
|
188
|
-
|
326
|
+
deepl.configure
|
189
327
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
190
328
|
end
|
191
329
|
|
192
|
-
context '
|
193
|
-
it '
|
330
|
+
context 'when fetching glossaries' do
|
331
|
+
it 'creates and call a request object' do
|
194
332
|
expect(DeepL::Requests::Glossary::List).to receive(:new)
|
195
|
-
.with(
|
333
|
+
.with(deepl.api, options).and_call_original
|
196
334
|
|
197
|
-
glossaries =
|
335
|
+
glossaries = deepl.glossaries.list(options)
|
198
336
|
expect(glossaries).to all(be_a(DeepL::Resources::Glossary))
|
199
337
|
end
|
200
338
|
end
|
201
339
|
end
|
202
340
|
|
203
341
|
describe '#glossaries.destroy' do
|
204
|
-
let(:id) { '
|
342
|
+
let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
|
205
343
|
let(:options) { {} }
|
206
344
|
|
207
345
|
around do |example|
|
208
|
-
|
346
|
+
deepl.configure
|
209
347
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
210
348
|
end
|
211
349
|
|
212
|
-
context '
|
350
|
+
context 'when destroy a glossary' do
|
213
351
|
let(:new_glossary) do
|
214
|
-
|
352
|
+
deepl.glossaries.create('fixture', 'EN', 'ES', [%w[Hello Hola]])
|
215
353
|
end
|
216
|
-
|
354
|
+
|
355
|
+
it 'creates and call a request object' do
|
217
356
|
expect(DeepL::Requests::Glossary::Destroy).to receive(:new)
|
218
|
-
.with(
|
357
|
+
.with(deepl.api, new_glossary.id, options).and_call_original
|
219
358
|
|
220
|
-
glossary_id =
|
359
|
+
glossary_id = deepl.glossaries.destroy(new_glossary.id, options)
|
221
360
|
expect(glossary_id).to eq(new_glossary.id)
|
222
361
|
end
|
223
362
|
end
|
224
363
|
|
225
|
-
context '
|
364
|
+
context 'when destroying a non existing glossary' do
|
226
365
|
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
227
366
|
|
228
|
-
it '
|
367
|
+
it 'raises an exception when the glossary does not exist' do
|
229
368
|
expect(DeepL::Requests::Glossary::Destroy).to receive(:new)
|
230
|
-
.with(
|
231
|
-
expect {
|
369
|
+
.with(deepl.api, id, options).and_call_original
|
370
|
+
expect { deepl.glossaries.destroy(id, options) }
|
232
371
|
.to raise_error(DeepL::Exceptions::NotFound)
|
233
372
|
end
|
234
373
|
end
|
235
374
|
end
|
236
375
|
|
237
376
|
describe '#glossaries.entries' do
|
238
|
-
let(:id) { '
|
377
|
+
let(:id) { 'e7a62637-7ef4-4959-a355-09ba61dd0126' }
|
239
378
|
let(:options) { {} }
|
240
379
|
|
241
380
|
around do |example|
|
242
|
-
|
381
|
+
deepl.configure
|
243
382
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
244
383
|
end
|
245
384
|
|
246
|
-
context '
|
247
|
-
it '
|
385
|
+
context 'when listing glossary entries' do
|
386
|
+
it 'creates and call a request object' do
|
248
387
|
expect(DeepL::Requests::Glossary::Entries).to receive(:new)
|
249
|
-
.with(
|
388
|
+
.with(deepl.api, id, options).and_call_original
|
250
389
|
|
251
|
-
entries =
|
390
|
+
entries = deepl.glossaries.entries(id, options)
|
252
391
|
expect(entries).to all(be_a(Array))
|
253
392
|
entries.each do |entry|
|
254
393
|
expect(entry.size).to eq(2)
|
@@ -258,13 +397,13 @@ describe DeepL do
|
|
258
397
|
end
|
259
398
|
end
|
260
399
|
|
261
|
-
context '
|
400
|
+
context 'when listing entries of a non existing glossary' do
|
262
401
|
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
263
402
|
|
264
|
-
it '
|
403
|
+
it 'raises an exception when the glossary does not exist' do
|
265
404
|
expect(DeepL::Requests::Glossary::Entries).to receive(:new)
|
266
|
-
.with(
|
267
|
-
expect {
|
405
|
+
.with(deepl.api, id, options).and_call_original
|
406
|
+
expect { deepl.glossaries.entries(id, options) }
|
268
407
|
.to raise_error(DeepL::Exceptions::NotFound)
|
269
408
|
end
|
270
409
|
end
|
@@ -274,16 +413,16 @@ describe DeepL do
|
|
274
413
|
let(:options) { {} }
|
275
414
|
|
276
415
|
around do |example|
|
277
|
-
|
416
|
+
deepl.configure
|
278
417
|
VCR.use_cassette('deepl_glossaries') { example.call }
|
279
418
|
end
|
280
419
|
|
281
|
-
context '
|
282
|
-
it '
|
420
|
+
context 'when fetching language pairs supported by glossaries' do
|
421
|
+
it 'creates and call a request object' do
|
283
422
|
expect(DeepL::Requests::Glossary::LanguagePairs).to receive(:new)
|
284
|
-
.with(
|
423
|
+
.with(deepl.api, options).and_call_original
|
285
424
|
|
286
|
-
language_pairs =
|
425
|
+
language_pairs = deepl.glossaries.language_pairs(options)
|
287
426
|
expect(language_pairs).to all(be_a(DeepL::Resources::LanguagePair))
|
288
427
|
end
|
289
428
|
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.deepl.com/v2/document
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
12
|
+
User-Agent:
|
13
|
+
- deepl-ruby/2.5.3 (darwin23) ruby/3.3.3
|
14
|
+
Content-Type:
|
15
|
+
- multipart/form-data
|
16
|
+
Accept-Encoding:
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
18
|
+
Accept:
|
19
|
+
- "*/*"
|
20
|
+
Fake-Header:
|
21
|
+
- fake_value
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Date:
|
28
|
+
- Tue, 09 Jul 2024 02:02:17 GMT
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
Transfer-Encoding:
|
32
|
+
- chunked
|
33
|
+
Vary:
|
34
|
+
- Accept-Encoding
|
35
|
+
Access-Control-Allow-Origin:
|
36
|
+
- "*"
|
37
|
+
X-Trace-Id:
|
38
|
+
- cdde031b7a5e48d7a8c4a5a2f1b9dc6e
|
39
|
+
Strict-Transport-Security:
|
40
|
+
- max-age=63072000; includeSubDomains; preload
|
41
|
+
Server-Timing:
|
42
|
+
- l7_lb_tls;dur=100, l7_lb_idle;dur=2, l7_lb_receive;dur=0, l7_lb_total;dur=192
|
43
|
+
Access-Control-Expose-Headers:
|
44
|
+
- Server-Timing, X-Trace-ID
|
45
|
+
body:
|
46
|
+
encoding: ASCII-8BIT
|
47
|
+
string: '{"document_id":"9B7CB9418DCDEBF2C4C519F65A32B99F","document_key":"EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815"}'
|
48
|
+
recorded_at: Tue, 09 Jul 2024 02:02:17 GMT
|
49
|
+
- request:
|
50
|
+
method: post
|
51
|
+
uri: https://api.deepl.com/v2/document/9B7CB9418DCDEBF2C4C519F65A32B99F
|
52
|
+
body:
|
53
|
+
encoding: UTF-8
|
54
|
+
string: '{"document_key":"EA637EA43BB3F8A52A2A25B76EF3E0C72CE9CD00C881148D1236CB584CB34815","param":"fake"}'
|
55
|
+
headers:
|
56
|
+
Authorization:
|
57
|
+
- DeepL-Auth-Key VALID_TOKEN
|
58
|
+
User-Agent:
|
59
|
+
- deepl-ruby/2.5.3 (darwin23) ruby/3.3.3
|
60
|
+
Content-Type:
|
61
|
+
- application/json
|
62
|
+
Accept-Encoding:
|
63
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
64
|
+
Accept:
|
65
|
+
- "*/*"
|
66
|
+
Fake-Header:
|
67
|
+
- fake_value
|
68
|
+
response:
|
69
|
+
status:
|
70
|
+
code: 200
|
71
|
+
message: OK
|
72
|
+
headers:
|
73
|
+
Date:
|
74
|
+
- Tue, 09 Jul 2024 02:03:49 GMT
|
75
|
+
Content-Type:
|
76
|
+
- application/json; charset=utf-8
|
77
|
+
Transfer-Encoding:
|
78
|
+
- chunked
|
79
|
+
Vary:
|
80
|
+
- Accept-Encoding
|
81
|
+
Access-Control-Allow-Origin:
|
82
|
+
- "*"
|
83
|
+
X-Trace-Id:
|
84
|
+
- 73fc4be8f3964b4080f89ee686c090be
|
85
|
+
Strict-Transport-Security:
|
86
|
+
- max-age=63072000; includeSubDomains; preload
|
87
|
+
Server-Timing:
|
88
|
+
- l7_lb_tls;dur=152, l7_lb_idle;dur=9, l7_lb_receive;dur=0, l7_lb_total;dur=166
|
89
|
+
Access-Control-Expose-Headers:
|
90
|
+
- Server-Timing, X-Trace-ID
|
91
|
+
body:
|
92
|
+
encoding: ASCII-8BIT
|
93
|
+
string: '{"document_id":"9B7CB9418DCDEBF2C4C519F65A32B99F","status":"done","billed_characters":256}'
|
94
|
+
recorded_at: Tue, 09 Jul 2024 02:03:49 GMT
|
95
|
+
recorded_with: VCR 6.2.0
|