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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac9df781efec35e22812fb7d998386c19dd2f51afeb020d1850c4b2091e5ba20
|
|
4
|
+
data.tar.gz: 70db2ae1bd08aa8e1dffb01198225ad29fc5c2514cf4f1a38da948bbe97c51f3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c55b0eb6a6ef528eb14f78acfb89591fa99de7c7d8a82fb322e5b189c6663ff5f5f915d46ac4e93fcebc5a1d1f71bcef3d94fb1cac36d5e5fcabec9eb656cb5
|
|
7
|
+
data.tar.gz: a606b2405448a3598faf0d38e51830437d14019ab6b2cec4a794f93bc47f8329612fc524b1f2d5c71e48063ef4682a12831cada04d8b5c2a9f8ffd1f2012c3e6
|
data/.gitlab-ci.yml
CHANGED
|
@@ -57,6 +57,8 @@ package:
|
|
|
57
57
|
image:
|
|
58
58
|
name: ruby:2.7
|
|
59
59
|
entrypoint: ['/builds/deepl/backend/oss-client-libs/deepl-ruby']
|
|
60
|
+
variables:
|
|
61
|
+
HOME: /tmp
|
|
60
62
|
script: bundle exec rubocop
|
|
61
63
|
|
|
62
64
|
rubocop_scheduled:
|
|
@@ -167,6 +169,9 @@ test_manual:
|
|
|
167
169
|
|
|
168
170
|
gitlab release:
|
|
169
171
|
stage: publish
|
|
172
|
+
image: registry.gitlab.com/gitlab-org/release-cli:latest
|
|
170
173
|
extends: .create_gitlab_release
|
|
174
|
+
before_script:
|
|
175
|
+
- echo "overriding default before_script..."
|
|
171
176
|
rules:
|
|
172
177
|
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
|
data/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.7.0] - 2026-05-14
|
|
10
|
+
### Added
|
|
11
|
+
- Added support for listing translation memories via `DeepL.translation_memories.list`.
|
|
12
|
+
- Added `translation_memory` and `translation_memory_threshold` parameters to `translate()`
|
|
13
|
+
to use a translation memory during text translation. The `translation_memory` parameter
|
|
14
|
+
accepts a string ID or a `TranslationMemory` object.
|
|
15
|
+
- Added support for style rules CRUD operations via `DeepL.style_rules`:
|
|
16
|
+
`create()`, `find()`, `update_name()`, `update_configured_rules()`, and `destroy()`.
|
|
17
|
+
- Added support for style rule custom instruction CRUD operations via `DeepL.style_rules`:
|
|
18
|
+
`create_custom_instruction()`, `find_custom_instruction()`,
|
|
19
|
+
`update_custom_instruction()`, and `destroy_custom_instruction()`.
|
|
20
|
+
Please refer to the README for usage instructions.
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
- Updated unit test to expect the `model_type_used` to now be `quality_optimized`
|
|
24
|
+
- Set explicit `image` for `gitlab release` CI job to avoid missing `$HOME` issues
|
|
25
|
+
|
|
9
26
|
## [3.6.1] - 2025-12-19
|
|
10
27
|
### Fixed
|
|
11
28
|
- Fixed broken 3.6.0 release
|
|
@@ -102,7 +119,8 @@ The change in major version is only due to the change in maintainership, there i
|
|
|
102
119
|
### Fixed
|
|
103
120
|
- Make RequestEntityTooLarge error message more clear
|
|
104
121
|
|
|
105
|
-
[Unreleased]: https://github.com/DeepLcom/deepl-rb/compare/v3.
|
|
122
|
+
[Unreleased]: https://github.com/DeepLcom/deepl-rb/compare/v3.7.0...HEAD
|
|
123
|
+
[3.7.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.6.1...v3.7.0
|
|
106
124
|
[3.6.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.6.0...v3.6.1
|
|
107
125
|
[3.6.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.5.1...v3.6.0
|
|
108
126
|
[3.5.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.5.0...v3.5.1
|
data/README.md
CHANGED
|
@@ -191,8 +191,9 @@ The following parameters will be automatically converted:
|
|
|
191
191
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
|
192
192
|
| `formality` | No conversion applied
|
|
193
193
|
| `glossary_id` | No conversion applied
|
|
194
|
-
| `style_id` | No conversion applied
|
|
195
194
|
| `style_rule` | No conversion applied (can be a string ID or a StyleRule object)
|
|
195
|
+
| `translation_memory` | No conversion applied (can be a string ID or a TranslationMemory object)
|
|
196
|
+
| `translation_memory_threshold` | No conversion applied (integer 0-100, recommended minimum 75)
|
|
196
197
|
| `context` | No conversion applied
|
|
197
198
|
| `custom_instructions` | No conversion applied
|
|
198
199
|
| `tag_handling_version` | No conversion applied
|
|
@@ -329,28 +330,52 @@ Style rules allow you to customize your translations using a managed, shared lis
|
|
|
329
330
|
of rules for style, formatting, and more. Multiple style rules can be stored with
|
|
330
331
|
your account, each with a user-specified name and a uniquely-assigned ID.
|
|
331
332
|
|
|
332
|
-
#### Creating
|
|
333
|
+
#### Creating a style rule
|
|
333
334
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
come shortly.
|
|
335
|
+
Use `create` to create a new style rule with a name and language code. You can
|
|
336
|
+
optionally provide `configured_rules` and `custom_instructions`.
|
|
337
337
|
|
|
338
|
-
|
|
338
|
+
```rb
|
|
339
|
+
# Simple creation with just a name and language
|
|
340
|
+
style_rule = DeepL.style_rules.create('My Style Rule', 'en')
|
|
341
|
+
puts "Created: #{style_rule.name} (#{style_rule.style_id})"
|
|
342
|
+
|
|
343
|
+
# Creation with configured rules and custom instructions
|
|
344
|
+
style_rule = DeepL.style_rules.create(
|
|
345
|
+
'Formal English',
|
|
346
|
+
'en',
|
|
347
|
+
configured_rules: { style_and_tone: { formality: 'formal' } },
|
|
348
|
+
custom_instructions: [{ label: 'Tone', prompt: 'Always use formal language' }]
|
|
349
|
+
)
|
|
350
|
+
```
|
|
339
351
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
352
|
+
#### Retrieving and listing style rules
|
|
353
|
+
|
|
354
|
+
Use `find` to retrieve a single style rule by ID, or `list` to list all style
|
|
355
|
+
rules.
|
|
356
|
+
|
|
357
|
+
`list` returns a list of `StyleRule` objects corresponding to all of your stored
|
|
358
|
+
style rules. The method accepts optional parameters: `page` (page number for
|
|
359
|
+
pagination, 0-indexed), `page_size` (number of items per page), and `detailed`.
|
|
360
|
+
When `true`, the response includes `configured_rules` and `custom_instructions`
|
|
361
|
+
for each style rule. When `false` (default), these fields are omitted for faster
|
|
362
|
+
responses.
|
|
345
363
|
|
|
346
364
|
```rb
|
|
347
|
-
# Get
|
|
365
|
+
# Get a single style rule by ID
|
|
366
|
+
style_rule = DeepL.style_rules.find('YOUR_STYLE_ID')
|
|
367
|
+
puts "#{style_rule.name} (#{style_rule.language})"
|
|
368
|
+
|
|
369
|
+
# List all style rules
|
|
348
370
|
style_rules = DeepL.style_rules.list
|
|
349
371
|
style_rules.each do |rule|
|
|
350
372
|
puts "#{rule.name} (#{rule.style_id})"
|
|
351
373
|
end
|
|
352
374
|
|
|
353
|
-
#
|
|
375
|
+
# List with pagination
|
|
376
|
+
style_rules = DeepL.style_rules.list(page: 0, page_size: 10)
|
|
377
|
+
|
|
378
|
+
# List with detailed configuration
|
|
354
379
|
style_rules = DeepL.style_rules.list(detailed: true)
|
|
355
380
|
style_rules.each do |rule|
|
|
356
381
|
if rule.configured_rules
|
|
@@ -359,24 +384,130 @@ style_rules.each do |rule|
|
|
|
359
384
|
end
|
|
360
385
|
```
|
|
361
386
|
|
|
362
|
-
|
|
387
|
+
#### Updating a style rule
|
|
388
|
+
|
|
389
|
+
Use `update_name` to rename a style rule, and `update_configured_rules` to
|
|
390
|
+
update its configured rules.
|
|
363
391
|
|
|
364
392
|
```rb
|
|
365
|
-
|
|
393
|
+
# Update the name
|
|
394
|
+
updated = DeepL.style_rules.update_name('YOUR_STYLE_ID', 'New Name')
|
|
366
395
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
396
|
+
# Update configured rules
|
|
397
|
+
updated = DeepL.style_rules.update_configured_rules(
|
|
398
|
+
'YOUR_STYLE_ID',
|
|
399
|
+
{ style_and_tone: { formality: 'formal' } }
|
|
400
|
+
)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
The `configured_rules` hash supports the following categories: `dates_and_times`,
|
|
404
|
+
`formatting`, `numbers`, `punctuation`, `spelling_and_grammar`, `style_and_tone`,
|
|
405
|
+
and `vocabulary`.
|
|
406
|
+
|
|
407
|
+
#### Managing custom instructions
|
|
408
|
+
|
|
409
|
+
Custom instructions allow you to add free-text prompts to a style rule. Each
|
|
410
|
+
instruction has an `id`, `label`, `prompt`, and `source_language`. Use
|
|
411
|
+
`create_custom_instruction`, `find_custom_instruction`,
|
|
412
|
+
`update_custom_instruction`, and `destroy_custom_instruction` to manage them.
|
|
413
|
+
|
|
414
|
+
```rb
|
|
415
|
+
# Create a custom instruction
|
|
416
|
+
instruction = DeepL.style_rules.create_custom_instruction(
|
|
417
|
+
'YOUR_STYLE_ID', 'Formal tone', 'Always use formal language'
|
|
418
|
+
)
|
|
419
|
+
puts "Created instruction: #{instruction.id}"
|
|
420
|
+
|
|
421
|
+
# Create with an optional source language
|
|
422
|
+
instruction = DeepL.style_rules.create_custom_instruction(
|
|
423
|
+
'YOUR_STYLE_ID', 'Formal tone', 'Always use formal language', 'en'
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
# Get a custom instruction
|
|
427
|
+
instruction = DeepL.style_rules.find_custom_instruction('YOUR_STYLE_ID', instruction.id)
|
|
428
|
+
|
|
429
|
+
# Update a custom instruction
|
|
430
|
+
updated = DeepL.style_rules.update_custom_instruction(
|
|
431
|
+
'YOUR_STYLE_ID', instruction.id, 'Updated label', 'Use very formal language'
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
# Delete a custom instruction
|
|
435
|
+
DeepL.style_rules.destroy_custom_instruction('YOUR_STYLE_ID', instruction.id)
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
#### Deleting a style rule
|
|
439
|
+
|
|
440
|
+
Use `destroy` to delete a style rule by ID.
|
|
441
|
+
|
|
442
|
+
```rb
|
|
443
|
+
DeepL.style_rules.destroy('YOUR_STYLE_ID')
|
|
371
444
|
```
|
|
372
445
|
|
|
373
|
-
|
|
446
|
+
#### Using style rules in translations
|
|
447
|
+
|
|
448
|
+
Style rules can be used in the `translate` method by specifying the `style_rule` option
|
|
449
|
+
with either a style rule ID string or a `StyleRule` object:
|
|
374
450
|
|
|
375
451
|
```rb
|
|
452
|
+
# Using a style rule ID
|
|
453
|
+
translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4'
|
|
454
|
+
|
|
455
|
+
# Or using a StyleRule object
|
|
376
456
|
style_rules = DeepL.style_rules.list
|
|
377
|
-
|
|
457
|
+
translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: style_rules.first
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### Translation Memories
|
|
461
|
+
|
|
462
|
+
Translation memories allow you to store and reuse previously created translations.
|
|
463
|
+
They can be used in text translation requests to improve consistency by matching
|
|
464
|
+
against stored segments. Multiple translation memories can be stored with your
|
|
465
|
+
account, each with a source language and one or more target languages.
|
|
466
|
+
|
|
467
|
+
#### Uploading and managing translation memories
|
|
468
|
+
|
|
469
|
+
Currently translation memories must be uploaded and managed in the DeepL UI via
|
|
470
|
+
https://www.deepl.com/translation-memory. Full translation memory management via
|
|
471
|
+
the API will come shortly.
|
|
472
|
+
|
|
473
|
+
#### Listing translation memories
|
|
474
|
+
|
|
475
|
+
`translation_memories.list` returns a list of `TranslationMemory` objects
|
|
476
|
+
for your stored translation memories. The method accepts optional parameters:
|
|
477
|
+
`page` (page number for pagination, 0-indexed) and `page_size` (number of items
|
|
478
|
+
per page, max 25).
|
|
378
479
|
|
|
379
|
-
|
|
480
|
+
```rb
|
|
481
|
+
# List translation memories
|
|
482
|
+
translation_memories = DeepL.translation_memories.list
|
|
483
|
+
translation_memories.each do |tm|
|
|
484
|
+
puts "#{tm.name} (#{tm.translation_memory_id})"
|
|
485
|
+
puts " Source: #{tm.source_language}, Targets: #{tm.target_languages.join(', ')}"
|
|
486
|
+
puts " Segments: #{tm.segment_count}"
|
|
487
|
+
end
|
|
488
|
+
|
|
489
|
+
# List with pagination
|
|
490
|
+
translation_memories = DeepL.translation_memories.list(page: 0, page_size: 10)
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
#### Using a translation memory in translations
|
|
494
|
+
|
|
495
|
+
Pass the `translation_memory` parameter to `translate` to use a translation
|
|
496
|
+
memory. You can pass either a string containing the translation memory ID, or a
|
|
497
|
+
`TranslationMemory` object. Use `translation_memory_threshold` to control the
|
|
498
|
+
minimum matching percentage for fuzzy matches (0-100, recommended minimum of
|
|
499
|
+
75%).
|
|
500
|
+
|
|
501
|
+
```rb
|
|
502
|
+
# Using a translation memory ID
|
|
503
|
+
translation = DeepL.translate 'Hello, world!', 'EN', 'DE',
|
|
504
|
+
translation_memory: 'YOUR_TM_ID',
|
|
505
|
+
translation_memory_threshold: 80
|
|
506
|
+
|
|
507
|
+
# Or using a TranslationMemory object
|
|
508
|
+
translation_memories = DeepL.translation_memories.list
|
|
509
|
+
translation = DeepL.translate 'Hello, world!', 'EN', 'DE',
|
|
510
|
+
translation_memory: translation_memories.first
|
|
380
511
|
```
|
|
381
512
|
|
|
382
513
|
### Monitor usage
|
data/Rakefile
CHANGED
|
@@ -33,6 +33,8 @@ Juwelier::Tasks.new do |gem|
|
|
|
33
33
|
'documentation_uri' => 'https://github.com/DeepLcom/deepl-rb/blob/main/README.md',
|
|
34
34
|
'homepage_uri' => 'https://github.com/DeepLcom/deepl-rb'
|
|
35
35
|
}
|
|
36
|
+
gem.files.exclude '.bumpversion.toml'
|
|
37
|
+
gem.files.exclude '.devcontainer/**/*'
|
|
36
38
|
gem.files.exclude '.github'
|
|
37
39
|
gem.files.exclude '.circleci'
|
|
38
40
|
gem.files.exclude 'catalog-info.yaml'
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
3.
|
|
1
|
+
3.7.0
|
data/deepl-rb.gemspec
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: deepl-rb 3.
|
|
5
|
+
# stub: deepl-rb 3.7.0 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "deepl-rb".freeze
|
|
9
|
-
s.version = "3.
|
|
9
|
+
s.version = "3.7.0"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.metadata = { "bug_tracker_uri" => "https://github.com/DeepLcom/deepl-rb/issues", "changelog_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md", "documentation_uri" => "https://github.com/DeepLcom/deepl-rb/blob/main/README.md", "homepage_uri" => "https://github.com/DeepLcom/deepl-rb" } if s.respond_to? :metadata=
|
|
13
13
|
s.require_paths = ["lib".freeze]
|
|
14
14
|
s.authors = ["DeepL SE".freeze]
|
|
15
|
-
s.date = "
|
|
15
|
+
s.date = "2026-05-14"
|
|
16
16
|
s.description = "Official Ruby library for the DeepL language translation API (v2). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
|
|
17
17
|
s.email = "open-source@deepl.com".freeze
|
|
18
18
|
s.extra_rdoc_files = [
|
|
@@ -71,8 +71,18 @@ Gem::Specification.new do |s|
|
|
|
71
71
|
"lib/deepl/requests/glossary/list.rb",
|
|
72
72
|
"lib/deepl/requests/languages.rb",
|
|
73
73
|
"lib/deepl/requests/rephrase.rb",
|
|
74
|
+
"lib/deepl/requests/style_rule/create.rb",
|
|
75
|
+
"lib/deepl/requests/style_rule/create_custom_instruction.rb",
|
|
76
|
+
"lib/deepl/requests/style_rule/destroy.rb",
|
|
77
|
+
"lib/deepl/requests/style_rule/destroy_custom_instruction.rb",
|
|
78
|
+
"lib/deepl/requests/style_rule/find.rb",
|
|
79
|
+
"lib/deepl/requests/style_rule/find_custom_instruction.rb",
|
|
74
80
|
"lib/deepl/requests/style_rule/list.rb",
|
|
81
|
+
"lib/deepl/requests/style_rule/update.rb",
|
|
82
|
+
"lib/deepl/requests/style_rule/update_configured_rules.rb",
|
|
83
|
+
"lib/deepl/requests/style_rule/update_custom_instruction.rb",
|
|
75
84
|
"lib/deepl/requests/translate.rb",
|
|
85
|
+
"lib/deepl/requests/translation_memory/list.rb",
|
|
76
86
|
"lib/deepl/requests/usage.rb",
|
|
77
87
|
"lib/deepl/resources/base.rb",
|
|
78
88
|
"lib/deepl/resources/document_handle.rb",
|
|
@@ -82,8 +92,10 @@ Gem::Specification.new do |s|
|
|
|
82
92
|
"lib/deepl/resources/language_pair.rb",
|
|
83
93
|
"lib/deepl/resources/style_rule.rb",
|
|
84
94
|
"lib/deepl/resources/text.rb",
|
|
95
|
+
"lib/deepl/resources/translation_memory.rb",
|
|
85
96
|
"lib/deepl/resources/usage.rb",
|
|
86
97
|
"lib/deepl/style_rule_api.rb",
|
|
98
|
+
"lib/deepl/translation_memory_api.rb",
|
|
87
99
|
"lib/deepl/utils/backoff_timer.rb",
|
|
88
100
|
"lib/deepl/utils/exception_builder.rb",
|
|
89
101
|
"lib/http_client_options.rb",
|
|
@@ -104,11 +116,14 @@ Gem::Specification.new do |s|
|
|
|
104
116
|
"spec/fixtures/vcr_cassettes/languages.yml",
|
|
105
117
|
"spec/fixtures/vcr_cassettes/rephrase_texts.yml",
|
|
106
118
|
"spec/fixtures/vcr_cassettes/style_rules.yml",
|
|
119
|
+
"spec/fixtures/vcr_cassettes/style_rules_crud.yml",
|
|
107
120
|
"spec/fixtures/vcr_cassettes/translate_texts.yml",
|
|
121
|
+
"spec/fixtures/vcr_cassettes/translation_memories.yml",
|
|
108
122
|
"spec/fixtures/vcr_cassettes/usage.yml",
|
|
109
123
|
"spec/integration_tests/document_api_spec.rb",
|
|
110
124
|
"spec/integration_tests/integration_test_utils.rb",
|
|
111
125
|
"spec/integration_tests/style_rule_api_spec.rb",
|
|
126
|
+
"spec/integration_tests/translation_memory_api_spec.rb",
|
|
112
127
|
"spec/requests/extra_body_parameters_types_spec.rb",
|
|
113
128
|
"spec/requests/glossary/create_spec.rb",
|
|
114
129
|
"spec/requests/glossary/destroy_spec.rb",
|
|
@@ -118,18 +133,30 @@ Gem::Specification.new do |s|
|
|
|
118
133
|
"spec/requests/glossary/list_spec.rb",
|
|
119
134
|
"spec/requests/languages_spec.rb",
|
|
120
135
|
"spec/requests/rephrase_spec.rb",
|
|
136
|
+
"spec/requests/style_rule/create_custom_instruction_spec.rb",
|
|
137
|
+
"spec/requests/style_rule/create_spec.rb",
|
|
138
|
+
"spec/requests/style_rule/destroy_custom_instruction_spec.rb",
|
|
139
|
+
"spec/requests/style_rule/destroy_spec.rb",
|
|
140
|
+
"spec/requests/style_rule/find_custom_instruction_spec.rb",
|
|
141
|
+
"spec/requests/style_rule/find_spec.rb",
|
|
142
|
+
"spec/requests/style_rule/list_spec.rb",
|
|
143
|
+
"spec/requests/style_rule/update_configured_rules_spec.rb",
|
|
144
|
+
"spec/requests/style_rule/update_custom_instruction_spec.rb",
|
|
145
|
+
"spec/requests/style_rule/update_spec.rb",
|
|
121
146
|
"spec/requests/translate_spec.rb",
|
|
147
|
+
"spec/requests/translation_memory/list_spec.rb",
|
|
122
148
|
"spec/requests/usage_spec.rb",
|
|
123
149
|
"spec/resources/glossary_spec.rb",
|
|
124
150
|
"spec/resources/language_pair_spec.rb",
|
|
125
151
|
"spec/resources/language_spec.rb",
|
|
126
152
|
"spec/resources/text_spec.rb",
|
|
153
|
+
"spec/resources/translation_memory_spec.rb",
|
|
127
154
|
"spec/resources/usage_spec.rb",
|
|
128
155
|
"spec/spec_helper.rb"
|
|
129
156
|
]
|
|
130
157
|
s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
|
|
131
158
|
s.licenses = ["MIT".freeze]
|
|
132
|
-
s.rubygems_version = "3.4.
|
|
159
|
+
s.rubygems_version = "3.4.10".freeze
|
|
133
160
|
s.summary = "Official Ruby library for the DeepL language translation API.".freeze
|
|
134
161
|
|
|
135
162
|
s.specification_version = 4
|
data/lib/deepl/requests/base.rb
CHANGED
|
@@ -143,6 +143,22 @@ module DeepL
|
|
|
143
143
|
get_req
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
+
def patch_request(payload)
|
|
147
|
+
apply_extra_body_parameters_to_json(payload)
|
|
148
|
+
http_headers = add_json_content_type(headers)
|
|
149
|
+
req = Net::HTTP::Patch.new(uri.path, http_headers)
|
|
150
|
+
req.body = payload.merge(options_without_extra_params).to_json
|
|
151
|
+
req
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def put_request(payload)
|
|
155
|
+
apply_extra_body_parameters_to_json(payload)
|
|
156
|
+
http_headers = add_json_content_type(headers)
|
|
157
|
+
req = Net::HTTP::Put.new(uri.path, http_headers)
|
|
158
|
+
req.body = payload.merge(options_without_extra_params).to_json
|
|
159
|
+
req
|
|
160
|
+
end
|
|
161
|
+
|
|
146
162
|
def delete_request
|
|
147
163
|
http_headers = add_json_content_type(headers)
|
|
148
164
|
del_req = Net::HTTP::Delete.new(uri.path, http_headers)
|
|
@@ -21,11 +21,12 @@ module DeepL
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def request
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
File.open(input_file_path, 'rb') do |input_file|
|
|
25
|
+
form_data = build_base_form_data(input_file)
|
|
26
|
+
apply_extra_body_parameters_to_form(form_data)
|
|
27
|
+
build_doc_handle(*execute_request_with_retries(post_request_with_file(form_data),
|
|
28
|
+
[input_file]))
|
|
29
|
+
end
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def details
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Requests
|
|
8
|
+
module StyleRule
|
|
9
|
+
class Create < Base
|
|
10
|
+
def initialize(api, name, language, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@name = name
|
|
13
|
+
@language = language
|
|
14
|
+
@configured_rules = delete_option(:configured_rules)
|
|
15
|
+
@custom_instructions = delete_option(:custom_instructions)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def request
|
|
19
|
+
payload = { name: @name, language: @language }
|
|
20
|
+
payload[:configured_rules] = @configured_rules if @configured_rules
|
|
21
|
+
payload[:custom_instructions] = @custom_instructions if @custom_instructions
|
|
22
|
+
build_style_rule(*execute_request_with_retries(post_request(payload)))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_s
|
|
26
|
+
"POST #{uri.request_uri}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def build_style_rule(request, response)
|
|
32
|
+
data = JSON.parse(response.body)
|
|
33
|
+
DeepL::Resources::StyleRule.new(data, request, response)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def uri
|
|
37
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def path
|
|
41
|
+
'style_rules'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
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
|
+
module DeepL
|
|
7
|
+
module Requests
|
|
8
|
+
module StyleRule
|
|
9
|
+
class CreateCustomInstruction < Base
|
|
10
|
+
def initialize(api, style_id, label, prompt, source_language = nil, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
@label = label
|
|
14
|
+
@prompt = prompt
|
|
15
|
+
@source_language = source_language
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def request
|
|
19
|
+
payload = { label: @label, prompt: @prompt }
|
|
20
|
+
payload[:source_language] = @source_language if @source_language
|
|
21
|
+
build_custom_instruction(*execute_request_with_retries(post_request(payload)))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s
|
|
25
|
+
"POST #{uri.request_uri}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def build_custom_instruction(_request, response)
|
|
31
|
+
data = JSON.parse(response.body)
|
|
32
|
+
DeepL::Resources::CustomInstruction.new(data)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def uri
|
|
36
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def path
|
|
40
|
+
"style_rules/#{@style_id}/custom_instructions"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Requests
|
|
8
|
+
module StyleRule
|
|
9
|
+
class Destroy < Base
|
|
10
|
+
def initialize(api, style_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def request
|
|
16
|
+
build_response(*execute_request_with_retries(delete_request))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"DELETE #{uri.request_uri}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def build_response(_, _)
|
|
26
|
+
@style_id
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def uri
|
|
30
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def path
|
|
34
|
+
"style_rules/#{@style_id}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Requests
|
|
8
|
+
module StyleRule
|
|
9
|
+
class DestroyCustomInstruction < Base
|
|
10
|
+
def initialize(api, style_id, instruction_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
@instruction_id = instruction_id
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def request
|
|
17
|
+
build_response(*execute_request_with_retries(delete_request))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_s
|
|
21
|
+
"DELETE #{uri.request_uri}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def build_response(_, _)
|
|
27
|
+
@instruction_id
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uri
|
|
31
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def path
|
|
35
|
+
"style_rules/#{@style_id}/custom_instructions/#{@instruction_id}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
module DeepL
|
|
7
|
+
module Requests
|
|
8
|
+
module StyleRule
|
|
9
|
+
class Find < Base
|
|
10
|
+
def initialize(api, style_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def request
|
|
16
|
+
build_style_rule(*execute_request_with_retries(get_request))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"GET #{uri.request_uri}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def build_style_rule(request, response)
|
|
26
|
+
data = JSON.parse(response.body)
|
|
27
|
+
DeepL::Resources::StyleRule.new(data, request, response)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uri
|
|
31
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def path
|
|
35
|
+
"style_rules/#{@style_id}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|