deepl-rb 2.3.1 → 2.5.1
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/.rubocop.yml +7 -4
- data/README.md +100 -1
- data/VERSION +1 -1
- data/deepl-rb.gemspec +25 -4
- data/lib/deepl/configuration.rb +2 -2
- data/lib/deepl/exceptions/not_found.rb +13 -0
- data/lib/deepl/exceptions/not_supported.rb +11 -0
- data/lib/deepl/glossary_api.rb +35 -0
- data/lib/deepl/requests/base.rb +21 -4
- data/lib/deepl/requests/glossary/create.rb +45 -0
- data/lib/deepl/requests/glossary/destroy.rb +30 -0
- data/lib/deepl/requests/glossary/entries.rb +30 -0
- data/lib/deepl/requests/glossary/find.rb +31 -0
- data/lib/deepl/requests/glossary/language_pairs.rb +31 -0
- data/lib/deepl/requests/glossary/list.rb +30 -0
- data/lib/deepl/requests/languages.rb +3 -1
- data/lib/deepl/requests/translate.rb +4 -2
- data/lib/deepl/resources/glossary.rb +25 -0
- data/lib/deepl/resources/language.rb +8 -1
- data/lib/deepl/resources/language_pair.rb +20 -0
- data/lib/deepl.rb +16 -0
- data/spec/api/configuration_spec.rb +1 -1
- data/spec/api/deepl_spec.rb +189 -0
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +374 -0
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +3 -1
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +212 -1
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +3 -1
- data/spec/fixtures/vcr_cassettes/glossaries.yml +480 -0
- data/spec/fixtures/vcr_cassettes/languages.yml +9 -3
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +101 -44
- data/spec/fixtures/vcr_cassettes/usage.yml +3 -1
- data/spec/requests/glossary/create_spec.rb +55 -0
- data/spec/requests/glossary/destroy_spec.rb +50 -0
- data/spec/requests/glossary/entries_spec.rb +48 -0
- data/spec/requests/glossary/find_spec.rb +54 -0
- data/spec/requests/glossary/language_pairs_spec.rb +30 -0
- data/spec/requests/glossary/list_spec.rb +44 -0
- data/spec/requests/translate_spec.rb +74 -2
- data/spec/resources/glossary_spec.rb +35 -0
- data/spec/resources/language_pair_spec.rb +20 -0
- data/spec/resources/language_spec.rb +23 -1
- data/spec/spec_helper.rb +3 -3
- metadata +24 -3
@@ -2,11 +2,13 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api-free.deepl.com/v2/languages
|
5
|
+
uri: https://api-free.deepl.com/v2/languages
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
|
+
Authorization:
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10
12
|
Accept-Encoding:
|
11
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
14
|
Accept:
|
@@ -36,11 +38,13 @@ http_interactions:
|
|
36
38
|
recorded_at: Mon, 17 May 2021 14:49:42 GMT
|
37
39
|
- request:
|
38
40
|
method: get
|
39
|
-
uri: https://api-free.deepl.com/v2/languages?
|
41
|
+
uri: https://api-free.deepl.com/v2/languages?type=target
|
40
42
|
body:
|
41
43
|
encoding: US-ASCII
|
42
44
|
string: ''
|
43
45
|
headers:
|
46
|
+
Authorization:
|
47
|
+
- DeepL-Auth-Key VALID_TOKEN
|
44
48
|
Accept-Encoding:
|
45
49
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
46
50
|
Accept:
|
@@ -74,11 +78,13 @@ http_interactions:
|
|
74
78
|
recorded_at: Mon, 17 May 2021 14:55:30 GMT
|
75
79
|
- request:
|
76
80
|
method: get
|
77
|
-
uri: https://api-free.deepl.com/v2/languages?
|
81
|
+
uri: https://api-free.deepl.com/v2/languages?type=invalid
|
78
82
|
body:
|
79
83
|
encoding: US-ASCII
|
80
84
|
string: ''
|
81
85
|
headers:
|
86
|
+
Authorization:
|
87
|
+
- DeepL-Auth-Key VALID_TOKEN
|
82
88
|
Accept-Encoding:
|
83
89
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
84
90
|
Accept:
|
@@ -2,11 +2,13 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://api-free.deepl.com/v2/translate
|
5
|
+
uri: https://api-free.deepl.com/v2/translate
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: text=Sample+text&source_lang=EN&target_lang=ES
|
9
9
|
headers:
|
10
|
+
Authorization:
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10
12
|
Accept-Encoding:
|
11
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
14
|
Accept:
|
@@ -39,11 +41,13 @@ http_interactions:
|
|
39
41
|
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
40
42
|
- request:
|
41
43
|
method: post
|
42
|
-
uri: https://api-free.deepl.com/v2/translate
|
44
|
+
uri: https://api-free.deepl.com/v2/translate
|
43
45
|
body:
|
44
46
|
encoding: US-ASCII
|
45
47
|
string: text=Sample&text=Word&source_lang=EN&target_lang=ES
|
46
48
|
headers:
|
49
|
+
Authorization:
|
50
|
+
- DeepL-Auth-Key VALID_TOKEN
|
47
51
|
Accept-Encoding:
|
48
52
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
49
53
|
Accept:
|
@@ -75,11 +79,13 @@ http_interactions:
|
|
75
79
|
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
76
80
|
- request:
|
77
81
|
method: post
|
78
|
-
uri: https://api-free.deepl.com/v2/translate?
|
82
|
+
uri: https://api-free.deepl.com/v2/translate?tag_handling=xml
|
79
83
|
body:
|
80
84
|
encoding: US-ASCII
|
81
85
|
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
82
86
|
headers:
|
87
|
+
Authorization:
|
88
|
+
- DeepL-Auth-Key VALID_TOKEN
|
83
89
|
Accept-Encoding:
|
84
90
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
85
91
|
Accept:
|
@@ -112,48 +118,13 @@ http_interactions:
|
|
112
118
|
recorded_at: Mon, 17 May 2021 14:20:15 GMT
|
113
119
|
- request:
|
114
120
|
method: post
|
115
|
-
uri: https://api-free.deepl.com/v2/translate
|
116
|
-
body:
|
117
|
-
encoding: US-ASCII
|
118
|
-
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
119
|
-
headers:
|
120
|
-
Accept-Encoding:
|
121
|
-
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
122
|
-
Accept:
|
123
|
-
- "*/*"
|
124
|
-
User-Agent:
|
125
|
-
- Ruby
|
126
|
-
Content-Type:
|
127
|
-
- application/x-www-form-urlencoded
|
128
|
-
response:
|
129
|
-
status:
|
130
|
-
code: 200
|
131
|
-
message: OK
|
132
|
-
headers:
|
133
|
-
Server:
|
134
|
-
- nginx
|
135
|
-
Date:
|
136
|
-
- Mon, 17 May 2021 14:20:16 GMT
|
137
|
-
Content-Type:
|
138
|
-
- application/json
|
139
|
-
Content-Length:
|
140
|
-
- '119'
|
141
|
-
Connection:
|
142
|
-
- keep-alive
|
143
|
-
Access-Control-Allow-Origin:
|
144
|
-
- "*"
|
145
|
-
body:
|
146
|
-
encoding: ASCII-8BIT
|
147
|
-
string: !binary |-
|
148
|
-
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5Ib2xhIGdyYW4gbXVuZG88L2NvZGU+IMKhQnVlbm9zIGTDrWFzISJ9XX0=
|
149
|
-
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
150
|
-
- request:
|
151
|
-
method: post
|
152
|
-
uri: https://api-free.deepl.com/v2/translate?auth_key=invalid
|
121
|
+
uri: https://api-free.deepl.com/v2/translate
|
153
122
|
body:
|
154
123
|
encoding: US-ASCII
|
155
124
|
string: text=Sample+text&source_lang=EN&target_lang=ES
|
156
125
|
headers:
|
126
|
+
Authorization:
|
127
|
+
- DeepL-Auth-Key invalid
|
157
128
|
Accept-Encoding:
|
158
129
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
159
130
|
Accept:
|
@@ -183,11 +154,13 @@ http_interactions:
|
|
183
154
|
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
184
155
|
- request:
|
185
156
|
method: post
|
186
|
-
uri: https://api-free.deepl.com/v2/translate
|
157
|
+
uri: https://api-free.deepl.com/v2/translate
|
187
158
|
body:
|
188
159
|
encoding: US-ASCII
|
189
160
|
string: source_lang=EN&target_lang=ES
|
190
161
|
headers:
|
162
|
+
Authorization:
|
163
|
+
- DeepL-Auth-Key VALID_TOKEN
|
191
164
|
Accept-Encoding:
|
192
165
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
193
166
|
Accept:
|
@@ -217,11 +190,13 @@ http_interactions:
|
|
217
190
|
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
218
191
|
- request:
|
219
192
|
method: post
|
220
|
-
uri: https://api-free.deepl.com/v2/translate
|
193
|
+
uri: https://api-free.deepl.com/v2/translate
|
221
194
|
body:
|
222
195
|
encoding: US-ASCII
|
223
196
|
string: text=Sample+text&source_lang=EN
|
224
197
|
headers:
|
198
|
+
Authorization:
|
199
|
+
- DeepL-Auth-Key VALID_TOKEN
|
225
200
|
Accept-Encoding:
|
226
201
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
227
202
|
Accept:
|
@@ -322,4 +297,86 @@ http_interactions:
|
|
322
297
|
encoding: UTF-8
|
323
298
|
string: '{"message":"Value for ''termbaseId'' not supported."}'
|
324
299
|
recorded_at: Tue, 28 Sep 2021 17:20:52 GMT
|
325
|
-
|
300
|
+
- request:
|
301
|
+
method: post
|
302
|
+
uri: https://api-free.deepl.com/v2/translate?ignore_tags=code,span&tag_handling=xml
|
303
|
+
body:
|
304
|
+
encoding: US-ASCII
|
305
|
+
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
306
|
+
headers:
|
307
|
+
Authorization:
|
308
|
+
- DeepL-Auth-Key VALID_TOKEN
|
309
|
+
Accept-Encoding:
|
310
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
311
|
+
Accept:
|
312
|
+
- "*/*"
|
313
|
+
User-Agent:
|
314
|
+
- Ruby
|
315
|
+
Content-Type:
|
316
|
+
- application/x-www-form-urlencoded
|
317
|
+
response:
|
318
|
+
status:
|
319
|
+
code: 200
|
320
|
+
message: OK
|
321
|
+
headers:
|
322
|
+
Server:
|
323
|
+
- nginx
|
324
|
+
Date:
|
325
|
+
- Thu, 17 Mar 2022 09:55:34 GMT
|
326
|
+
Content-Type:
|
327
|
+
- application/json
|
328
|
+
Transfer-Encoding:
|
329
|
+
- chunked
|
330
|
+
Connection:
|
331
|
+
- keep-alive
|
332
|
+
Vary:
|
333
|
+
- Accept-Encoding
|
334
|
+
Access-Control-Allow-Origin:
|
335
|
+
- "*"
|
336
|
+
body:
|
337
|
+
encoding: ASCII-8BIT
|
338
|
+
string: !binary |-
|
339
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
|
340
|
+
recorded_at: Thu, 17 Mar 2022 09:55:32 GMT
|
341
|
+
- request:
|
342
|
+
method: post
|
343
|
+
uri: https://api-free.deepl.com/v2/translate?outline_detection=0&split_sentences=nonewlines&splitting_tags=title,par&tag_handling=xml
|
344
|
+
body:
|
345
|
+
encoding: US-ASCII
|
346
|
+
string: text=%3Cdocument%3E%0A++%3Cmeta%3E%0A++++%3Ctitle%3EA+document%27s+title%3C%2Ftitle%3E%0A++%3C%2Fmeta%3E%0A++%3Ccontent%3E%0A++++%3Cpar%3EThis+is+the+first+sentence.+Followed+by+a+second+one.%3C%2Fpar%3E%0A++++%3Cpar%3EThis+is+the+third+sentence.%3C%2Fpar%3E%0A++%3C%2Fcontent%3E%0A%3C%2Fdocument%3E%0A&source_lang=EN&target_lang=ES
|
347
|
+
headers:
|
348
|
+
Authorization:
|
349
|
+
- DeepL-Auth-Key VALID_TOKEN
|
350
|
+
Accept-Encoding:
|
351
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
352
|
+
Accept:
|
353
|
+
- "*/*"
|
354
|
+
User-Agent:
|
355
|
+
- Ruby
|
356
|
+
Content-Type:
|
357
|
+
- application/x-www-form-urlencoded
|
358
|
+
response:
|
359
|
+
status:
|
360
|
+
code: 200
|
361
|
+
message: OK
|
362
|
+
headers:
|
363
|
+
Server:
|
364
|
+
- nginx
|
365
|
+
Date:
|
366
|
+
- Wed, 22 Jun 2022 18:04:58 GMT
|
367
|
+
Content-Type:
|
368
|
+
- application/json
|
369
|
+
Transfer-Encoding:
|
370
|
+
- chunked
|
371
|
+
Connection:
|
372
|
+
- keep-alive
|
373
|
+
Vary:
|
374
|
+
- Accept-Encoding
|
375
|
+
Access-Control-Allow-Origin:
|
376
|
+
- "*"
|
377
|
+
body:
|
378
|
+
encoding: ASCII-8BIT
|
379
|
+
string: !binary |-
|
380
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6Ijxkb2N1bWVudD5cbiAgPG1ldGE+XG4gICAgPHRpdGxlPkVsIHTDrXR1bG8gZGUgdW4gZG9jdW1lbnRvPC90aXRsZT5cbiAgPC9tZXRhPlxuICA8Y29udGVudD5cbiAgICA8cGFyPkVzIGxhIHByaW1lcmEgZnJhc2UuIFNlZ3VpZG8gZGUgdW5hIHNlZ3VuZGEuPC9wYXI+XG4gICAgPHBhcj5Fc3RhIGVzIGxhIHRlcmNlcmEgZnJhc2UuPC9wYXI+XG4gIDwvY29udGVudD5cbjwvZG9jdW1lbnQ+XG4ifV19
|
381
|
+
recorded_at: Wed, 22 Jun 2022 18:04:56 GMT
|
382
|
+
recorded_with: VCR 6.1.0
|
@@ -2,11 +2,13 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api-free.deepl.com/v2/usage
|
5
|
+
uri: https://api-free.deepl.com/v2/usage
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
|
+
Authorization:
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
10
12
|
Accept-Encoding:
|
11
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
14
|
Accept:
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::Create do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:name) { 'Mi Glosario' }
|
8
|
+
let(:source_lang) { 'EN' }
|
9
|
+
let(:target_lang) { 'ES' }
|
10
|
+
let(:entries) do
|
11
|
+
[
|
12
|
+
%w[Hello Hola],
|
13
|
+
%w[World Mundo]
|
14
|
+
]
|
15
|
+
end
|
16
|
+
let(:entries_format) { 'tsv' }
|
17
|
+
let(:options) { {} }
|
18
|
+
subject do
|
19
|
+
DeepL::Requests::Glossary::Create.new(api, name, source_lang, target_lang, entries, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#initialize' do
|
23
|
+
context 'When building a request' do
|
24
|
+
it 'should create a request object' do
|
25
|
+
expect(subject).to be_a(described_class)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set the default value for the entries format if not specified' do
|
29
|
+
request = DeepL::Requests::Glossary::Create.new(api, name, source_lang, target_lang,
|
30
|
+
entries, options)
|
31
|
+
expect(request.entries_format).to eq('tsv')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#request' do
|
37
|
+
around do |example|
|
38
|
+
VCR.use_cassette('glossaries') { example.call }
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'When performing a valid request with two glossary entries' do
|
42
|
+
it 'should return a glossaries object' do
|
43
|
+
glossary = subject.request
|
44
|
+
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
45
|
+
expect(glossary.id).to be_kind_of(String)
|
46
|
+
expect(glossary.name).to eq('Mi Glosario')
|
47
|
+
expect(glossary.ready).to be(true).or be(false)
|
48
|
+
expect(glossary.source_lang).to eq('en')
|
49
|
+
expect(glossary.target_lang).to eq('es')
|
50
|
+
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
51
|
+
expect(glossary.entry_count).to eq(2)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::Destroy do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:id) { '367eef44-b533-4d95-be19-74950c7760e9' }
|
8
|
+
subject { DeepL::Requests::Glossary::Destroy.new(api, id) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
context 'When building a request' do
|
12
|
+
it 'should create a request object' do
|
13
|
+
expect(subject).to be_a(described_class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#request' do
|
19
|
+
around do |example|
|
20
|
+
VCR.use_cassette('glossaries') { example.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When performing a valid request' do
|
24
|
+
let(:new_glossary) do
|
25
|
+
DeepL::Requests::Glossary::Create.new(api, 'fixture', 'EN', 'ES', [%w[Hello Hola]]).request
|
26
|
+
end
|
27
|
+
subject { DeepL::Requests::Glossary::Destroy.new(api, new_glossary.id) }
|
28
|
+
it 'should return an empty object' do
|
29
|
+
response = subject.request
|
30
|
+
expect(response).to eq(new_glossary.id)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'When deleting a non existing glossary with a valid id' do
|
35
|
+
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
36
|
+
subject { DeepL::Requests::Glossary::Destroy.new(api, id) }
|
37
|
+
it 'should raise a not found error' do
|
38
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::NotFound)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'When deleting a non existing glossary with an invalid id' do
|
43
|
+
let(:id) { 'invalid-uuid' }
|
44
|
+
subject { DeepL::Requests::Glossary::Destroy.new(api, id) }
|
45
|
+
it 'should raise a bad request error' do
|
46
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::Entries do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:id) { '012a5576-b551-4d4c-b917-ce01bc8debb6' }
|
8
|
+
subject { DeepL::Requests::Glossary::Entries.new(api, id) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
context 'When building a request' do
|
12
|
+
it 'should create a request object' do
|
13
|
+
expect(subject).to be_a(described_class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#request' do
|
19
|
+
around do |example|
|
20
|
+
VCR.use_cassette('glossaries') { example.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When performing a valid request' do
|
24
|
+
it 'should return a list of entries in TSV format' do
|
25
|
+
entries = subject.request
|
26
|
+
expect(entries).to be_kind_of(Array)
|
27
|
+
expect(entries).to all(be_a(Array))
|
28
|
+
expect(entries.size).to eq(2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'When requesting entries with a valid but non existing glossary id' do
|
33
|
+
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
34
|
+
subject { DeepL::Requests::Glossary::Entries.new(api, id) }
|
35
|
+
it 'should raise a not found error' do
|
36
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::NotFound)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'When requesting entries with an invalid glossary id' do
|
41
|
+
let(:id) { 'invalid-uuid' }
|
42
|
+
subject { DeepL::Requests::Glossary::Entries.new(api, id) }
|
43
|
+
it 'should raise a bad request error' do
|
44
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::Find do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:id) { 'd9ad833f-c818-430c-a3c9-47071384fa3e' }
|
8
|
+
let(:options) { {} }
|
9
|
+
subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
context 'When building a request' do
|
13
|
+
it 'should create a request object' do
|
14
|
+
expect(subject).to be_a(described_class)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#request' do
|
20
|
+
around do |example|
|
21
|
+
VCR.use_cassette('glossaries') { example.call }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'When performing a valid request' do
|
25
|
+
it 'should return a glossary object' do
|
26
|
+
glossary = subject.request
|
27
|
+
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
28
|
+
expect(glossary.id).to eq('d9ad833f-c818-430c-a3c9-47071384fa3e')
|
29
|
+
expect(glossary.name).to eq('Mi Glosario')
|
30
|
+
expect(glossary.ready).to be(true).or be(false)
|
31
|
+
expect(glossary.source_lang).to eq('en')
|
32
|
+
expect(glossary.target_lang).to eq('es')
|
33
|
+
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
34
|
+
expect(glossary.entry_count).to eq(2)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'When requesting a non existing glossary with a valid id' do
|
39
|
+
let(:id) { 'a0af40e1-d81b-4aab-a95c-7cafbcfd1eb1' }
|
40
|
+
subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
|
41
|
+
it 'should raise a not found error' do
|
42
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::NotFound)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'When requesting a non existing glossary with an invalid id' do
|
47
|
+
let(:id) { 'invalid-uuid' }
|
48
|
+
subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
|
49
|
+
it 'should raise a bad request error' do
|
50
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::LanguagePairs do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:options) { {} }
|
8
|
+
subject { DeepL::Requests::Glossary::LanguagePairs.new(api, options) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
context 'When building a request' do
|
12
|
+
it 'should create a request object' do
|
13
|
+
expect(subject).to be_a(described_class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#request' do
|
19
|
+
around do |example|
|
20
|
+
VCR.use_cassette('glossaries') { example.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When requesting a list of all language pairs supported by glossaries' do
|
24
|
+
it 'should return a language pairs object' do
|
25
|
+
language_pairs = subject.request
|
26
|
+
expect(language_pairs).to be_an(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Glossary::List do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:options) { {} }
|
8
|
+
subject { DeepL::Requests::Glossary::List.new(api, options) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
context 'When building a request' do
|
12
|
+
it 'should create a request object' do
|
13
|
+
expect(subject).to be_a(described_class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#request' do
|
19
|
+
around do |example|
|
20
|
+
VCR.use_cassette('glossaries') { example.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When requesting a list of all glossaries' do
|
24
|
+
it 'should return a glossaries object' do
|
25
|
+
glossaries = subject.request
|
26
|
+
expect(glossaries).to be_an(Array)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'When performing a bad request' do
|
31
|
+
context 'When using an invalid token' do
|
32
|
+
let(:api) do
|
33
|
+
api = build_deepl_api
|
34
|
+
api.configuration.auth_key = 'invalid'
|
35
|
+
api
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should raise an unauthorized error' do
|
39
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DeepL::Requests::Translate do
|
6
|
-
let(:tags_str) { 'p,
|
6
|
+
let(:tags_str) { 'p,strong,span' }
|
7
7
|
let(:tags_array) { %w[p strong span] }
|
8
8
|
|
9
9
|
let(:api) { build_deepl_api }
|
@@ -11,6 +11,7 @@ describe DeepL::Requests::Translate do
|
|
11
11
|
let(:source_lang) { 'EN' }
|
12
12
|
let(:target_lang) { 'ES' }
|
13
13
|
let(:options) { {} }
|
14
|
+
|
14
15
|
subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
|
15
16
|
|
16
17
|
describe '#initialize' do
|
@@ -20,6 +21,33 @@ describe DeepL::Requests::Translate do
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
context 'when using `splitting_tags` options' do
|
25
|
+
it 'should work with a nil values' do
|
26
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: nil)
|
27
|
+
expect(request.options[:splitting_tags]).to eq(nil)
|
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('')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should work with a comma-separated list' do
|
36
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
|
37
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should convert arrays to strings' do
|
41
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_array)
|
42
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should leave strings as they are' do
|
46
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
|
47
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
23
51
|
context 'when using `non_splitting_tags` options' do
|
24
52
|
it 'should work with a nil values' do
|
25
53
|
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: nil)
|
@@ -215,7 +243,7 @@ describe DeepL::Requests::Translate do
|
|
215
243
|
|
216
244
|
context 'When performing a valid request and passing a variable' do
|
217
245
|
let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
|
218
|
-
let(:options) { { tag_handling: 'xml', ignore_tags:
|
246
|
+
let(:options) { { tag_handling: 'xml', ignore_tags: %w[code span] } }
|
219
247
|
|
220
248
|
it 'should return a text object' do
|
221
249
|
text = subject.request
|
@@ -226,6 +254,50 @@ describe DeepL::Requests::Translate do
|
|
226
254
|
end
|
227
255
|
end
|
228
256
|
|
257
|
+
context 'When performing a valid request with an HTML document' do
|
258
|
+
let(:text) do
|
259
|
+
<<~XML
|
260
|
+
<document>
|
261
|
+
<meta>
|
262
|
+
<title>A document's title</title>
|
263
|
+
</meta>
|
264
|
+
<content>
|
265
|
+
<par>This is the first sentence. Followed by a second one.</par>
|
266
|
+
<par>This is the third sentence.</par>
|
267
|
+
</content>
|
268
|
+
</document>
|
269
|
+
XML
|
270
|
+
end
|
271
|
+
let(:options) do
|
272
|
+
{
|
273
|
+
tag_handling: 'xml',
|
274
|
+
split_sentences: 'nonewlines',
|
275
|
+
outline_detection: false,
|
276
|
+
splitting_tags: %w[title par]
|
277
|
+
}
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should return a text object' do
|
281
|
+
text = subject.request
|
282
|
+
|
283
|
+
expect(text).to be_a(DeepL::Resources::Text)
|
284
|
+
expect(text.text).to eq(
|
285
|
+
<<~XML
|
286
|
+
<document>
|
287
|
+
<meta>
|
288
|
+
<title>El título de un documento</title>
|
289
|
+
</meta>
|
290
|
+
<content>
|
291
|
+
<par>Es la primera frase. Seguido de una segunda.</par>
|
292
|
+
<par>Esta es la tercera frase.</par>
|
293
|
+
</content>
|
294
|
+
</document>
|
295
|
+
XML
|
296
|
+
)
|
297
|
+
expect(text.detected_source_language).to eq('EN')
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
229
301
|
context 'When performing a bad request' do
|
230
302
|
context 'When using an invalid token' do
|
231
303
|
let(:api) do
|