deepl-rb 3.2.0 → 3.4.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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +46 -27
  3. data/README.md +71 -0
  4. metadata +3 -95
  5. data/.circleci/config.yml +0 -27
  6. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  7. data/.gitlab-ci.yml +0 -135
  8. data/.rubocop.yml +0 -51
  9. data/CODE_OF_CONDUCT.md +0 -132
  10. data/CONTRIBUTING.md +0 -37
  11. data/Gemfile +0 -24
  12. data/Rakefile +0 -53
  13. data/SECURITY.md +0 -58
  14. data/VERSION +0 -1
  15. data/deepl-rb.gemspec +0 -132
  16. data/lib/deepl/api.rb +0 -22
  17. data/lib/deepl/configuration.rb +0 -59
  18. data/lib/deepl/constants/base_constant.rb +0 -18
  19. data/lib/deepl/constants/formality.rb +0 -16
  20. data/lib/deepl/constants/model_type.rb +0 -14
  21. data/lib/deepl/constants/split_sentences.rb +0 -14
  22. data/lib/deepl/constants/tag_handling.rb +0 -13
  23. data/lib/deepl/constants/tone.rb +0 -20
  24. data/lib/deepl/constants/writing_style.rb +0 -20
  25. data/lib/deepl/document_api.rb +0 -121
  26. data/lib/deepl/exceptions/authorization_failed.rb +0 -14
  27. data/lib/deepl/exceptions/bad_request.rb +0 -16
  28. data/lib/deepl/exceptions/document_translation_error.rb +0 -15
  29. data/lib/deepl/exceptions/error.rb +0 -14
  30. data/lib/deepl/exceptions/limit_exceeded.rb +0 -18
  31. data/lib/deepl/exceptions/not_found.rb +0 -16
  32. data/lib/deepl/exceptions/not_supported.rb +0 -14
  33. data/lib/deepl/exceptions/quota_exceeded.rb +0 -14
  34. data/lib/deepl/exceptions/request_entity_too_large.rb +0 -15
  35. data/lib/deepl/exceptions/request_error.rb +0 -21
  36. data/lib/deepl/exceptions/server_error.rb +0 -18
  37. data/lib/deepl/glossary_api.rb +0 -38
  38. data/lib/deepl/requests/base.rb +0 -163
  39. data/lib/deepl/requests/document/download.rb +0 -44
  40. data/lib/deepl/requests/document/get_status.rb +0 -44
  41. data/lib/deepl/requests/document/upload.rb +0 -64
  42. data/lib/deepl/requests/glossary/create.rb +0 -59
  43. data/lib/deepl/requests/glossary/destroy.rb +0 -37
  44. data/lib/deepl/requests/glossary/entries.rb +0 -37
  45. data/lib/deepl/requests/glossary/find.rb +0 -38
  46. data/lib/deepl/requests/glossary/language_pairs.rb +0 -38
  47. data/lib/deepl/requests/glossary/list.rb +0 -37
  48. data/lib/deepl/requests/languages.rb +0 -37
  49. data/lib/deepl/requests/rephrase.rb +0 -54
  50. data/lib/deepl/requests/translate.rb +0 -82
  51. data/lib/deepl/requests/usage.rb +0 -33
  52. data/lib/deepl/resources/base.rb +0 -17
  53. data/lib/deepl/resources/document_handle.rb +0 -57
  54. data/lib/deepl/resources/document_translation_status.rb +0 -54
  55. data/lib/deepl/resources/glossary.rb +0 -28
  56. data/lib/deepl/resources/language.rb +0 -30
  57. data/lib/deepl/resources/language_pair.rb +0 -23
  58. data/lib/deepl/resources/text.rb +0 -24
  59. data/lib/deepl/resources/usage.rb +0 -27
  60. data/lib/deepl/utils/backoff_timer.rb +0 -46
  61. data/lib/deepl/utils/exception_builder.rb +0 -34
  62. data/lib/deepl.rb +0 -142
  63. data/lib/http_client_options.rb +0 -22
  64. data/spec/api/api_spec.rb +0 -20
  65. data/spec/api/configuration_spec.rb +0 -122
  66. data/spec/api/deepl_spec.rb +0 -431
  67. data/spec/constants/constants_spec.rb +0 -158
  68. data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
  69. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
  70. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
  71. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
  72. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
  73. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
  74. data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
  75. data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
  76. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
  77. data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10372
  78. data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
  79. data/spec/integration_tests/document_api_spec.rb +0 -155
  80. data/spec/integration_tests/integration_test_utils.rb +0 -170
  81. data/spec/requests/glossary/create_spec.rb +0 -65
  82. data/spec/requests/glossary/destroy_spec.rb +0 -66
  83. data/spec/requests/glossary/entries_spec.rb +0 -62
  84. data/spec/requests/glossary/find_spec.rb +0 -68
  85. data/spec/requests/glossary/language_pairs_spec.rb +0 -40
  86. data/spec/requests/glossary/list_spec.rb +0 -54
  87. data/spec/requests/languages_spec.rb +0 -68
  88. data/spec/requests/rephrase_spec.rb +0 -172
  89. data/spec/requests/translate_spec.rb +0 -410
  90. data/spec/requests/usage_spec.rb +0 -43
  91. data/spec/resources/glossary_spec.rb +0 -38
  92. data/spec/resources/language_pair_spec.rb +0 -23
  93. data/spec/resources/language_spec.rb +0 -45
  94. data/spec/resources/text_spec.rb +0 -23
  95. data/spec/resources/usage_spec.rb +0 -35
  96. data/spec/spec_helper.rb +0 -92
@@ -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