deepl-rb 3.6.1 → 3.8.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/.gitlab-ci.yml +8 -1
- data/CHANGELOG.md +35 -1
- data/Gemfile +0 -2
- data/README.md +165 -34
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +52 -20
- data/lib/deepl/requests/base.rb +16 -0
- data/lib/deepl/requests/document/upload.rb +6 -5
- data/lib/deepl/requests/rephrase.rb +3 -2
- data/lib/deepl/requests/style_rule/create.rb +46 -0
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +45 -0
- data/lib/deepl/requests/style_rule/destroy.rb +39 -0
- data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +40 -0
- data/lib/deepl/requests/style_rule/find.rb +40 -0
- data/lib/deepl/requests/style_rule/find_custom_instruction.rb +41 -0
- data/lib/deepl/requests/style_rule/update.rb +42 -0
- data/lib/deepl/requests/style_rule/update_configured_rules.rb +41 -0
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +47 -0
- data/lib/deepl/requests/translate.rb +17 -4
- data/lib/deepl/requests/translation_memory/list.rb +58 -0
- data/lib/deepl/resources/style_rule.rb +2 -1
- data/lib/deepl/resources/translation_memory.rb +25 -0
- data/lib/deepl/style_rule_api.rb +44 -0
- data/lib/deepl/translation_memory_api.rb +17 -0
- data/lib/deepl.rb +75 -55
- data/lib/version.rb +1 -1
- data/spec/api/deepl_spec.rb +134 -332
- data/spec/integration_tests/document_api_spec.rb +4 -18
- data/spec/integration_tests/document_error_paths_spec.rb +33 -0
- data/spec/integration_tests/glossary_api_spec.rb +114 -0
- data/spec/integration_tests/glossary_error_paths_spec.rb +107 -0
- data/spec/integration_tests/languages_api_spec.rb +54 -0
- data/spec/integration_tests/languages_error_paths_spec.rb +25 -0
- data/spec/integration_tests/rephrase_api_spec.rb +90 -0
- data/spec/integration_tests/rephrase_error_paths_spec.rb +53 -0
- data/spec/integration_tests/smoke_test_spec.rb +24 -0
- data/spec/integration_tests/style_rule_api_spec.rb +55 -17
- data/spec/integration_tests/style_rule_error_paths_spec.rb +45 -0
- data/spec/integration_tests/translate_api_spec.rb +98 -0
- data/spec/integration_tests/translate_error_paths_spec.rb +48 -0
- data/spec/integration_tests/translation_memory_api_spec.rb +54 -0
- data/spec/integration_tests/translation_memory_error_paths_spec.rb +19 -0
- data/spec/integration_tests/usage_api_spec.rb +29 -0
- data/spec/integration_tests/usage_error_paths_spec.rb +18 -0
- data/spec/requests/glossary/create_spec.rb +0 -21
- data/spec/requests/glossary/destroy_spec.rb +0 -39
- data/spec/requests/glossary/entries_spec.rb +0 -35
- data/spec/requests/glossary/find_spec.rb +0 -40
- data/spec/requests/glossary/language_pairs_spec.rb +0 -13
- data/spec/requests/glossary/list_spec.rb +0 -27
- data/spec/requests/languages_spec.rb +0 -41
- data/spec/requests/rephrase_spec.rb +13 -139
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +30 -0
- data/spec/requests/style_rule/create_spec.rb +29 -0
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +28 -0
- data/spec/requests/style_rule/destroy_spec.rb +27 -0
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +29 -0
- data/spec/requests/style_rule/find_spec.rb +28 -0
- data/spec/requests/style_rule/list_spec.rb +27 -0
- data/spec/requests/style_rule/update_configured_rules_spec.rb +31 -0
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +32 -0
- data/spec/requests/style_rule/update_spec.rb +29 -0
- data/spec/requests/translate_spec.rb +8 -218
- data/spec/requests/translation_memory/list_spec.rb +27 -0
- data/spec/requests/usage_spec.rb +0 -16
- data/spec/resources/custom_instruction_spec.rb +32 -0
- data/spec/resources/style_rule_spec.rb +68 -0
- data/spec/resources/translation_memory_spec.rb +35 -0
- data/spec/spec_helper.rb +15 -45
- data/spec/support/live_mock_server.rb +12 -0
- data/spec/support/managed_glossary.rb +17 -0
- data/spec/support/managed_style_rule.rb +17 -0
- data/spec/support/managed_translation_memory.rb +7 -0
- metadata +48 -19
- data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
- data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
- data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
- data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
- data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
- data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
- data/spec/fixtures/vcr_cassettes/style_rules.yml +0 -92
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10630
- data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.translate' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
let(:text) { 'proton beam' }
|
|
12
|
+
|
|
13
|
+
describe 'happy path' do
|
|
14
|
+
it 'translates a single string into a Text resource' do
|
|
15
|
+
result = DeepL.translate(text, 'EN', 'DE')
|
|
16
|
+
|
|
17
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
18
|
+
expect(result.text).to be_a(String)
|
|
19
|
+
expect(result.text).not_to be_empty
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'translates an array of strings into an array of Text resources' do
|
|
23
|
+
results = DeepL.translate(%w[Sample Word], 'EN', 'ES')
|
|
24
|
+
|
|
25
|
+
expect(results).to be_an(Array)
|
|
26
|
+
expect(results.size).to eq(2)
|
|
27
|
+
expect(results).to all(be_a(DeepL::Resources::Text))
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'options' do
|
|
32
|
+
it 'accepts a formality setting' do
|
|
33
|
+
result = DeepL.translate('How are you?', 'EN', 'DE', { formality: 'more' })
|
|
34
|
+
|
|
35
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'translates with XML tag handling and ignored tags' do
|
|
39
|
+
result = DeepL.translate('<p>Sample <code>x</code></p>', 'EN', 'ES',
|
|
40
|
+
{ tag_handling: 'xml', ignore_tags: %w[code] })
|
|
41
|
+
|
|
42
|
+
expect(result.text).to be_a(String)
|
|
43
|
+
expect(result.text).not_to be_empty
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'accepts a context option' do
|
|
47
|
+
result = DeepL.translate('That is hot!', 'EN', 'ES', { context: 'about the weather' })
|
|
48
|
+
|
|
49
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'accepts an empty context option' do
|
|
53
|
+
result = DeepL.translate('That is hot!', 'EN', 'ES', { context: '' })
|
|
54
|
+
|
|
55
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'translates an HTML document with split_sentences, outline_detection and splitting_tags' do
|
|
59
|
+
document = '<document><meta><title>Title</title></meta>' \
|
|
60
|
+
'<content><par>First sentence. Second one.</par></content></document>'
|
|
61
|
+
result = DeepL.translate(document, 'EN', 'ES',
|
|
62
|
+
{ tag_handling: 'xml', split_sentences: 'nonewlines',
|
|
63
|
+
outline_detection: false, splitting_tags: %w[title par] })
|
|
64
|
+
|
|
65
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
66
|
+
expect(result.text).not_to be_empty
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'translates using a glossary' do
|
|
70
|
+
with_managed_glossary(name: 'Translate Glossary', source_lang: 'en', target_lang: 'de',
|
|
71
|
+
entries: [%w[Hello Hallo]]) do |glossary|
|
|
72
|
+
result = DeepL.translate('Hello', 'EN', 'DE', { glossary_id: glossary.id })
|
|
73
|
+
|
|
74
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
75
|
+
expect(result.text).not_to be_empty
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
%w[quality_optimized latency_optimized prefer_quality_optimized].each do |model_type|
|
|
80
|
+
it "returns model_type_used for #{model_type}" do
|
|
81
|
+
result = DeepL.translate(text, 'EN', 'DE', { model_type: model_type })
|
|
82
|
+
|
|
83
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
84
|
+
expect(result.model_type_used).not_to be_nil
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
%w[v1 v2].each do |version|
|
|
89
|
+
it "translates with tag_handling_version #{version}" do
|
|
90
|
+
result = DeepL.translate('<p>Hello world</p>', 'EN', 'DE',
|
|
91
|
+
{ tag_handling: 'html', tag_handling_version: version })
|
|
92
|
+
|
|
93
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
94
|
+
expect(result.text).not_to be_empty
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.translate error paths' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
let(:text) { 'proton beam' }
|
|
12
|
+
|
|
13
|
+
describe 'authorization failures' do
|
|
14
|
+
it 'raises AuthorizationFailed when the auth key is invalid' do
|
|
15
|
+
request = DeepL::Requests::Translate.new(unauthorized_api, text, 'EN', 'DE')
|
|
16
|
+
|
|
17
|
+
expect { request.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'bad request errors' do
|
|
22
|
+
it 'raises BadRequest for an unsupported target language' do
|
|
23
|
+
expect { DeepL.translate(text, 'EN', 'ZZ') }
|
|
24
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'raises BadRequest when no target language is given' do
|
|
28
|
+
expect { DeepL.translate(text, 'EN', nil) }
|
|
29
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Real-server only: the mock coerces text:[null] to text:[""] and accepts it,
|
|
33
|
+
# so it cannot reproduce this; prod rejects [null] with 400.
|
|
34
|
+
it 'raises BadRequest when the text is nil', :real_server_only do
|
|
35
|
+
expect { DeepL.translate(nil, 'EN', 'DE') }
|
|
36
|
+
.to raise_error(DeepL::Exceptions::BadRequest)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'request entity too large errors' do
|
|
41
|
+
it 'raises RequestEntityTooLarge when too many texts are sent in a single request' do
|
|
42
|
+
texts = Array.new(10_000) { |i| "This is the sentence number #{i}" }
|
|
43
|
+
|
|
44
|
+
expect { DeepL.translate(texts, 'EN', 'DE') }
|
|
45
|
+
.to raise_error(DeepL::Exceptions::RequestEntityTooLarge)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::TranslationMemoryApi, :mock_server_only do
|
|
9
|
+
describe '#translate_with_translation_memory' do
|
|
10
|
+
it 'when performing a request with translation_memory_id' do
|
|
11
|
+
source_lang = 'DE'
|
|
12
|
+
target_lang = 'EN'
|
|
13
|
+
text = 'Protonenstrahl'
|
|
14
|
+
translation_memory_id = 'a74d88fb-ed2a-4943-a664-a4512398b994'
|
|
15
|
+
|
|
16
|
+
result = DeepL.translate(text, source_lang, target_lang,
|
|
17
|
+
{ translation_memory: translation_memory_id })
|
|
18
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'when performing a request with translation_memory resource object' do
|
|
22
|
+
source_lang = 'DE'
|
|
23
|
+
target_lang = 'EN'
|
|
24
|
+
text = 'Protonenstrahl'
|
|
25
|
+
translation_memory = build_test_translation_memory
|
|
26
|
+
|
|
27
|
+
result = DeepL.translate(text, source_lang, target_lang,
|
|
28
|
+
{ translation_memory: translation_memory })
|
|
29
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe '#list_translation_memories' do
|
|
34
|
+
it 'when requesting a list of all translation memories' do
|
|
35
|
+
translation_memories = DeepL.translation_memories.list
|
|
36
|
+
expect(translation_memories).to be_an(Array)
|
|
37
|
+
expect(translation_memories).not_to be_empty
|
|
38
|
+
expect(translation_memories.first).to be_a(DeepL::Resources::TranslationMemory)
|
|
39
|
+
expect(translation_memories.first.translation_memory_id).not_to be_nil
|
|
40
|
+
expect(translation_memories.first.name).not_to be_nil
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def build_test_translation_memory
|
|
45
|
+
tm_data = {
|
|
46
|
+
'translation_memory_id' => 'a74d88fb-ed2a-4943-a664-a4512398b994',
|
|
47
|
+
'name' => 'Default Translation Memory',
|
|
48
|
+
'source_language' => 'DE',
|
|
49
|
+
'target_languages' => %w[EN ES FR],
|
|
50
|
+
'segment_count' => 3542
|
|
51
|
+
}
|
|
52
|
+
DeepL::Resources::TranslationMemory.new(tm_data, nil, nil)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::TranslationMemoryApi, :mock_server_only do # rubocop:disable RSpec/SpecFilePathFormat
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
describe 'authorization failures' do
|
|
12
|
+
let(:unauthorized_translation_memories) { described_class.new(unauthorized_api) }
|
|
13
|
+
|
|
14
|
+
it 'raises AuthorizationFailed when listing with an invalid auth key' do
|
|
15
|
+
expect { unauthorized_translation_memories.list }
|
|
16
|
+
.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.usage' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
describe 'happy path' do
|
|
10
|
+
it 'returns a Usage resource with integer counters where count does not exceed limit' do
|
|
11
|
+
usage = DeepL.usage
|
|
12
|
+
|
|
13
|
+
expect(usage).to be_a(DeepL::Resources::Usage)
|
|
14
|
+
expect(usage).to respond_to(:character_count, :character_limit)
|
|
15
|
+
expect(usage.character_count).to be_an(Integer)
|
|
16
|
+
expect(usage.character_limit).to be_an(Integer)
|
|
17
|
+
expect(usage.character_count).to be <= usage.character_limit
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe 'resource shape' do
|
|
22
|
+
it 'exposes quota_exceeded? consistent with character_count vs character_limit' do
|
|
23
|
+
usage = DeepL.usage
|
|
24
|
+
|
|
25
|
+
expect(usage).to respond_to(:quota_exceeded?)
|
|
26
|
+
expect(usage.quota_exceeded?).to eq(usage.character_count >= usage.character_limit)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
+
# Use of this source code is governed by an MIT
|
|
3
|
+
# license that can be found in the LICENSE file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe 'DeepL.usage error paths' do # rubocop:disable RSpec/DescribeClass
|
|
9
|
+
include_context 'with a live mock server'
|
|
10
|
+
|
|
11
|
+
describe 'authorization failures' do
|
|
12
|
+
it 'raises AuthorizationFailed when the auth key is invalid' do
|
|
13
|
+
request = DeepL::Requests::Usage.new(unauthorized_api)
|
|
14
|
+
|
|
15
|
+
expect { request.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -26,7 +26,6 @@ describe DeepL::Requests::Glossary::Create do
|
|
|
26
26
|
%w[World Mundo]
|
|
27
27
|
]
|
|
28
28
|
end
|
|
29
|
-
let(:entries_format) { 'tsv' }
|
|
30
29
|
let(:options) { {} }
|
|
31
30
|
|
|
32
31
|
describe '#initialize' do
|
|
@@ -42,24 +41,4 @@ describe DeepL::Requests::Glossary::Create do
|
|
|
42
41
|
end
|
|
43
42
|
end
|
|
44
43
|
end
|
|
45
|
-
|
|
46
|
-
describe '#request' do
|
|
47
|
-
around do |example|
|
|
48
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'when performing a valid request with two glossary entries' do
|
|
52
|
-
it 'returns a glossaries object' do
|
|
53
|
-
glossary = create.request
|
|
54
|
-
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
|
55
|
-
expect(glossary.id).to be_a(String)
|
|
56
|
-
expect(glossary.name).to eq('Mi Glosario')
|
|
57
|
-
expect(glossary.ready).to be(true).or be(false)
|
|
58
|
-
expect(glossary.source_lang).to eq('en')
|
|
59
|
-
expect(glossary.target_lang).to eq('es')
|
|
60
|
-
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
|
61
|
-
expect(glossary.entry_count).to eq(2)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
44
|
end
|
|
@@ -24,43 +24,4 @@ describe DeepL::Requests::Glossary::Destroy do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when performing a valid request' do
|
|
34
|
-
subject(:destroy) { described_class.new(api, new_glossary.id) }
|
|
35
|
-
|
|
36
|
-
let(:new_glossary) do
|
|
37
|
-
DeepL::Requests::Glossary::Create.new(api, 'fixture', 'EN', 'ES', [%w[Hello Hola]]).request
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
it 'returns an empty object' do
|
|
41
|
-
response = destroy.request
|
|
42
|
-
expect(response).to eq(new_glossary.id)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
context 'when deleting a non existing glossary with a valid id' do
|
|
47
|
-
subject(:destroy) { described_class.new(api, id) }
|
|
48
|
-
|
|
49
|
-
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
|
50
|
-
|
|
51
|
-
it 'raises a not found error' do
|
|
52
|
-
expect { destroy.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context 'when deleting a non existing glossary with an invalid id' do
|
|
57
|
-
subject(:destroy) { described_class.new(api, id) }
|
|
58
|
-
|
|
59
|
-
let(:id) { 'invalid-uuid' }
|
|
60
|
-
|
|
61
|
-
it 'raises a bad request error' do
|
|
62
|
-
expect { destroy.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
27
|
end
|
|
@@ -24,39 +24,4 @@ describe DeepL::Requests::Glossary::Entries do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when performing a valid request' do
|
|
34
|
-
it 'returns a list of entries in TSV format' do
|
|
35
|
-
entries = entries_obj.request
|
|
36
|
-
expect(entries).to be_a(Array)
|
|
37
|
-
expect(entries).to all(be_a(Array))
|
|
38
|
-
expect(entries.size).to eq(2)
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
context 'when requesting entries with a valid but non existing glossary id' do
|
|
43
|
-
subject(:entries_obj) { described_class.new(api, id) }
|
|
44
|
-
|
|
45
|
-
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
|
46
|
-
|
|
47
|
-
it 'raises a not found error' do
|
|
48
|
-
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
context 'when requesting entries with an invalid glossary id' do
|
|
53
|
-
subject(:entries_obj) { described_class.new(api, id) }
|
|
54
|
-
|
|
55
|
-
let(:id) { 'invalid-uuid' }
|
|
56
|
-
|
|
57
|
-
it 'raises a bad request error' do
|
|
58
|
-
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
27
|
end
|
|
@@ -25,44 +25,4 @@ describe DeepL::Requests::Glossary::Find do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
|
-
|
|
29
|
-
describe '#request' do
|
|
30
|
-
around do |example|
|
|
31
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
context 'when performing a valid request' do
|
|
35
|
-
it 'returns a glossary object' do
|
|
36
|
-
glossary = glossary_find.request
|
|
37
|
-
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
|
38
|
-
expect(glossary.id).to eq('9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb')
|
|
39
|
-
expect(glossary.name).to eq('Mi Glosario')
|
|
40
|
-
expect(glossary.ready).to be(true).or be(false)
|
|
41
|
-
expect(glossary.source_lang).to eq('en')
|
|
42
|
-
expect(glossary.target_lang).to eq('es')
|
|
43
|
-
expect { Time.iso8601(glossary.creation_time) }.not_to raise_error
|
|
44
|
-
expect(glossary.entry_count).to eq(2)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
context 'when requesting a non existing glossary with a valid id' do
|
|
49
|
-
subject(:glossary_find) { described_class.new(api, id, options) }
|
|
50
|
-
|
|
51
|
-
let(:id) { 'a0af40e1-d81b-4aab-a95c-7cafbcfd1eb1' }
|
|
52
|
-
|
|
53
|
-
it 'raises a not found error' do
|
|
54
|
-
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::NotFound)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
context 'when requesting a non existing glossary with an invalid id' do
|
|
59
|
-
subject(:glossary_find) { described_class.new(api, id, options) }
|
|
60
|
-
|
|
61
|
-
let(:id) { 'invalid-uuid' }
|
|
62
|
-
|
|
63
|
-
it 'raises a bad request error' do
|
|
64
|
-
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
28
|
end
|
|
@@ -24,17 +24,4 @@ describe DeepL::Requests::Glossary::LanguagePairs do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting a list of all language pairs supported by glossaries' do
|
|
34
|
-
it 'returns a language pairs object' do
|
|
35
|
-
language_pairs = language_pairs_obj.request
|
|
36
|
-
expect(language_pairs).to be_an(Array)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
27
|
end
|
|
@@ -24,31 +24,4 @@ describe DeepL::Requests::Glossary::List do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('glossaries') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting a list of all glossaries' do
|
|
34
|
-
it 'returns a glossaries object' do
|
|
35
|
-
glossaries = glossary_list.request
|
|
36
|
-
expect(glossaries).to be_an(Array)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context 'when performing a bad request' do
|
|
41
|
-
context 'when using an invalid token' do
|
|
42
|
-
let(:api) do
|
|
43
|
-
api = build_deepl_api
|
|
44
|
-
api.configuration.auth_key = 'invalid'
|
|
45
|
-
api
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'raises an unauthorized error' do
|
|
49
|
-
expect { glossary_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
27
|
end
|
|
@@ -24,45 +24,4 @@ describe DeepL::Requests::Languages do
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
|
|
28
|
-
describe '#request' do
|
|
29
|
-
around do |example|
|
|
30
|
-
VCR.use_cassette('languages') { example.call }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when requesting source languages' do
|
|
34
|
-
it 'returns a valid list of source languages' do
|
|
35
|
-
languages = languages_obj.request
|
|
36
|
-
|
|
37
|
-
expect(languages).to be_an(Array)
|
|
38
|
-
expect(languages.size).to eq(29)
|
|
39
|
-
expect(languages).to(be_any { |l| l.code == 'EN' && l.name == 'English' })
|
|
40
|
-
expect(languages).to(be_any { |l| l.code == 'ES' && l.name == 'Spanish' })
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'when requesting target languages' do
|
|
45
|
-
let(:options) { { type: :target } }
|
|
46
|
-
|
|
47
|
-
it 'returns a valid list of target languages' do
|
|
48
|
-
languages = languages_obj.request
|
|
49
|
-
|
|
50
|
-
expect(languages).to be_an(Array)
|
|
51
|
-
expect(languages.size).to eq(31)
|
|
52
|
-
expect(languages).not_to(be_any { |l| l.code == 'EN' && l.name == 'English' })
|
|
53
|
-
expect(languages).to(be_any { |l| l.code == 'ES' && l.name == 'Spanish' })
|
|
54
|
-
expect(languages)
|
|
55
|
-
.to(be_any { |l| l.code == 'EN-US' && l.name == 'English (American)' })
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context 'when using an invalid type' do
|
|
60
|
-
let(:options) { { type: :invalid } }
|
|
61
|
-
|
|
62
|
-
it 'returns an usage object' do
|
|
63
|
-
message = "Parameter 'type' is invalid. 'source' and 'target' are valid values."
|
|
64
|
-
expect { languages_obj.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
27
|
end
|