deepl-rb 2.5.3 → 3.0.1
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 +39 -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 +121 -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 +155 -0
- data/spec/integration_tests/integration_test_utils.rb +170 -0
- data/spec/requests/glossary/create_spec.rb +23 -13
- data/spec/requests/glossary/destroy_spec.rb +33 -17
- data/spec/requests/glossary/entries_spec.rb +31 -17
- data/spec/requests/glossary/find_spec.rb +31 -17
- data/spec/requests/glossary/language_pairs_spec.rb +17 -7
- data/spec/requests/glossary/list_spec.rb +21 -11
- data/spec/requests/languages_spec.rb +31 -21
- data/spec/requests/translate_spec.rb +125 -131
- data/spec/requests/usage_spec.rb +17 -7
- data/spec/resources/glossary_spec.rb +15 -12
- data/spec/resources/language_pair_spec.rb +10 -7
- data/spec/resources/language_spec.rb +21 -18
- data/spec/resources/text_spec.rb +10 -7
- data/spec/resources/usage_spec.rb +16 -13
- data/spec/spec_helper.rb +63 -6
- metadata +32 -9
@@ -1,16 +1,26 @@
|
|
1
|
+
# Copyright 2022 Daniel Herzog
|
2
|
+
# Use of this source code is governed by an MIT
|
3
|
+
# license that can be found in the LICENSE.md file.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
|
-
let(:id) { '
|
8
|
-
subject { DeepL::Requests::Glossary::Entries.new(api, id) }
|
18
|
+
let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
|
9
19
|
|
10
20
|
describe '#initialize' do
|
11
|
-
context '
|
12
|
-
it '
|
13
|
-
expect(
|
21
|
+
context 'when building a request' do
|
22
|
+
it 'creates a request object' do
|
23
|
+
expect(entries_obj).to be_a(described_class)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -20,28 +30,32 @@ describe DeepL::Requests::Glossary::Entries do
|
|
20
30
|
VCR.use_cassette('glossaries') { example.call }
|
21
31
|
end
|
22
32
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
entries =
|
26
|
-
expect(entries).to
|
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)
|
27
37
|
expect(entries).to all(be_a(Array))
|
28
38
|
expect(entries.size).to eq(2)
|
29
39
|
end
|
30
40
|
end
|
31
41
|
|
32
|
-
context '
|
42
|
+
context 'when requesting entries with a valid but non existing glossary id' do
|
43
|
+
subject(:entries_obj) { described_class.new(api, id) }
|
44
|
+
|
33
45
|
let(:id) { '00000000-0000-0000-0000-000000000000' }
|
34
|
-
|
35
|
-
it '
|
36
|
-
expect {
|
46
|
+
|
47
|
+
it 'raises a not found error' do
|
48
|
+
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::NotFound)
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
40
|
-
context '
|
52
|
+
context 'when requesting entries with an invalid glossary id' do
|
53
|
+
subject(:entries_obj) { described_class.new(api, id) }
|
54
|
+
|
41
55
|
let(:id) { 'invalid-uuid' }
|
42
|
-
|
43
|
-
it '
|
44
|
-
expect {
|
56
|
+
|
57
|
+
it 'raises a bad request error' do
|
58
|
+
expect { entries_obj.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
45
59
|
end
|
46
60
|
end
|
47
61
|
end
|
@@ -1,17 +1,27 @@
|
|
1
|
+
# Copyright 2022 Daniel Herzog
|
2
|
+
# Use of this source code is governed by an MIT
|
3
|
+
# license that can be found in the LICENSE.md file.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
|
-
let(:id) { '
|
18
|
+
let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
|
8
19
|
let(:options) { {} }
|
9
|
-
subject { DeepL::Requests::Glossary::Find.new(api, id, options) }
|
10
20
|
|
11
21
|
describe '#initialize' do
|
12
|
-
context '
|
13
|
-
it '
|
14
|
-
expect(
|
22
|
+
context 'when building a request' do
|
23
|
+
it 'creates a request object' do
|
24
|
+
expect(glossary_find).to be_a(described_class)
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
@@ -21,11 +31,11 @@ describe DeepL::Requests::Glossary::Find do
|
|
21
31
|
VCR.use_cassette('glossaries') { example.call }
|
22
32
|
end
|
23
33
|
|
24
|
-
context '
|
25
|
-
it '
|
26
|
-
glossary =
|
34
|
+
context 'when performing a valid request' do
|
35
|
+
it 'returns a glossary object' do
|
36
|
+
glossary = glossary_find.request
|
27
37
|
expect(glossary).to be_a(DeepL::Resources::Glossary)
|
28
|
-
expect(glossary.id).to eq('
|
38
|
+
expect(glossary.id).to eq('9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb')
|
29
39
|
expect(glossary.name).to eq('Mi Glosario')
|
30
40
|
expect(glossary.ready).to be(true).or be(false)
|
31
41
|
expect(glossary.source_lang).to eq('en')
|
@@ -35,19 +45,23 @@ describe DeepL::Requests::Glossary::Find do
|
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
|
-
context '
|
48
|
+
context 'when requesting a non existing glossary with a valid id' do
|
49
|
+
subject(:glossary_find) { described_class.new(api, id, options) }
|
50
|
+
|
39
51
|
let(:id) { 'a0af40e1-d81b-4aab-a95c-7cafbcfd1eb1' }
|
40
|
-
|
41
|
-
it '
|
42
|
-
expect {
|
52
|
+
|
53
|
+
it 'raises a not found error' do
|
54
|
+
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::NotFound)
|
43
55
|
end
|
44
56
|
end
|
45
57
|
|
46
|
-
context '
|
58
|
+
context 'when requesting a non existing glossary with an invalid id' do
|
59
|
+
subject(:glossary_find) { described_class.new(api, id, options) }
|
60
|
+
|
47
61
|
let(:id) { 'invalid-uuid' }
|
48
|
-
|
49
|
-
it '
|
50
|
-
expect {
|
62
|
+
|
63
|
+
it 'raises a bad request error' do
|
64
|
+
expect { glossary_find.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
51
65
|
end
|
52
66
|
end
|
53
67
|
end
|
@@ -1,16 +1,26 @@
|
|
1
|
+
# Copyright 2022 Daniel Herzog
|
2
|
+
# Use of this source code is governed by an MIT
|
3
|
+
# license that can be found in the LICENSE.md file.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
18
|
let(:options) { {} }
|
8
|
-
subject { DeepL::Requests::Glossary::LanguagePairs.new(api, options) }
|
9
19
|
|
10
20
|
describe '#initialize' do
|
11
|
-
context '
|
12
|
-
it '
|
13
|
-
expect(
|
21
|
+
context 'when building a request' do
|
22
|
+
it 'creates a request object' do
|
23
|
+
expect(language_pairs_obj).to be_a(described_class)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -20,9 +30,9 @@ describe DeepL::Requests::Glossary::LanguagePairs do
|
|
20
30
|
VCR.use_cassette('glossaries') { example.call }
|
21
31
|
end
|
22
32
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
language_pairs =
|
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
|
26
36
|
expect(language_pairs).to be_an(Array)
|
27
37
|
end
|
28
38
|
end
|
@@ -1,16 +1,26 @@
|
|
1
|
+
# Copyright 2022 Daniel Herzog
|
2
|
+
# Use of this source code is governed by an MIT
|
3
|
+
# license that can be found in the LICENSE.md file.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
18
|
let(:options) { {} }
|
8
|
-
subject { DeepL::Requests::Glossary::List.new(api, options) }
|
9
19
|
|
10
20
|
describe '#initialize' do
|
11
|
-
context '
|
12
|
-
it '
|
13
|
-
expect(
|
21
|
+
context 'when building a request' do
|
22
|
+
it 'creates a request object' do
|
23
|
+
expect(glossary_list).to be_a(described_class)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -20,23 +30,23 @@ describe DeepL::Requests::Glossary::List do
|
|
20
30
|
VCR.use_cassette('glossaries') { example.call }
|
21
31
|
end
|
22
32
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
glossaries =
|
33
|
+
context 'when requesting a list of all glossaries' do
|
34
|
+
it 'returns a glossaries object' do
|
35
|
+
glossaries = glossary_list.request
|
26
36
|
expect(glossaries).to be_an(Array)
|
27
37
|
end
|
28
38
|
end
|
29
39
|
|
30
|
-
context '
|
31
|
-
context '
|
40
|
+
context 'when performing a bad request' do
|
41
|
+
context 'when using an invalid token' do
|
32
42
|
let(:api) do
|
33
43
|
api = build_deepl_api
|
34
44
|
api.configuration.auth_key = 'invalid'
|
35
45
|
api
|
36
46
|
end
|
37
47
|
|
38
|
-
it '
|
39
|
-
expect {
|
48
|
+
it 'raises an unauthorized error' do
|
49
|
+
expect { glossary_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
40
50
|
end
|
41
51
|
end
|
42
52
|
end
|
@@ -1,16 +1,26 @@
|
|
1
|
+
# Copyright 2021 Daniel Herzog
|
2
|
+
# Use of this source code is governed by an MIT
|
3
|
+
# license that can be found in the LICENSE.md file.
|
1
4
|
# frozen_string_literal: true
|
2
5
|
|
3
6
|
require 'spec_helper'
|
4
7
|
|
5
8
|
describe DeepL::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
|
+
|
6
17
|
let(:api) { build_deepl_api }
|
7
18
|
let(:options) { {} }
|
8
|
-
subject { DeepL::Requests::Languages.new(api, options) }
|
9
19
|
|
10
20
|
describe '#initialize' do
|
11
|
-
context '
|
12
|
-
it '
|
13
|
-
expect(
|
21
|
+
context 'when building a request' do
|
22
|
+
it 'creates a request object' do
|
23
|
+
expect(languages_obj).to be_a(described_class)
|
14
24
|
end
|
15
25
|
end
|
16
26
|
end
|
@@ -20,38 +30,38 @@ describe DeepL::Requests::Languages do
|
|
20
30
|
VCR.use_cassette('languages') { example.call }
|
21
31
|
end
|
22
32
|
|
23
|
-
context '
|
24
|
-
it '
|
25
|
-
languages =
|
33
|
+
context 'when requesting source languages' do
|
34
|
+
it 'returns a valid list of source languages' do
|
35
|
+
languages = languages_obj.request
|
26
36
|
|
27
37
|
expect(languages).to be_an(Array)
|
28
|
-
expect(languages.size).to eq(
|
29
|
-
expect(languages.
|
30
|
-
expect(languages.
|
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' })
|
31
41
|
end
|
32
42
|
end
|
33
43
|
|
34
|
-
context '
|
44
|
+
context 'when requesting target languages' do
|
35
45
|
let(:options) { { type: :target } }
|
36
46
|
|
37
|
-
it '
|
38
|
-
languages =
|
47
|
+
it 'returns a valid list of target languages' do
|
48
|
+
languages = languages_obj.request
|
39
49
|
|
40
50
|
expect(languages).to be_an(Array)
|
41
|
-
expect(languages.size).to eq(
|
42
|
-
expect(languages.
|
43
|
-
expect(languages.
|
44
|
-
expect(languages
|
45
|
-
.to
|
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)' })
|
46
56
|
end
|
47
57
|
end
|
48
58
|
|
49
|
-
context '
|
59
|
+
context 'when using an invalid type' do
|
50
60
|
let(:options) { { type: :invalid } }
|
51
61
|
|
52
|
-
it '
|
62
|
+
it 'returns an usage object' do
|
53
63
|
message = "Parameter 'type' is invalid. 'source' and 'target' are valid values."
|
54
|
-
expect {
|
64
|
+
expect { languages_obj.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
55
65
|
end
|
56
66
|
end
|
57
67
|
end
|