deepl-rb 3.10.0 → 4.0.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/.rubocop.yml +1 -1
- data/CHANGELOG.md +313 -1
- data/README.md +225 -309
- data/Rakefile +17 -8
- data/VERSION +1 -1
- data/deepl-rb.gemspec +73 -86
- data/lib/deepl/admin_client.rb +39 -14
- data/lib/deepl/api.rb +3 -17
- data/lib/deepl/app_info.rb +0 -1
- data/lib/deepl/client.rb +399 -84
- data/lib/deepl/configuration.rb +19 -70
- data/lib/deepl/exceptions/authorization_failed.rb +1 -1
- data/lib/deepl/exceptions/connection_error.rb +10 -7
- data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
- data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
- data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
- data/lib/deepl/exceptions/request_error.rb +7 -0
- data/lib/deepl/exceptions/server_error.rb +2 -1
- data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
- data/lib/deepl/exceptions/validation_error.rb +3 -2
- data/lib/deepl/requests/base.rb +129 -51
- data/lib/deepl/requests/correct.rb +2 -8
- data/lib/deepl/requests/document/upload.rb +29 -26
- data/lib/deepl/requests/glossary/base.rb +30 -0
- data/lib/deepl/requests/glossary/create.rb +18 -22
- data/lib/deepl/requests/glossary/destroy.rb +4 -16
- data/lib/deepl/requests/glossary/entries.rb +6 -14
- data/lib/deepl/requests/glossary/find.rb +3 -13
- data/lib/deepl/requests/glossary/language_pairs.rb +2 -2
- data/lib/deepl/requests/glossary/list.rb +2 -2
- data/lib/deepl/requests/languages.rb +6 -11
- data/lib/deepl/requests/languages_for_resource.rb +2 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +8 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +4 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +5 -3
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +22 -14
- data/lib/deepl/requests/rephrase.rb +3 -1
- data/lib/deepl/requests/spoken_terms/create.rb +5 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +1 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +1 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +9 -2
- data/lib/deepl/requests/style_profile/create.rb +5 -0
- data/lib/deepl/requests/style_profile/list.rb +2 -2
- data/lib/deepl/requests/style_rule/create.rb +25 -1
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +7 -0
- data/lib/deepl/requests/style_rule/helpers.rb +13 -4
- data/lib/deepl/requests/style_rule/list.rb +2 -0
- data/lib/deepl/requests/style_rule/update.rb +1 -0
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +2 -0
- data/lib/deepl/requests/translate.rb +20 -36
- data/lib/deepl/requests/translation_memory/create_export.rb +6 -1
- data/lib/deepl/requests/translation_memory/create_import.rb +10 -0
- data/lib/deepl/requests/translation_memory/download_export.rb +0 -4
- data/lib/deepl/requests/translation_memory/list.rb +2 -2
- data/lib/deepl/requests/translation_memory/segments.rb +2 -2
- data/lib/deepl/requests/translation_memory/storage_base.rb +5 -9
- data/lib/deepl/requests/write_improvements.rb +7 -0
- data/lib/deepl/resources/document_handle.rb +1 -26
- data/lib/deepl/resources/document_translation_status.rb +0 -12
- data/lib/deepl/resources/language.rb +4 -10
- data/lib/deepl/resources/multilingual_glossary.rb +4 -4
- data/lib/deepl/resources/style_rule.rb +1 -23
- data/lib/deepl/resources/translation_memory_job.rb +3 -4
- data/lib/deepl/resources/usage.rb +5 -38
- data/lib/deepl/utils/client_builder.rb +44 -9
- data/lib/deepl/utils/glossary_entries.rb +30 -0
- data/lib/deepl/utils/http_client_builder.rb +50 -13
- data/lib/deepl/utils/output_path.rb +25 -0
- data/lib/deepl/utils/term_validator.rb +3 -3
- data/lib/deepl/utils/translation_memory_operations.rb +230 -0
- data/lib/deepl.rb +6 -171
- data/lib/http_client_options.rb +2 -2
- data/lib/version.rb +1 -1
- data/upgrading_to_v4.md +374 -0
- metadata +9 -50
- data/.gitlab-ci.yml +0 -197
- data/lib/deepl/deprecation.rb +0 -42
- data/lib/deepl/document_api.rb +0 -150
- data/lib/deepl/exceptions/not_supported.rb +0 -20
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/style_rule_api.rb +0 -72
- data/lib/deepl/translation_memory_api.rb +0 -389
- data/license_checker.sh +0 -8
- data/spec/fixtures.rb +0 -33
- data/spec/offline/admin_client_spec.rb +0 -551
- data/spec/offline/client_spec.rb +0 -273
- data/spec/offline/configuration_spec.rb +0 -164
- data/spec/offline/constants_spec.rb +0 -180
- data/spec/offline/correct_text_spec.rb +0 -50
- data/spec/offline/deprecation_spec.rb +0 -32
- data/spec/offline/errors_spec.rb +0 -92
- data/spec/offline/glossaries_spec.rb +0 -98
- data/spec/offline/http_client_spec.rb +0 -319
- data/spec/offline/languages_spec.rb +0 -155
- data/spec/offline/module_methods_spec.rb +0 -13
- data/spec/offline/multilingual_glossaries_spec.rb +0 -358
- data/spec/offline/offline_helper.rb +0 -71
- data/spec/offline/rephrase_text_spec.rb +0 -73
- data/spec/offline/spoken_terms_spec.rb +0 -215
- data/spec/offline/style_profiles_spec.rb +0 -266
- data/spec/offline/style_rules_spec.rb +0 -318
- data/spec/offline/translate_document_spec.rb +0 -606
- data/spec/offline/translate_text_spec.rb +0 -286
- data/spec/offline/translation_memories_client_spec.rb +0 -256
- data/spec/offline/translation_memories_spec.rb +0 -463
- data/spec/offline/usage_spec.rb +0 -151
- data/spec/real_api/admin_client_spec.rb +0 -77
- data/spec/real_api/correct_text_spec.rb +0 -20
- data/spec/real_api/glossaries_spec.rb +0 -28
- data/spec/real_api/languages_spec.rb +0 -27
- data/spec/real_api/multilingual_glossaries_spec.rb +0 -53
- data/spec/real_api/proxy_spec.rb +0 -41
- data/spec/real_api/real_api_helper.rb +0 -65
- data/spec/real_api/rephrase_text_spec.rb +0 -16
- data/spec/real_api/spoken_terms_spec.rb +0 -56
- data/spec/real_api/style_profiles_spec.rb +0 -46
- data/spec/real_api/style_rules_spec.rb +0 -46
- data/spec/real_api/translate_document_spec.rb +0 -18
- data/spec/real_api/translate_text_spec.rb +0 -16
- data/spec/real_api/translation_memories_spec.rb +0 -56
- data/spec/real_api/usage_spec.rb +0 -20
- data/spec/spec_helper.rb +0 -13
|
@@ -1,215 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
# The client has its own key and server, different from the module configuration, so a request
|
|
9
|
-
# that falls back to module state hits no stub.
|
|
10
|
-
describe 'DeepL::Client spoken terms' do
|
|
11
|
-
let(:client) { DeepL::Client.new('client-key', server_url: 'https://client.example.test') }
|
|
12
|
-
let(:collection_json) do
|
|
13
|
-
{ spoken_terms_id: 'st-1', name: 'terms', creation_time: '2026-10-23T17:15:53.434769Z',
|
|
14
|
-
term_lists: [{ lang: 'en', entry_count: 2 }] }
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def url(path)
|
|
18
|
-
"https://client.example.test#{path}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def json_headers
|
|
22
|
-
{ 'Authorization' => 'DeepL-Auth-Key client-key', 'Content-Type' => 'application/json' }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def no_body
|
|
26
|
-
->(body) { body.to_s.empty? }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def collection(json = collection_json)
|
|
30
|
-
stub_request(:get, url('/v3/spoken-terms/st-1')).to_return(reply(json))
|
|
31
|
-
client.get_spoken_terms('st-1')
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe '#create_spoken_terms' do
|
|
35
|
-
it 'sends the entries of each language joined by newlines' do
|
|
36
|
-
stub_request(:post, url('/v3/spoken-terms')).with(
|
|
37
|
-
body: { name: 'terms', term_lists: [{ lang: 'en', entries: "a\nb" }] },
|
|
38
|
-
headers: json_headers
|
|
39
|
-
).to_return(reply(collection_json, 201))
|
|
40
|
-
|
|
41
|
-
client.create_spoken_terms('terms', [DeepL::Resources::SpokenTermsEntries.new('en', %w[a b])])
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'accepts term lists given as hashes and sends the extra body parameters' do
|
|
45
|
-
stub_request(:post, url('/v3/spoken-terms'))
|
|
46
|
-
.with(body: { name: 'terms', term_lists: [{ lang: 'de', entries: 'x' }], beta: true })
|
|
47
|
-
.to_return(reply(collection_json, 201))
|
|
48
|
-
|
|
49
|
-
client.create_spoken_terms('terms', [{ lang: 'de', entries: ['x'] }],
|
|
50
|
-
extra_body_parameters: { beta: true })
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'parses the collection, including a creation time with microseconds' do
|
|
54
|
-
stub_request(:post, url('/v3/spoken-terms')).to_return(reply(collection_json, 201))
|
|
55
|
-
|
|
56
|
-
created = client.create_spoken_terms('terms', [])
|
|
57
|
-
|
|
58
|
-
expect(created.spoken_terms_id).to eq('st-1')
|
|
59
|
-
expect(created.creation_time)
|
|
60
|
-
.to eq(Time.utc(2026, 10, 23, 17, 15, Rational(53_434_769, 1_000_000)))
|
|
61
|
-
expect(created.term_lists.map { |l| [l.lang, l.entry_count] }).to eq([['en', 2]])
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
describe 'SpokenTerms#creation_time' do
|
|
66
|
-
it 'is nil for a malformed timestamp' do
|
|
67
|
-
expect(collection(collection_json.merge(creation_time: 'yesterday')).creation_time).to be_nil
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'reads a timestamp without an offset as UTC, not local time' do
|
|
71
|
-
original_tz = ENV.fetch('TZ', nil)
|
|
72
|
-
ENV['TZ'] = 'America/New_York'
|
|
73
|
-
expect(collection(collection_json.merge(creation_time: '2026-10-23T17:15:53')).creation_time)
|
|
74
|
-
.to eq(Time.utc(2026, 10, 23, 17, 15, 53))
|
|
75
|
-
ensure
|
|
76
|
-
ENV['TZ'] = original_tz
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe 'term check' do
|
|
81
|
-
it 'strips surrounding whitespace from each term before sending it' do
|
|
82
|
-
stub_request(:post, url('/v3/spoken-terms'))
|
|
83
|
-
.with(body: { name: 'terms', term_lists: [{ lang: 'en', entries: "API\nDeepL" }] })
|
|
84
|
-
.to_return(reply(collection_json, 201))
|
|
85
|
-
|
|
86
|
-
client.create_spoken_terms('terms', [{ lang: 'en', entries: [' API ', "DeepL\n"] }])
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
[["a\nb"], [' ']].each do |bad|
|
|
90
|
-
it "raises ValidationError for #{bad.inspect} and sends no request" do
|
|
91
|
-
expect { client.create_spoken_terms('terms', [{ lang: 'en', entries: bad }]) }
|
|
92
|
-
.to raise_error(DeepL::Exceptions::ValidationError)
|
|
93
|
-
expect { client.update_spoken_terms('st-1', term_lists: [{ lang: 'en', entries: bad }]) }
|
|
94
|
-
.to raise_error(DeepL::Exceptions::ValidationError)
|
|
95
|
-
expect { client.replace_spoken_terms_list('st-1', { lang: 'en', entries: bad }) }
|
|
96
|
-
.to raise_error(DeepL::Exceptions::ValidationError)
|
|
97
|
-
expect(a_request(:any, /.*/)).not_to have_been_made
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe '#list_spoken_terms and #get_spoken_terms' do
|
|
103
|
-
it 'send GET requests without a body' do
|
|
104
|
-
stub_request(:get, url('/v3/spoken-terms')).with(headers: json_headers, body: no_body)
|
|
105
|
-
.to_return(reply(spoken_terms: [collection_json]))
|
|
106
|
-
stub_request(:get, url('/v3/spoken-terms/st-1')).with(headers: json_headers, body: no_body)
|
|
107
|
-
.to_return(reply(collection_json))
|
|
108
|
-
|
|
109
|
-
expect(client.list_spoken_terms.map(&:spoken_terms_id)).to eq(['st-1'])
|
|
110
|
-
expect(client.get_spoken_terms('st-1').name).to eq('terms')
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
it 'turns a missing term_lists into an empty list' do
|
|
114
|
-
stub_request(:get, url('/v3/spoken-terms'))
|
|
115
|
-
.to_return(reply(spoken_terms: [collection_json.reject { |k, _| k == :term_lists }]))
|
|
116
|
-
|
|
117
|
-
expect(client.list_spoken_terms.map(&:term_lists)).to eq([[]])
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
describe '#update_spoken_terms' do
|
|
122
|
-
it 'sends only the given arguments' do
|
|
123
|
-
stub_request(:patch, url('/v3/spoken-terms/st-1'))
|
|
124
|
-
.with(body: { term_lists: [{ lang: 'en', entries: 'c' }] }, headers: json_headers)
|
|
125
|
-
.to_return(reply(collection_json))
|
|
126
|
-
stub_request(:patch, url('/v3/spoken-terms/st-1')).with(body: { name: 'new' })
|
|
127
|
-
.to_return(reply(collection_json))
|
|
128
|
-
|
|
129
|
-
client.update_spoken_terms('st-1', term_lists: [{ lang: 'en', entries: ['c'] }])
|
|
130
|
-
client.update_spoken_terms('st-1', name: 'new')
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
it 'sends the extra body parameters' do
|
|
134
|
-
stub_request(:patch, url('/v3/spoken-terms/st-1'))
|
|
135
|
-
.with(body: { name: 'new', beta: true }).to_return(reply(collection_json))
|
|
136
|
-
|
|
137
|
-
client.update_spoken_terms('st-1', name: 'new', extra_body_parameters: { beta: true })
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'sends an empty object when no argument is given' do
|
|
141
|
-
stub_request(:patch, url('/v3/spoken-terms/st-1')).with(body: '{}')
|
|
142
|
-
.to_return(reply(collection_json))
|
|
143
|
-
|
|
144
|
-
client.update_spoken_terms('st-1')
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
describe '#get_spoken_terms_entries' do
|
|
149
|
-
it 'sends the language in the query and splits the entries on newlines' do
|
|
150
|
-
stub_request(:get, url('/v3/spoken-terms/st-1/entries?lang=en'))
|
|
151
|
-
.with(headers: json_headers).to_return(reply(lang: 'en', entries: "a\nb\n"))
|
|
152
|
-
|
|
153
|
-
result = client.get_spoken_terms_entries('st-1', 'en')
|
|
154
|
-
|
|
155
|
-
expect([result.lang, result.entries]).to eq(['en', %w[a b]])
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
describe '#replace_spoken_terms_list' do
|
|
160
|
-
it 'takes a SpokenTermsEntries and a SpokenTerms object' do
|
|
161
|
-
stub_request(:put, url('/v3/spoken-terms/st-1/term-lists'))
|
|
162
|
-
.with(body: { lang: 'en', entries: "a\nb" }, headers: json_headers)
|
|
163
|
-
.to_return(reply(lang: 'en', entry_count: 2))
|
|
164
|
-
|
|
165
|
-
list = client.replace_spoken_terms_list(
|
|
166
|
-
collection, DeepL::Resources::SpokenTermsEntries.new('en', %w[a b])
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
expect([list.lang, list.entry_count]).to eq(['en', 2])
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
it 'takes a hash and sends the extra body parameters' do
|
|
173
|
-
stub_request(:put, url('/v3/spoken-terms/st-1/term-lists'))
|
|
174
|
-
.with(body: { lang: 'de', entries: 'x', beta: true })
|
|
175
|
-
.to_return(reply(lang: 'de', entry_count: 1))
|
|
176
|
-
|
|
177
|
-
client.replace_spoken_terms_list('st-1', { lang: 'de', entries: ['x'] },
|
|
178
|
-
extra_body_parameters: { beta: true })
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
describe '#delete_spoken_terms and #delete_spoken_terms_list' do
|
|
183
|
-
it 'send DELETE requests without a body and return nil' do
|
|
184
|
-
stub_request(:delete, url('/v3/spoken-terms/st-1/term-lists?lang=de'))
|
|
185
|
-
.with(headers: json_headers, body: no_body).to_return(status: 204)
|
|
186
|
-
stub_request(:delete, url('/v3/spoken-terms/st-1'))
|
|
187
|
-
.with(headers: json_headers, body: no_body).to_return(status: 204)
|
|
188
|
-
|
|
189
|
-
expect(client.delete_spoken_terms_list('st-1', 'de')).to be_nil
|
|
190
|
-
expect(client.delete_spoken_terms('st-1')).to be_nil
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
describe 'collection IDs' do
|
|
195
|
-
before do
|
|
196
|
-
encoded = url('/v3/spoken-terms/a%20b%2Fc')
|
|
197
|
-
stub_request(:get, encoded).to_return(reply(collection_json))
|
|
198
|
-
stub_request(:patch, encoded).to_return(reply(collection_json))
|
|
199
|
-
stub_request(:delete, encoded).to_return(status: 204)
|
|
200
|
-
stub_request(:get, "#{encoded}/entries?lang=en").to_return(reply(lang: 'en', entries: ''))
|
|
201
|
-
stub_request(:put, "#{encoded}/term-lists").to_return(reply(lang: 'en', entry_count: 0))
|
|
202
|
-
stub_request(:delete, "#{encoded}/term-lists?lang=en").to_return(status: 204)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
it 'are URL-encoded in every path' do
|
|
206
|
-
id = 'a b/c'
|
|
207
|
-
client.get_spoken_terms(id)
|
|
208
|
-
client.update_spoken_terms(id, name: 'x')
|
|
209
|
-
client.delete_spoken_terms(id)
|
|
210
|
-
client.get_spoken_terms_entries(id, 'en')
|
|
211
|
-
client.replace_spoken_terms_list(id, { lang: 'en', entries: ['x'] })
|
|
212
|
-
client.delete_spoken_terms_list(id, 'en')
|
|
213
|
-
end
|
|
214
|
-
end
|
|
215
|
-
end
|
|
@@ -1,266 +0,0 @@
|
|
|
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_relative 'offline_helper'
|
|
7
|
-
|
|
8
|
-
# The client has its own key and server, different from the module configuration, so a request
|
|
9
|
-
# that falls back to module state hits no stub.
|
|
10
|
-
describe 'DeepL::Client style profiles' do
|
|
11
|
-
let(:client) { DeepL::Client.new('client-key', server_url: 'https://client.example.test') }
|
|
12
|
-
let(:profile_id) { '3f1c9d0e-7a24-4b58-9c31-8f0e5d2a1b47' }
|
|
13
|
-
let(:profile_path) { "/v3/style_profiles/#{profile_id}" }
|
|
14
|
-
# The full example of the API specification.
|
|
15
|
-
let(:profile_json) do
|
|
16
|
-
{ style_profile_id: profile_id, name: 'Legal, German',
|
|
17
|
-
description: 'Contract wording for the German market.', industry: 'Legal',
|
|
18
|
-
glossary_ids: ['4d0a2e1c-6b93-4f7a-8d15-2c6e9a3b7f81'],
|
|
19
|
-
style_rule_ids: ['bd0a38f3-1831-440b-a8dd-2c702e2325ab'],
|
|
20
|
-
translation_memory_ids: ['a74d88fb-ed2a-4943-a664-a4512398b994'],
|
|
21
|
-
glossary_priority_order_enabled: true,
|
|
22
|
-
creation_time: '2026-04-01T16:34:25.223Z', updated_time: '2026-08-06T09:12:44.108Z' }
|
|
23
|
-
end
|
|
24
|
-
let(:bare_profile_json) do
|
|
25
|
-
{ style_profile_id: 'c58e2a71-90b4-4d6f-a2e3-71d5c8b4f902', name: 'Marketing, Japanese',
|
|
26
|
-
glossary_ids: [], style_rule_ids: [], translation_memory_ids: [],
|
|
27
|
-
glossary_priority_order_enabled: false,
|
|
28
|
-
creation_time: '2026-07-14T11:02:09.640Z', updated_time: '2026-07-14T11:02:09.640Z' }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def url(path)
|
|
32
|
-
"https://client.example.test#{path}"
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def json_headers
|
|
36
|
-
{ 'Authorization' => 'DeepL-Auth-Key client-key', 'Content-Type' => 'application/json' }
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def profile_object
|
|
40
|
-
DeepL::Resources::StyleProfile.new(profile_json.transform_keys(&:to_s), nil, nil)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def glossary
|
|
44
|
-
DeepL::Resources::Glossary.new({ 'glossary_id' => 'g1', 'name' => 'n' }, nil, nil)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def multilingual_glossary
|
|
48
|
-
DeepL::Resources::MultilingualGlossary.new({ 'glossary_id' => 'g3', 'name' => 'n' }, nil, nil)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def style_rule
|
|
52
|
-
DeepL::Resources::StyleRule.new({ 'style_id' => 's1', 'name' => 'n' }, nil, nil)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def translation_memory
|
|
56
|
-
DeepL::Resources::TranslationMemory.new({ 'translation_memory_id' => 't2', 'name' => 'n' },
|
|
57
|
-
nil, nil)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe '#list_style_profiles' do
|
|
61
|
-
it 'sends no query without paging options and returns the profiles as an array' do
|
|
62
|
-
list_json = { style_profiles: [profile_json, bare_profile_json], total_count: 2 }
|
|
63
|
-
stub_request(:get, url('/v3/style_profiles')).with(headers: json_headers)
|
|
64
|
-
.to_return(reply(list_json))
|
|
65
|
-
|
|
66
|
-
profiles = client.list_style_profiles
|
|
67
|
-
|
|
68
|
-
expect(profiles.map(&:name)).to eq(['Legal, German', 'Marketing, Japanese'])
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'sends page and page_size as query parameters' do
|
|
72
|
-
stub_request(:get, url('/v3/style_profiles?page=2&page_size=100'))
|
|
73
|
-
.to_return(reply(style_profiles: [], total_count: 0))
|
|
74
|
-
|
|
75
|
-
expect(client.list_style_profiles(page: 2, page_size: 100)).to eq([])
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'returns an empty array when style_profiles is missing' do
|
|
79
|
-
stub_request(:get, url('/v3/style_profiles')).to_return(reply(total_count: 0))
|
|
80
|
-
|
|
81
|
-
expect(client.list_style_profiles).to eq([])
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
describe '#create_style_profile' do
|
|
86
|
-
it 'sends only the name when no component is given' do
|
|
87
|
-
stub_request(:post, url('/v3/style_profiles'))
|
|
88
|
-
.with(body: { name: 'profile' }.to_json, headers: json_headers)
|
|
89
|
-
.to_return(reply(bare_profile_json, 201))
|
|
90
|
-
|
|
91
|
-
client.create_style_profile('profile')
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'sends every field, the ID arrays in order and the boolean as JSON true' do
|
|
95
|
-
body = { name: 'profile', description: 'd', industry: 'Legal',
|
|
96
|
-
glossary_ids: %w[g2 g1], style_rule_ids: %w[s1], translation_memory_ids: %w[t1],
|
|
97
|
-
glossary_priority_order_enabled: true }
|
|
98
|
-
stub_request(:post, url('/v3/style_profiles'))
|
|
99
|
-
.with { |request| JSON.parse(request.body) == JSON.parse(body.to_json) }
|
|
100
|
-
.to_return(reply(profile_json, 201))
|
|
101
|
-
|
|
102
|
-
client.create_style_profile('profile', description: 'd', industry: 'Legal',
|
|
103
|
-
glossary_ids: %w[g2 g1], style_rule_ids: %w[s1],
|
|
104
|
-
translation_memory_ids: %w[t1],
|
|
105
|
-
glossary_priority_order_enabled: true)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it 'sends the IDs of glossary, style rule and translation memory objects' do
|
|
109
|
-
body = { name: 'profile', glossary_ids: %w[g1 g2 g3], style_rule_ids: %w[s1 s2],
|
|
110
|
-
translation_memory_ids: %w[t1 t2] }
|
|
111
|
-
stub_request(:post, url('/v3/style_profiles')).with(body: body.to_json)
|
|
112
|
-
.to_return(reply(profile_json, 201))
|
|
113
|
-
|
|
114
|
-
client.create_style_profile('profile', glossary_ids: [glossary, 'g2', multilingual_glossary],
|
|
115
|
-
style_rule_ids: [style_rule, 's2'],
|
|
116
|
-
translation_memory_ids: ['t1', translation_memory])
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it 'applies extra body parameters' do
|
|
120
|
-
stub_request(:post, url('/v3/style_profiles'))
|
|
121
|
-
.with(body: { name: 'profile', beta: 'x' }.to_json)
|
|
122
|
-
.to_return(reply(bare_profile_json, 201))
|
|
123
|
-
|
|
124
|
-
client.create_style_profile('profile', extra_body_parameters: { beta: 'x' })
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
describe '#get_style_profile' do
|
|
129
|
-
it 'accepts an ID string or a style profile object' do
|
|
130
|
-
stub_request(:get, url(profile_path)).with(headers: json_headers)
|
|
131
|
-
.to_return(reply(profile_json)).times(2)
|
|
132
|
-
|
|
133
|
-
expect(client.get_style_profile(profile_id).style_profile_id).to eq(profile_id)
|
|
134
|
-
expect(client.get_style_profile(profile_object).style_profile_id).to eq(profile_id)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it 'escapes the ID in the path' do
|
|
138
|
-
stub_request(:get, url('/v3/style_profiles/a%2Fb%20c')).to_return(reply(profile_json))
|
|
139
|
-
|
|
140
|
-
client.get_style_profile('a/b c')
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it 'raises NotFound on 404' do
|
|
144
|
-
stub_request(:get, url(profile_path))
|
|
145
|
-
.to_return(reply({ message: 'Style profile not found' }, 404))
|
|
146
|
-
|
|
147
|
-
expect { client.get_style_profile(profile_id) }.to raise_error(DeepL::Exceptions::NotFound)
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe '#update_style_profile' do
|
|
152
|
-
it 'sends only the set fields, including an empty string and an empty array' do
|
|
153
|
-
stub_request(:patch, url(profile_path))
|
|
154
|
-
.with(body: { name: 'new', description: '', style_rule_ids: [] }.to_json,
|
|
155
|
-
headers: json_headers)
|
|
156
|
-
.to_return(reply(profile_json))
|
|
157
|
-
|
|
158
|
-
client.update_style_profile(profile_id, name: 'new', description: '', style_rule_ids: [])
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
it 'sends an empty object when nothing is set, also for a style profile object' do
|
|
162
|
-
stub_request(:patch, url(profile_path)).with(body: '{}').to_return(reply(profile_json))
|
|
163
|
-
.times(2)
|
|
164
|
-
|
|
165
|
-
client.update_style_profile(profile_id)
|
|
166
|
-
client.update_style_profile(profile_object)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it 'sends the IDs of component objects' do
|
|
170
|
-
body = { glossary_ids: %w[g1 g3], style_rule_ids: %w[s1], translation_memory_ids: %w[t2] }
|
|
171
|
-
stub_request(:patch, url(profile_path)).with(body: body.to_json)
|
|
172
|
-
.to_return(reply(profile_json))
|
|
173
|
-
|
|
174
|
-
client.update_style_profile(profile_id, glossary_ids: [glossary, multilingual_glossary],
|
|
175
|
-
style_rule_ids: [style_rule],
|
|
176
|
-
translation_memory_ids: [translation_memory])
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it 'sends glossary_priority_order_enabled false as JSON false' do
|
|
180
|
-
stub_request(:patch, url(profile_path))
|
|
181
|
-
.with(body: { glossary_priority_order_enabled: false }.to_json)
|
|
182
|
-
.to_return(reply(profile_json))
|
|
183
|
-
|
|
184
|
-
client.update_style_profile(profile_id, glossary_priority_order_enabled: false)
|
|
185
|
-
end
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
describe '#delete_style_profile' do
|
|
189
|
-
it 'sends DELETE for an ID string or a style profile object and returns nil' do
|
|
190
|
-
stub_request(:delete, url(profile_path)).with(headers: json_headers)
|
|
191
|
-
.to_return(status: 204).times(2)
|
|
192
|
-
|
|
193
|
-
expect(client.delete_style_profile(profile_id)).to be_nil
|
|
194
|
-
expect(client.delete_style_profile(profile_object)).to be_nil
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
describe 'empty ID' do
|
|
199
|
-
it 'raises ArgumentError and sends no request' do
|
|
200
|
-
['', nil].each do |id|
|
|
201
|
-
expect { client.get_style_profile(id) }.to raise_error(ArgumentError)
|
|
202
|
-
expect { client.update_style_profile(id, name: 'x') }.to raise_error(ArgumentError)
|
|
203
|
-
expect { client.delete_style_profile(id) }.to raise_error(ArgumentError)
|
|
204
|
-
end
|
|
205
|
-
expect(a_request(:any, /.*/)).not_to have_been_made
|
|
206
|
-
end
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
describe 'parsing' do
|
|
210
|
-
it 'parses every field of the specification example' do
|
|
211
|
-
stub_request(:get, url(profile_path)).to_return(reply(profile_json))
|
|
212
|
-
|
|
213
|
-
times = { creation_time: Time.utc(2026, 4, 1, 16, 34, Rational(25_223, 1000)),
|
|
214
|
-
updated_time: Time.utc(2026, 8, 6, 9, 12, Rational(44_108, 1000)) }
|
|
215
|
-
expected = profile_json.merge(times)
|
|
216
|
-
expect(client.get_style_profile(profile_id)).to have_attributes(expected)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it 'parses a profile without description and industry, and ignores unknown fields' do
|
|
220
|
-
stub_request(:get, url(profile_path)).to_return(
|
|
221
|
-
reply(bare_profile_json.merge(example_document_ids: ['e1'], spoken_terms_ids: ['s1']))
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
profile = client.get_style_profile(profile_id)
|
|
225
|
-
|
|
226
|
-
expect(profile.description).to be_nil
|
|
227
|
-
expect(profile.industry).to be_nil
|
|
228
|
-
expect(profile.glossary_priority_order_enabled).to be(false)
|
|
229
|
-
expect(profile).not_to respond_to(:example_document_ids)
|
|
230
|
-
expect(profile).not_to respond_to(:spoken_terms_ids)
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
it 'parses a timestamp with 7 fractional digits' do
|
|
234
|
-
stub_request(:get, url(profile_path))
|
|
235
|
-
.to_return(reply(bare_profile_json.merge(creation_time: '2026-10-26T16:27:10.2982869Z')))
|
|
236
|
-
|
|
237
|
-
expect(client.get_style_profile(profile_id).creation_time)
|
|
238
|
-
.to eq(Time.utc(2026, 10, 26, 16, 27, Rational(102_982_869, 10_000_000)))
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
it 'defaults missing ID lists and the boolean' do
|
|
242
|
-
stub_request(:get, url(profile_path))
|
|
243
|
-
.to_return(reply(style_profile_id: profile_id, name: 'n', glossary_ids: nil))
|
|
244
|
-
|
|
245
|
-
profile = client.get_style_profile(profile_id)
|
|
246
|
-
|
|
247
|
-
expect([profile.glossary_ids, profile.style_rule_ids, profile.translation_memory_ids])
|
|
248
|
-
.to eq([[], [], []])
|
|
249
|
-
expect(profile.glossary_priority_order_enabled).to be(false)
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it 'turns malformed values into nil or skips them without failing the call' do
|
|
253
|
-
stub_request(:get, url(profile_path)).to_return(
|
|
254
|
-
reply(profile_json.merge(creation_time: 'not a timestamp', glossary_ids: ['g1', 7, nil]))
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
profile = client.get_style_profile(profile_id)
|
|
258
|
-
|
|
259
|
-
expect(profile.creation_time).to be_nil
|
|
260
|
-
expect(profile.glossary_ids).to eq(['g1'])
|
|
261
|
-
expect(profile.name).to eq('Legal, German')
|
|
262
|
-
expect(profile.style_rule_ids).to eq(['bd0a38f3-1831-440b-a8dd-2c702e2325ab'])
|
|
263
|
-
expect(profile.updated_time).to eq(Time.utc(2026, 8, 6, 9, 12, Rational(44_108, 1000)))
|
|
264
|
-
end
|
|
265
|
-
end
|
|
266
|
-
end
|