deepl-rb 3.6.1 → 3.7.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 +5 -0
- data/CHANGELOG.md +19 -1
- data/README.md +153 -22
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +31 -4
- data/lib/deepl/requests/base.rb +16 -0
- data/lib/deepl/requests/document/upload.rb +6 -5
- 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 +15 -2
- 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 +68 -51
- data/lib/version.rb +1 -1
- data/spec/fixtures/vcr_cassettes/style_rules_crud.yml +926 -0
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +1 -1
- data/spec/fixtures/vcr_cassettes/translation_memories.yml +74 -0
- data/spec/integration_tests/style_rule_api_spec.rb +56 -0
- data/spec/integration_tests/translation_memory_api_spec.rb +70 -0
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +54 -0
- data/spec/requests/style_rule/create_spec.rb +45 -0
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +54 -0
- data/spec/requests/style_rule/destroy_spec.rb +54 -0
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +56 -0
- data/spec/requests/style_rule/find_spec.rb +56 -0
- data/spec/requests/style_rule/list_spec.rb +58 -0
- data/spec/requests/style_rule/update_configured_rules_spec.rb +52 -0
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +58 -0
- data/spec/requests/style_rule/update_spec.rb +48 -0
- data/spec/requests/translate_spec.rb +1 -2
- data/spec/requests/translation_memory/list_spec.rb +61 -0
- data/spec/resources/translation_memory_spec.rb +35 -0
- metadata +30 -3
|
@@ -10367,7 +10367,7 @@ http_interactions:
|
|
|
10367
10367
|
- de2645cb65c3418db54e3bdefd35fe52
|
|
10368
10368
|
body:
|
|
10369
10369
|
encoding: ASCII-8BIT
|
|
10370
|
-
string: '{"translations":[{"detected_source_language":"EN","text":"Beispieltext","model_type_used":"
|
|
10370
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Beispieltext","model_type_used":"quality_optimized"}]}'
|
|
10371
10371
|
recorded_at: Fri, 15 Nov 2024 11:35:22 GMT
|
|
10372
10372
|
- request:
|
|
10373
10373
|
method: post
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: get
|
|
5
|
+
uri: https://api.deepl.com/v3/translation_memories
|
|
6
|
+
body:
|
|
7
|
+
encoding: US-ASCII
|
|
8
|
+
string: ''
|
|
9
|
+
headers:
|
|
10
|
+
Authorization:
|
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
|
12
|
+
User-Agent:
|
|
13
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.2.2
|
|
14
|
+
Content-Type:
|
|
15
|
+
- application/json
|
|
16
|
+
Accept-Encoding:
|
|
17
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
18
|
+
Accept:
|
|
19
|
+
- "*/*"
|
|
20
|
+
response:
|
|
21
|
+
status:
|
|
22
|
+
code: 200
|
|
23
|
+
message: OK
|
|
24
|
+
headers:
|
|
25
|
+
Content-Type:
|
|
26
|
+
- application/json; charset=utf-8
|
|
27
|
+
Date:
|
|
28
|
+
- Tue, 22 Apr 2026 10:00:00 GMT
|
|
29
|
+
X-Trace-Id:
|
|
30
|
+
- abc123def456
|
|
31
|
+
Access-Control-Expose-Headers:
|
|
32
|
+
- Server-Timing, X-Trace-ID
|
|
33
|
+
Strict-Transport-Security:
|
|
34
|
+
- max-age=63072000; includeSubDomains; preload
|
|
35
|
+
Transfer-Encoding:
|
|
36
|
+
- chunked
|
|
37
|
+
Vary:
|
|
38
|
+
- Accept-Encoding
|
|
39
|
+
body:
|
|
40
|
+
encoding: ASCII-8BIT
|
|
41
|
+
string: '{"translation_memories":[{"translation_memory_id":"a74d88fb-ed2a-4943-a664-a4512398b994","name":"Legal","source_language":"en","target_languages":["es","de"],"segment_count":3542},{"translation_memory_id":"855d36ab-6112-4ef5-8868-0d69bc4d826a","name":"Medical
|
|
42
|
+
terms","source_language":"de","target_languages":["fr","ja","zh"],"segment_count":23}],"total_count":2}'
|
|
43
|
+
recorded_at: Tue, 22 Apr 2026 10:00:00 GMT
|
|
44
|
+
- request:
|
|
45
|
+
method: get
|
|
46
|
+
uri: https://api.deepl.com/v3/translation_memories
|
|
47
|
+
body:
|
|
48
|
+
encoding: US-ASCII
|
|
49
|
+
string: ''
|
|
50
|
+
headers:
|
|
51
|
+
Authorization:
|
|
52
|
+
- DeepL-Auth-Key invalid
|
|
53
|
+
User-Agent:
|
|
54
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.2.2
|
|
55
|
+
Content-Type:
|
|
56
|
+
- application/json
|
|
57
|
+
Accept-Encoding:
|
|
58
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
|
59
|
+
Accept:
|
|
60
|
+
- "*/*"
|
|
61
|
+
response:
|
|
62
|
+
status:
|
|
63
|
+
code: 403
|
|
64
|
+
message: Forbidden
|
|
65
|
+
headers:
|
|
66
|
+
Content-Type:
|
|
67
|
+
- application/json; charset=utf-8
|
|
68
|
+
Date:
|
|
69
|
+
- Tue, 22 Apr 2026 10:00:01 GMT
|
|
70
|
+
body:
|
|
71
|
+
encoding: ASCII-8BIT
|
|
72
|
+
string: '{"message":"Forbidden"}'
|
|
73
|
+
recorded_at: Tue, 22 Apr 2026 10:00:01 GMT
|
|
74
|
+
recorded_with: VCR 6.3.1
|
|
@@ -65,6 +65,62 @@ describe DeepL::StyleRuleApi do
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
describe 'style rule management operations' do
|
|
69
|
+
it 'when performing all management operations on style rules' do # rubocop:disable RSpec/ExampleLength,RSpec/MultipleExpectations
|
|
70
|
+
skip 'Only runs on mock server' if real_server?
|
|
71
|
+
|
|
72
|
+
# Create a style rule
|
|
73
|
+
style_rule = DeepL.style_rules.create('Test Style Rule', 'en')
|
|
74
|
+
expect(style_rule).to be_a(DeepL::Resources::StyleRule)
|
|
75
|
+
expect(style_rule.style_id).not_to be_nil
|
|
76
|
+
style_id = style_rule.style_id
|
|
77
|
+
|
|
78
|
+
# Find the style rule
|
|
79
|
+
found_rule = DeepL.style_rules.find(style_id)
|
|
80
|
+
expect(found_rule).to be_a(DeepL::Resources::StyleRule)
|
|
81
|
+
expect(found_rule.style_id).to eq(style_id)
|
|
82
|
+
|
|
83
|
+
# Update the style rule name
|
|
84
|
+
updated_rule = DeepL.style_rules.update_name(style_id, 'Updated Style Rule')
|
|
85
|
+
expect(updated_rule).to be_a(DeepL::Resources::StyleRule)
|
|
86
|
+
|
|
87
|
+
# Update configured rules
|
|
88
|
+
configured_rules = {
|
|
89
|
+
'dates_and_times' => { 'calendar_era' => 'use_bc_and_ad' }
|
|
90
|
+
}
|
|
91
|
+
updated_rule = DeepL.style_rules.update_configured_rules(style_id, configured_rules)
|
|
92
|
+
expect(updated_rule).to be_a(DeepL::Resources::StyleRule)
|
|
93
|
+
|
|
94
|
+
# Create a custom instruction
|
|
95
|
+
custom_instruction = DeepL.style_rules.create_custom_instruction(
|
|
96
|
+
style_id, 'Test Instruction', 'Always use formal language'
|
|
97
|
+
)
|
|
98
|
+
expect(custom_instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
99
|
+
expect(custom_instruction.id).not_to be_nil
|
|
100
|
+
instruction_id = custom_instruction.id
|
|
101
|
+
|
|
102
|
+
# Find a custom instruction
|
|
103
|
+
fetched_instruction = DeepL.style_rules.find_custom_instruction(style_id, instruction_id)
|
|
104
|
+
expect(fetched_instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
105
|
+
expect(fetched_instruction.id).to eq(instruction_id)
|
|
106
|
+
|
|
107
|
+
# Update a custom instruction
|
|
108
|
+
updated_instruction = DeepL.style_rules.update_custom_instruction(
|
|
109
|
+
style_id, instruction_id, 'Updated Instruction', 'Use casual language'
|
|
110
|
+
)
|
|
111
|
+
expect(updated_instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
112
|
+
|
|
113
|
+
# Destroy the custom instruction
|
|
114
|
+
deleted_instruction_id = DeepL.style_rules.destroy_custom_instruction(style_id,
|
|
115
|
+
instruction_id)
|
|
116
|
+
expect(deleted_instruction_id).to eq(instruction_id)
|
|
117
|
+
|
|
118
|
+
# Destroy the style rule
|
|
119
|
+
deleted_style_id = DeepL.style_rules.destroy(style_id)
|
|
120
|
+
expect(deleted_style_id).to eq(style_id)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
68
124
|
def build_test_style_rule
|
|
69
125
|
style_rule_data = {
|
|
70
126
|
'style_id' => 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4',
|
|
@@ -0,0 +1,70 @@
|
|
|
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 do
|
|
9
|
+
before do
|
|
10
|
+
VCR.turn_off!
|
|
11
|
+
WebMock.allow_net_connect!
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
after do
|
|
15
|
+
VCR.turn_on!
|
|
16
|
+
WebMock.disable_net_connect!
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe '#translate_with_translation_memory' do
|
|
20
|
+
it 'when performing a request with translation_memory_id' do
|
|
21
|
+
skip 'Only runs on mock server' if real_server?
|
|
22
|
+
|
|
23
|
+
source_lang = 'DE'
|
|
24
|
+
target_lang = 'EN'
|
|
25
|
+
text = 'Protonenstrahl'
|
|
26
|
+
translation_memory_id = 'a74d88fb-ed2a-4943-a664-a4512398b994'
|
|
27
|
+
|
|
28
|
+
result = DeepL.translate(text, source_lang, target_lang,
|
|
29
|
+
{ translation_memory: translation_memory_id })
|
|
30
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'when performing a request with translation_memory resource object' do
|
|
34
|
+
skip 'Only runs on mock server' if real_server?
|
|
35
|
+
|
|
36
|
+
source_lang = 'DE'
|
|
37
|
+
target_lang = 'EN'
|
|
38
|
+
text = 'Protonenstrahl'
|
|
39
|
+
translation_memory = build_test_translation_memory
|
|
40
|
+
|
|
41
|
+
result = DeepL.translate(text, source_lang, target_lang,
|
|
42
|
+
{ translation_memory: translation_memory })
|
|
43
|
+
expect(result).to be_a(DeepL::Resources::Text)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
describe '#list_translation_memories' do
|
|
48
|
+
it 'when requesting a list of all translation memories' do
|
|
49
|
+
skip 'Only runs on mock server' if real_server?
|
|
50
|
+
|
|
51
|
+
translation_memories = DeepL.translation_memories.list
|
|
52
|
+
expect(translation_memories).to be_an(Array)
|
|
53
|
+
expect(translation_memories).not_to be_empty
|
|
54
|
+
expect(translation_memories.first).to be_a(DeepL::Resources::TranslationMemory)
|
|
55
|
+
expect(translation_memories.first.translation_memory_id).not_to be_nil
|
|
56
|
+
expect(translation_memories.first.name).not_to be_nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def build_test_translation_memory
|
|
61
|
+
tm_data = {
|
|
62
|
+
'translation_memory_id' => 'a74d88fb-ed2a-4943-a664-a4512398b994',
|
|
63
|
+
'name' => 'Default Translation Memory',
|
|
64
|
+
'source_language' => 'DE',
|
|
65
|
+
'target_languages' => %w[EN ES FR],
|
|
66
|
+
'segment_count' => 3542
|
|
67
|
+
}
|
|
68
|
+
DeepL::Resources::TranslationMemory.new(tm_data, nil, nil)
|
|
69
|
+
end
|
|
70
|
+
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::CreateCustomInstruction do
|
|
9
|
+
subject(:create_instruction) { described_class.new(api, style_id, label, prompt, nil, 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(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
19
|
+
let(:label) { 'Test Instruction' }
|
|
20
|
+
let(:prompt) { 'Always use formal language' }
|
|
21
|
+
let(:options) { {} }
|
|
22
|
+
|
|
23
|
+
describe '#initialize' do
|
|
24
|
+
context 'when building a request' do
|
|
25
|
+
it 'creates a request object' do
|
|
26
|
+
expect(create_instruction).to be_a(described_class)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#request' do
|
|
32
|
+
around do |example|
|
|
33
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when performing a valid request' do
|
|
37
|
+
subject(:create_instruction) do
|
|
38
|
+
described_class.new(api, new_rule.style_id, label, prompt)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
let(:new_rule) do
|
|
42
|
+
DeepL::Requests::StyleRule::Create.new(api, 'Instruction Test', 'en').request
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'returns a custom instruction object' do
|
|
46
|
+
instruction = create_instruction.request
|
|
47
|
+
expect(instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
48
|
+
expect(instruction.id).to be_a(String)
|
|
49
|
+
expect(instruction.label).to eq('Test Instruction')
|
|
50
|
+
expect(instruction.prompt).to eq('Always use formal language')
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::Create do
|
|
9
|
+
subject(:create) { described_class.new(api, name, language, 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(:name) { 'Test Style Rule' }
|
|
19
|
+
let(:language) { 'en' }
|
|
20
|
+
let(:options) { {} }
|
|
21
|
+
|
|
22
|
+
describe '#initialize' do
|
|
23
|
+
context 'when building a request' do
|
|
24
|
+
it 'creates a request object' do
|
|
25
|
+
expect(create).to be_a(described_class)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#request' do
|
|
31
|
+
around do |example|
|
|
32
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when performing a valid request' do
|
|
36
|
+
it 'returns a style rule object' do
|
|
37
|
+
style_rule = create.request
|
|
38
|
+
expect(style_rule).to be_a(DeepL::Resources::StyleRule)
|
|
39
|
+
expect(style_rule.style_id).to be_a(String)
|
|
40
|
+
expect(style_rule.name).to eq('Test Style Rule')
|
|
41
|
+
expect(style_rule.language).to eq('en')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::DestroyCustomInstruction do
|
|
9
|
+
subject(:destroy_instruction) { described_class.new(api, style_id, instruction_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(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
19
|
+
let(:instruction_id) { 'test-instruction-id' }
|
|
20
|
+
|
|
21
|
+
describe '#initialize' do
|
|
22
|
+
context 'when building a request' do
|
|
23
|
+
it 'creates a request object' do
|
|
24
|
+
expect(destroy_instruction).to be_a(described_class)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
describe '#request' do
|
|
30
|
+
around do |example|
|
|
31
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when performing a valid request' do
|
|
35
|
+
subject(:destroy_instruction) do
|
|
36
|
+
described_class.new(api, new_rule.style_id, new_instruction.id)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
let(:new_rule) do
|
|
40
|
+
DeepL::Requests::StyleRule::Create.new(api, 'Destroy Instruction Test', 'en').request
|
|
41
|
+
end
|
|
42
|
+
let(:new_instruction) do
|
|
43
|
+
DeepL::Requests::StyleRule::CreateCustomInstruction.new(
|
|
44
|
+
api, new_rule.style_id, 'To Delete', 'Delete me'
|
|
45
|
+
).request
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'returns the deleted instruction id' do
|
|
49
|
+
response = destroy_instruction.request
|
|
50
|
+
expect(response).to eq(new_instruction.id)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::Destroy do
|
|
9
|
+
subject(:destroy) { described_class.new(api, style_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(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
19
|
+
|
|
20
|
+
describe '#initialize' do
|
|
21
|
+
context 'when building a request' do
|
|
22
|
+
it 'creates a request object' do
|
|
23
|
+
expect(destroy).to be_a(described_class)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
describe '#request' do
|
|
29
|
+
around do |example|
|
|
30
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'when performing a valid request' do
|
|
34
|
+
subject(:destroy) { described_class.new(api, new_rule.style_id) }
|
|
35
|
+
|
|
36
|
+
let(:new_rule) do
|
|
37
|
+
DeepL::Requests::StyleRule::Create.new(api, 'Destroy Test', 'en').request
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns the deleted style rule id' do
|
|
41
|
+
response = destroy.request
|
|
42
|
+
expect(response).to eq(new_rule.style_id)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'when deleting a non existing style rule with an invalid id' do
|
|
47
|
+
let(:style_id) { 'invalid-uuid' }
|
|
48
|
+
|
|
49
|
+
it 'raises an error' do
|
|
50
|
+
expect { destroy.request }.to raise_error(DeepL::Exceptions::Error)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::FindCustomInstruction do
|
|
9
|
+
subject(:find_instruction) { described_class.new(api, style_id, instruction_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(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
19
|
+
let(:instruction_id) { 'test-instruction-id' }
|
|
20
|
+
let(:options) { {} }
|
|
21
|
+
|
|
22
|
+
describe '#initialize' do
|
|
23
|
+
context 'when building a request' do
|
|
24
|
+
it 'creates a request object' do
|
|
25
|
+
expect(find_instruction).to be_a(described_class)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe '#request' do
|
|
31
|
+
around do |example|
|
|
32
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'when performing a valid request' do
|
|
36
|
+
subject(:find_instruction) do
|
|
37
|
+
described_class.new(api, new_rule.style_id, new_instruction.id)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
let(:new_rule) do
|
|
41
|
+
DeepL::Requests::StyleRule::Create.new(api, 'Find Instruction Test', 'en').request
|
|
42
|
+
end
|
|
43
|
+
let(:new_instruction) do
|
|
44
|
+
DeepL::Requests::StyleRule::CreateCustomInstruction.new(
|
|
45
|
+
api, new_rule.style_id, 'Test', 'Test prompt'
|
|
46
|
+
).request
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'returns a custom instruction object' do
|
|
50
|
+
instruction = find_instruction.request
|
|
51
|
+
expect(instruction).to be_a(DeepL::Resources::CustomInstruction)
|
|
52
|
+
expect(instruction.id).to eq(new_instruction.id)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::Find do
|
|
9
|
+
subject(:style_rule_find) { described_class.new(api, style_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(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
19
|
+
let(:options) { {} }
|
|
20
|
+
|
|
21
|
+
describe '#initialize' do
|
|
22
|
+
context 'when building a request' do
|
|
23
|
+
it 'creates a request object' do
|
|
24
|
+
expect(style_rule_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('style_rules_crud') { example.call }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context 'when performing a valid request' do
|
|
35
|
+
subject(:style_rule_find) do
|
|
36
|
+
new_rule = DeepL::Requests::StyleRule::Create.new(api, 'Find Test', 'en').request
|
|
37
|
+
described_class.new(api, new_rule.style_id, options)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'returns a style rule object' do
|
|
41
|
+
style_rule = style_rule_find.request
|
|
42
|
+
expect(style_rule).to be_a(DeepL::Resources::StyleRule)
|
|
43
|
+
expect(style_rule.style_id).to be_a(String)
|
|
44
|
+
expect(style_rule.name).to be_a(String)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context 'when requesting a non existing style rule with an invalid id' do
|
|
49
|
+
let(:style_id) { 'invalid-uuid' }
|
|
50
|
+
|
|
51
|
+
it 'raises an error' do
|
|
52
|
+
expect { style_rule_find.request }.to raise_error(DeepL::Exceptions::Error)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::List do
|
|
9
|
+
subject(:style_rule_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(style_rule_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('style_rules') { example.call }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'when requesting a list of all style rules' do
|
|
34
|
+
it 'returns an array of style rules' do
|
|
35
|
+
style_rules = style_rule_list.request
|
|
36
|
+
expect(style_rules).to be_an(Array)
|
|
37
|
+
expect(style_rules).not_to be_empty
|
|
38
|
+
expect(style_rules.first).to be_a(DeepL::Resources::StyleRule)
|
|
39
|
+
expect(style_rules.first.style_id).to be_a(String)
|
|
40
|
+
expect(style_rules.first.name).to be_a(String)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'when performing a bad request' do
|
|
45
|
+
context 'when using an invalid token' do
|
|
46
|
+
let(:api) do
|
|
47
|
+
api = build_deepl_api
|
|
48
|
+
api.configuration.auth_key = 'invalid'
|
|
49
|
+
api
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it 'raises an authorization failed error' do
|
|
53
|
+
expect { style_rule_list.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
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.md file.
|
|
4
|
+
# frozen_string_literal: true
|
|
5
|
+
|
|
6
|
+
require 'spec_helper'
|
|
7
|
+
|
|
8
|
+
describe DeepL::Requests::StyleRule::UpdateConfiguredRules do
|
|
9
|
+
subject(:update_configured_rules) do
|
|
10
|
+
described_class.new(api, style_id, configured_rules, options)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
around do |tests|
|
|
14
|
+
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
15
|
+
tests.call
|
|
16
|
+
ENV.replace(tmp_env)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
let(:api) { build_deepl_api }
|
|
20
|
+
let(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
|
|
21
|
+
let(:configured_rules) { { 'dates_and_times' => { 'calendar_era' => 'use_bc_and_ad' } } }
|
|
22
|
+
let(:options) { {} }
|
|
23
|
+
|
|
24
|
+
describe '#initialize' do
|
|
25
|
+
context 'when building a request' do
|
|
26
|
+
it 'creates a request object' do
|
|
27
|
+
expect(update_configured_rules).to be_a(described_class)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe '#request' do
|
|
33
|
+
around do |example|
|
|
34
|
+
VCR.use_cassette('style_rules_crud') { example.call }
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context 'when performing a valid request' do
|
|
38
|
+
subject(:update_configured_rules) do
|
|
39
|
+
described_class.new(api, new_rule.style_id, configured_rules)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
let(:new_rule) do
|
|
43
|
+
DeepL::Requests::StyleRule::Create.new(api, 'Configured Rules Test', 'en').request
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'returns a style rule object' do
|
|
47
|
+
style_rule = update_configured_rules.request
|
|
48
|
+
expect(style_rule).to be_a(DeepL::Resources::StyleRule)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|