deepl-rb 3.3.0 → 3.5.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/CHANGELOG.md +21 -2
- data/README.md +72 -0
- metadata +2 -95
- data/.circleci/config.yml +0 -27
- data/.github/workflows/add_issues_to_kanban.yml +0 -16
- data/.gitlab-ci.yml +0 -172
- data/.rubocop.yml +0 -51
- data/CODE_OF_CONDUCT.md +0 -132
- data/CONTRIBUTING.md +0 -37
- data/Gemfile +0 -24
- data/Rakefile +0 -54
- data/SECURITY.md +0 -58
- data/VERSION +0 -1
- data/deepl-rb.gemspec +0 -133
- data/lib/deepl/api.rb +0 -22
- data/lib/deepl/configuration.rb +0 -59
- data/lib/deepl/constants/base_constant.rb +0 -18
- data/lib/deepl/constants/formality.rb +0 -16
- data/lib/deepl/constants/model_type.rb +0 -14
- data/lib/deepl/constants/split_sentences.rb +0 -14
- data/lib/deepl/constants/tag_handling.rb +0 -13
- data/lib/deepl/constants/tone.rb +0 -20
- data/lib/deepl/constants/writing_style.rb +0 -20
- data/lib/deepl/document_api.rb +0 -121
- data/lib/deepl/exceptions/authorization_failed.rb +0 -14
- data/lib/deepl/exceptions/bad_request.rb +0 -16
- data/lib/deepl/exceptions/document_translation_error.rb +0 -15
- data/lib/deepl/exceptions/error.rb +0 -14
- data/lib/deepl/exceptions/limit_exceeded.rb +0 -18
- data/lib/deepl/exceptions/not_found.rb +0 -16
- data/lib/deepl/exceptions/not_supported.rb +0 -14
- data/lib/deepl/exceptions/quota_exceeded.rb +0 -14
- data/lib/deepl/exceptions/request_entity_too_large.rb +0 -15
- data/lib/deepl/exceptions/request_error.rb +0 -21
- data/lib/deepl/exceptions/server_error.rb +0 -18
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/requests/base.rb +0 -196
- data/lib/deepl/requests/document/download.rb +0 -44
- data/lib/deepl/requests/document/get_status.rb +0 -44
- data/lib/deepl/requests/document/upload.rb +0 -74
- data/lib/deepl/requests/glossary/create.rb +0 -59
- data/lib/deepl/requests/glossary/destroy.rb +0 -37
- data/lib/deepl/requests/glossary/entries.rb +0 -37
- data/lib/deepl/requests/glossary/find.rb +0 -38
- data/lib/deepl/requests/glossary/language_pairs.rb +0 -38
- data/lib/deepl/requests/glossary/list.rb +0 -37
- data/lib/deepl/requests/languages.rb +0 -37
- data/lib/deepl/requests/rephrase.rb +0 -55
- data/lib/deepl/requests/translate.rb +0 -82
- data/lib/deepl/requests/usage.rb +0 -33
- data/lib/deepl/resources/base.rb +0 -17
- data/lib/deepl/resources/document_handle.rb +0 -57
- data/lib/deepl/resources/document_translation_status.rb +0 -54
- data/lib/deepl/resources/glossary.rb +0 -28
- data/lib/deepl/resources/language.rb +0 -30
- data/lib/deepl/resources/language_pair.rb +0 -23
- data/lib/deepl/resources/text.rb +0 -24
- data/lib/deepl/resources/usage.rb +0 -27
- data/lib/deepl/utils/backoff_timer.rb +0 -46
- data/lib/deepl/utils/exception_builder.rb +0 -34
- data/lib/deepl.rb +0 -147
- data/lib/http_client_options.rb +0 -22
- data/spec/api/api_spec.rb +0 -20
- data/spec/api/configuration_spec.rb +0 -122
- data/spec/api/deepl_spec.rb +0 -460
- data/spec/constants/constants_spec.rb +0 -158
- 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/translate_texts.yml +0 -10415
- data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
- data/spec/integration_tests/document_api_spec.rb +0 -177
- data/spec/integration_tests/integration_test_utils.rb +0 -170
- data/spec/requests/glossary/create_spec.rb +0 -65
- data/spec/requests/glossary/destroy_spec.rb +0 -66
- data/spec/requests/glossary/entries_spec.rb +0 -62
- data/spec/requests/glossary/find_spec.rb +0 -68
- data/spec/requests/glossary/language_pairs_spec.rb +0 -40
- data/spec/requests/glossary/list_spec.rb +0 -54
- data/spec/requests/languages_spec.rb +0 -68
- data/spec/requests/rephrase_spec.rb +0 -172
- data/spec/requests/translate_spec.rb +0 -422
- data/spec/requests/usage_spec.rb +0 -43
- data/spec/resources/glossary_spec.rb +0 -38
- data/spec/resources/language_pair_spec.rb +0 -23
- data/spec/resources/language_spec.rb +0 -45
- data/spec/resources/text_spec.rb +0 -23
- data/spec/resources/usage_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -92
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Glossary::Entries do
|
|
9
|
-
subject(:entries_obj) { described_class.new(api, id) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
|
|
19
|
-
|
|
20
|
-
describe '#initialize' do
|
|
21
|
-
context 'when building a request' do
|
|
22
|
-
it 'creates a request object' do
|
|
23
|
-
expect(entries_obj).to be_a(described_class)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
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
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Glossary::Find do
|
|
9
|
-
subject(:glossary_find) { described_class.new(api, id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(glossary_find).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
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
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Glossary::LanguagePairs do
|
|
9
|
-
subject(:language_pairs_obj) { described_class.new(api, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:options) { {} }
|
|
19
|
-
|
|
20
|
-
describe '#initialize' do
|
|
21
|
-
context 'when building a request' do
|
|
22
|
-
it 'creates a request object' do
|
|
23
|
-
expect(language_pairs_obj).to be_a(described_class)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
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
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Glossary::List do
|
|
9
|
-
subject(:glossary_list) { described_class.new(api, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:options) { {} }
|
|
19
|
-
|
|
20
|
-
describe '#initialize' do
|
|
21
|
-
context 'when building a request' do
|
|
22
|
-
it 'creates a request object' do
|
|
23
|
-
expect(glossary_list).to be_a(described_class)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
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
|
-
end
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Copyright 2021 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Languages do
|
|
9
|
-
subject(:languages_obj) { described_class.new(api, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:options) { {} }
|
|
19
|
-
|
|
20
|
-
describe '#initialize' do
|
|
21
|
-
context 'when building a request' do
|
|
22
|
-
it 'creates a request object' do
|
|
23
|
-
expect(languages_obj).to be_a(described_class)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
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
|
-
end
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Rephrase do
|
|
9
|
-
subject(:rephrase) { described_class.new(api, text, target_lang, writing_style, tone, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:text) do
|
|
19
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.'
|
|
20
|
-
end
|
|
21
|
-
let(:target_lang) { 'EN' }
|
|
22
|
-
let(:writing_style) { nil }
|
|
23
|
-
let(:tone) { nil }
|
|
24
|
-
let(:options) { {} }
|
|
25
|
-
|
|
26
|
-
describe '#request' do
|
|
27
|
-
around do |example|
|
|
28
|
-
VCR.use_cassette('rephrase_texts') { example.call }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context 'without a style or tone applied' do
|
|
32
|
-
context 'with a string as input' do
|
|
33
|
-
it 'returns a valid response as a DeepL Text resource' do
|
|
34
|
-
original_length = text.length
|
|
35
|
-
response_text = rephrase.request
|
|
36
|
-
|
|
37
|
-
expect(response_text).to be_a(DeepL::Resources::Text)
|
|
38
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
39
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
context 'with an array of texts as input' do
|
|
44
|
-
let(:text) do
|
|
45
|
-
[
|
|
46
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
47
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
48
|
-
]
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'returns a valid response as an array of DeepL Text resources' do
|
|
52
|
-
response_texts = rephrase.request
|
|
53
|
-
|
|
54
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
55
|
-
response_texts.each_with_index do |response_text, index|
|
|
56
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
57
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context 'with a valid tone applied' do
|
|
64
|
-
let(:tone) { 'friendly' }
|
|
65
|
-
|
|
66
|
-
context 'with a string as input' do
|
|
67
|
-
it 'returns a valid response with a string as text input' do
|
|
68
|
-
original_length = text.length
|
|
69
|
-
response_text = rephrase.request
|
|
70
|
-
|
|
71
|
-
expect(response_text).to be_a(DeepL::Resources::Text)
|
|
72
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
73
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context 'with an array of texts as input' do
|
|
78
|
-
let(:text) do
|
|
79
|
-
[
|
|
80
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
81
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
82
|
-
]
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'returns an array of valid text objects' do
|
|
86
|
-
response_texts = rephrase.request
|
|
87
|
-
|
|
88
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
89
|
-
response_texts.each_with_index do |response_text, index|
|
|
90
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
91
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context 'with a valid writing style applied' do
|
|
98
|
-
let(:writing_style) { 'business' }
|
|
99
|
-
|
|
100
|
-
context 'with a string as input' do
|
|
101
|
-
it 'returns a valid response with a string as text input' do
|
|
102
|
-
original_length = text.length
|
|
103
|
-
response_text = rephrase.request
|
|
104
|
-
|
|
105
|
-
expect(response_text).to be_a(DeepL::Resources::Text)
|
|
106
|
-
expect(response_text.text.length).not_to eq(original_length)
|
|
107
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
context 'with an array of texts as input' do
|
|
112
|
-
let(:text) do
|
|
113
|
-
[
|
|
114
|
-
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
|
115
|
-
'He lay on his armour-like back, and if he lifted his head a little'
|
|
116
|
-
]
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'returns an array of valid text objects' do
|
|
120
|
-
response_texts = rephrase.request
|
|
121
|
-
|
|
122
|
-
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
|
123
|
-
response_texts.each_with_index do |response_text, index|
|
|
124
|
-
expect(response_text.text.length).not_to eq(text[index].length)
|
|
125
|
-
expect(response_text.detected_source_language.upcase).to eq('EN')
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
context 'with a writing style or tone from the provided constants applied' do
|
|
132
|
-
let(:writing_style) { DeepL::Constants::WritingStyle::BUSINESS }
|
|
133
|
-
let(:tone) { DeepL::Constants::Tone::FRIENDLY }
|
|
134
|
-
|
|
135
|
-
it 'has the correct writing style and tone applied' do
|
|
136
|
-
expect(rephrase.writing_style).to eq('business')
|
|
137
|
-
expect(rephrase.tone).to eq('friendly')
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
context 'with an invalid writing style applied' do
|
|
142
|
-
let(:writing_style) { 'angry' }
|
|
143
|
-
|
|
144
|
-
it 'raises a bad request error' do
|
|
145
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
context 'when both writing style and tone are applied' do
|
|
150
|
-
let(:writing_style) { 'business' }
|
|
151
|
-
let(:tone) { 'friendly' }
|
|
152
|
-
|
|
153
|
-
it 'raises a bad request error' do
|
|
154
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
context 'when performing a bad request' do
|
|
159
|
-
context 'when using an invalid token' do
|
|
160
|
-
let(:api) do
|
|
161
|
-
api = build_deepl_api
|
|
162
|
-
api.configuration.auth_key = 'invalid'
|
|
163
|
-
api
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it 'raises an unauthorized error' do
|
|
167
|
-
expect { rephrase.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|