deepl-rb 3.6.1 → 3.8.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/.gitlab-ci.yml +8 -1
  3. data/CHANGELOG.md +35 -1
  4. data/Gemfile +0 -2
  5. data/README.md +165 -34
  6. data/Rakefile +2 -0
  7. data/VERSION +1 -1
  8. data/deepl-rb.gemspec +52 -20
  9. data/lib/deepl/requests/base.rb +16 -0
  10. data/lib/deepl/requests/document/upload.rb +6 -5
  11. data/lib/deepl/requests/rephrase.rb +3 -2
  12. data/lib/deepl/requests/style_rule/create.rb +46 -0
  13. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +45 -0
  14. data/lib/deepl/requests/style_rule/destroy.rb +39 -0
  15. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +40 -0
  16. data/lib/deepl/requests/style_rule/find.rb +40 -0
  17. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +41 -0
  18. data/lib/deepl/requests/style_rule/update.rb +42 -0
  19. data/lib/deepl/requests/style_rule/update_configured_rules.rb +41 -0
  20. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +47 -0
  21. data/lib/deepl/requests/translate.rb +17 -4
  22. data/lib/deepl/requests/translation_memory/list.rb +58 -0
  23. data/lib/deepl/resources/style_rule.rb +2 -1
  24. data/lib/deepl/resources/translation_memory.rb +25 -0
  25. data/lib/deepl/style_rule_api.rb +44 -0
  26. data/lib/deepl/translation_memory_api.rb +17 -0
  27. data/lib/deepl.rb +75 -55
  28. data/lib/version.rb +1 -1
  29. data/spec/api/deepl_spec.rb +134 -332
  30. data/spec/integration_tests/document_api_spec.rb +4 -18
  31. data/spec/integration_tests/document_error_paths_spec.rb +33 -0
  32. data/spec/integration_tests/glossary_api_spec.rb +114 -0
  33. data/spec/integration_tests/glossary_error_paths_spec.rb +107 -0
  34. data/spec/integration_tests/languages_api_spec.rb +54 -0
  35. data/spec/integration_tests/languages_error_paths_spec.rb +25 -0
  36. data/spec/integration_tests/rephrase_api_spec.rb +90 -0
  37. data/spec/integration_tests/rephrase_error_paths_spec.rb +53 -0
  38. data/spec/integration_tests/smoke_test_spec.rb +24 -0
  39. data/spec/integration_tests/style_rule_api_spec.rb +55 -17
  40. data/spec/integration_tests/style_rule_error_paths_spec.rb +45 -0
  41. data/spec/integration_tests/translate_api_spec.rb +98 -0
  42. data/spec/integration_tests/translate_error_paths_spec.rb +48 -0
  43. data/spec/integration_tests/translation_memory_api_spec.rb +54 -0
  44. data/spec/integration_tests/translation_memory_error_paths_spec.rb +19 -0
  45. data/spec/integration_tests/usage_api_spec.rb +29 -0
  46. data/spec/integration_tests/usage_error_paths_spec.rb +18 -0
  47. data/spec/requests/glossary/create_spec.rb +0 -21
  48. data/spec/requests/glossary/destroy_spec.rb +0 -39
  49. data/spec/requests/glossary/entries_spec.rb +0 -35
  50. data/spec/requests/glossary/find_spec.rb +0 -40
  51. data/spec/requests/glossary/language_pairs_spec.rb +0 -13
  52. data/spec/requests/glossary/list_spec.rb +0 -27
  53. data/spec/requests/languages_spec.rb +0 -41
  54. data/spec/requests/rephrase_spec.rb +13 -139
  55. data/spec/requests/style_rule/create_custom_instruction_spec.rb +30 -0
  56. data/spec/requests/style_rule/create_spec.rb +29 -0
  57. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +28 -0
  58. data/spec/requests/style_rule/destroy_spec.rb +27 -0
  59. data/spec/requests/style_rule/find_custom_instruction_spec.rb +29 -0
  60. data/spec/requests/style_rule/find_spec.rb +28 -0
  61. data/spec/requests/style_rule/list_spec.rb +27 -0
  62. data/spec/requests/style_rule/update_configured_rules_spec.rb +31 -0
  63. data/spec/requests/style_rule/update_custom_instruction_spec.rb +32 -0
  64. data/spec/requests/style_rule/update_spec.rb +29 -0
  65. data/spec/requests/translate_spec.rb +8 -218
  66. data/spec/requests/translation_memory/list_spec.rb +27 -0
  67. data/spec/requests/usage_spec.rb +0 -16
  68. data/spec/resources/custom_instruction_spec.rb +32 -0
  69. data/spec/resources/style_rule_spec.rb +68 -0
  70. data/spec/resources/translation_memory_spec.rb +35 -0
  71. data/spec/spec_helper.rb +15 -45
  72. data/spec/support/live_mock_server.rb +12 -0
  73. data/spec/support/managed_glossary.rb +17 -0
  74. data/spec/support/managed_style_rule.rb +17 -0
  75. data/spec/support/managed_translation_memory.rb +7 -0
  76. metadata +48 -19
  77. data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
  78. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
  79. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
  80. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
  81. data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
  82. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
  83. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
  84. data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
  85. data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
  86. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
  87. data/spec/fixtures/vcr_cassettes/style_rules.yml +0 -92
  88. data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10630
  89. data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ea8e9d6cc6601abfadddf2b0b70169a7449e71434a8b695c534789d2263d681
4
- data.tar.gz: '029b836b133bbf60d9b4a8acecf90b89d969d991e793db1bf5643f5633895282'
3
+ metadata.gz: 1e06f20b76b38eff20ef4f3f7c7863f374afe2e314438b0bc021df6c4535f991
4
+ data.tar.gz: 30ac12887bd80d6e81cf5c815e5bb8bc5725ea50c66edfd7f4c34c1881e5ad5d
5
5
  SHA512:
6
- metadata.gz: 83070b04ae93261b4524cb5353bdb888c2b9f5a98c9314239ed4ae8c76a53182363bb31ba31f7468a7a5d705162c09fbb69fb0f4a71bc802d8b373d97c46aeaa
7
- data.tar.gz: 8ac545b8fb392b31a0e3fa00f4ed7f556bcf92304d8852226e57d099d365554c6eb5f510fe76891c329bdf89851c2bff217417f157947ffb96e41e50ef58b562
6
+ metadata.gz: 0c5ded1350056aa468d7255ff93eb537dfcf141608a1761651530d5a1d01851bd242a1f205b14626ff8136ec103f38911731242f86e0127e00e75a6fc5c7da08
7
+ data.tar.gz: 570ce96a8751e4de0116b93cac78d08453df5eaf65bef669f9151b361481ab85bea83f72e8d07ffaac01c7e010d8537fd003b0ef3f762d2cc3b2c29c601bfec0
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:
@@ -116,6 +118,9 @@ semgrep-sast:
116
118
  .test_base:
117
119
  stage: test
118
120
  extends: .test
121
+ variables:
122
+ VALIDATE_REQUESTS_FOR_DEEPL_MOCK: '1'
123
+ VALIDATE_RESPONSES_FOR_DEEPL_MOCK: '1'
119
124
  parallel:
120
125
  matrix:
121
126
  - DOCKER_IMAGE: 'ruby:2.7'
@@ -162,11 +167,13 @@ test_manual:
162
167
  rules:
163
168
  - if: $CI_PIPELINE_SOURCE != "schedule"
164
169
 
165
-
166
170
  # stage: publish ----------------------
167
171
 
168
172
  gitlab release:
169
173
  stage: publish
174
+ image: registry.gitlab.com/gitlab-org/release-cli:latest
170
175
  extends: .create_gitlab_release
176
+ before_script:
177
+ - echo "overriding default before_script..."
171
178
  rules:
172
179
  - if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
data/CHANGELOG.md CHANGED
@@ -5,6 +5,38 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
+ ### Changed
9
+ - Reworked the test suite to run against the `deepl-mock` server with OpenAPI
10
+ request and response validation enabled in CI, replacing recorded VCR
11
+ cassettes. Added live integration and error-path specs across all endpoints,
12
+ with resource-level unit specs for response field mapping.
13
+
14
+ ### Removed
15
+ - Dropped VCR cassette playback and the `vcr` and `webmock` development
16
+ dependencies.
17
+
18
+ ## [3.8.0] - 2026-05-27
19
+ ### Added
20
+ - Added support for passing additional HTTP headers to `translate()` and
21
+ `rephrase()`. This can be used to send the `X-DeepL-Reporting-Tag` header
22
+ for usage reporting.
23
+
24
+ ## [3.7.0] - 2026-05-14
25
+ ### Added
26
+ - Added support for listing translation memories via `DeepL.translation_memories.list`.
27
+ - Added `translation_memory` and `translation_memory_threshold` parameters to `translate()`
28
+ to use a translation memory during text translation. The `translation_memory` parameter
29
+ accepts a string ID or a `TranslationMemory` object.
30
+ - Added support for style rules CRUD operations via `DeepL.style_rules`:
31
+ `create()`, `find()`, `update_name()`, `update_configured_rules()`, and `destroy()`.
32
+ - Added support for style rule custom instruction CRUD operations via `DeepL.style_rules`:
33
+ `create_custom_instruction()`, `find_custom_instruction()`,
34
+ `update_custom_instruction()`, and `destroy_custom_instruction()`.
35
+ Please refer to the README for usage instructions.
36
+
37
+ ### Changed
38
+ - Updated unit test to expect the `model_type_used` to now be `quality_optimized`
39
+ - Set explicit `image` for `gitlab release` CI job to avoid missing `$HOME` issues
8
40
 
9
41
  ## [3.6.1] - 2025-12-19
10
42
  ### Fixed
@@ -102,7 +134,9 @@ The change in major version is only due to the change in maintainership, there i
102
134
  ### Fixed
103
135
  - Make RequestEntityTooLarge error message more clear
104
136
 
105
- [Unreleased]: https://github.com/DeepLcom/deepl-rb/compare/v3.6.1...HEAD
137
+ [Unreleased]: https://github.com/DeepLcom/deepl-rb/compare/v3.8.0...HEAD
138
+ [3.8.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.7.0...v3.8.0
139
+ [3.7.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.6.1...v3.7.0
106
140
  [3.6.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.6.0...v3.6.1
107
141
  [3.6.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.5.1...v3.6.0
108
142
  [3.5.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.5.0...v3.5.1
data/Gemfile CHANGED
@@ -19,6 +19,4 @@ group :test do
19
19
  gem 'rubocop-rspec'
20
20
  gem 'simplecov'
21
21
  gem 'simplecov-cobertura'
22
- gem 'vcr'
23
- gem 'webmock'
24
22
  end
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 and managing style rules
333
+ #### Creating a style rule
333
334
 
334
- Currently style rules must be created and managed in the DeepL UI via
335
- https://www.deepl.com/en/custom-rules. Full CRUD functionality via the APIs will
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
- #### Listing all style rules
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
+ ```
351
+
352
+ #### Retrieving and listing style rules
339
353
 
340
- `style_rules.list` returns a list of `StyleRule` objects
341
- corresponding to all of your stored style rules. The method accepts optional
342
- parameters: `page` (page number for pagination, 0-indexed), `page_size` (number
343
- of items per page), and `detailed` (whether to include detailed configuration
344
- rules in the `configured_rules` property).
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 all style rules
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
- # Get style rules with detailed configuration
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
- Created style rules can be used in the `translate` method by specifying the `style_id` option:
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
- translation = DeepL.translate 'Hello World', 'EN', 'ES', style_id: 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4'
393
+ # Update the name
394
+ updated = DeepL.style_rules.update_name('YOUR_STYLE_ID', 'New Name')
366
395
 
367
- puts translation.class
368
- # => DeepL::Resources::Text
369
- puts translation.text
370
- # => 'Hola Mundo'
396
+ # Update configured rules
397
+ updated = DeepL.style_rules.update_configured_rules(
398
+ 'YOUR_STYLE_ID',
399
+ { style_and_tone: { formality: 'formal' } }
400
+ )
371
401
  ```
372
402
 
373
- You can also pass a `StyleRule` object directly:
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.
374
413
 
375
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')
444
+ ```
445
+
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:
450
+
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
- style_rule = style_rules.first
457
+ translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: style_rules.first
458
+ ```
378
459
 
379
- translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: style_rule
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).
479
+
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
@@ -420,6 +551,18 @@ doc_handle = DeepL.document.upload('/path/to/spanish_document.pdf', 'ES', 'EN',
420
551
 
421
552
  The `extra_body_parameters` option allows you to pass arbitrary parameters in the request body. This can be used to access beta features by adding new parameters, or to override built-in parameters (such as `target_lang`, `source_lang`, etc.) for testing purposes.
422
553
 
554
+ ### Sending additional HTTP headers
555
+
556
+ You can pass additional HTTP headers to `translate`, `rephrase`, and the
557
+ `document` methods. For example, to send the `X-DeepL-Reporting-Tag` header
558
+ for usage reporting (see the [cookbook entry](https://developers.deepl.com/docs/learning-how-tos/cookbook/sending-custom-reporting-tags-from-client-libraries)):
559
+
560
+ ```rb
561
+ additional_headers = { 'X-DeepL-Reporting-Tag' => 'my-tag' }
562
+ translation = DeepL.translate 'Hello, world!', 'EN', 'DE', {}, additional_headers
563
+ rephrased = DeepL.rephrase 'Hello, world!', 'EN', nil, nil, {}, additional_headers
564
+ ```
565
+
423
566
  ### Handle exceptions
424
567
 
425
568
  You can capture and process exceptions that may be raised during API calls. These are all the possible exceptions:
@@ -581,18 +724,6 @@ To run tests (rspec and rubocop), use
581
724
  bundle exec rake test
582
725
  ```
583
726
 
584
- ### Caution: Changing VCR Tests
585
-
586
- If you need to rerecord some of the VCR tests, simply setting `record: :new_episodes` and rerunning `rspec` won't be enough in some cases, specifically around document translation (due to its statefulness) and glossaries (since a glossary ID is associated with a specific API account).
587
- For example, there are document translations tests that split up the `upload`, `get_status` and `download` calls into separate test cases. You need to first rerecord the `upload` call, you can do execute a single test like this (the line should be where the `it` block of the test starts):
588
-
589
- ```sh
590
- rspec ./spec/api/deepl_spec.rb:152
591
- ```
592
-
593
- This will return a `document_id` and a `document_key`, you will need to update the values in the `get_status` and `download` tests accordingly. You can find examples for this in the git history.
594
- Similarly, for the glossary tests you will need to delete the recorded HTTP requests for certain glossary IDs so that `rspec` will create the glossaries on your account instead. Feel free to reach out on our discord if you run into any trouble here.
595
-
596
727
  ## Acknowledgements
597
728
 
598
729
  This library was originally developed by [Daniel Herzog](mailto:info@danielherzog.es), we are grateful for his contributions. Beginning with v3.0.0, DeepL took over development and officially supports and maintains the library together with Daniel.
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.6.1
1
+ 3.8.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.6.1 ruby lib
5
+ # stub: deepl-rb 3.8.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "3.6.1"
9
+ s.version = "3.8.0".freeze
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 = "2025-12-19"
15
+ s.date = "2026-06-18"
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",
@@ -93,22 +105,24 @@ Gem::Specification.new do |s|
93
105
  "spec/api/configuration_spec.rb",
94
106
  "spec/api/deepl_spec.rb",
95
107
  "spec/constants/constants_spec.rb",
96
- "spec/fixtures/vcr_cassettes/deepl_document.yml",
97
- "spec/fixtures/vcr_cassettes/deepl_document_download.yml",
98
- "spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
99
- "spec/fixtures/vcr_cassettes/deepl_languages.yml",
100
- "spec/fixtures/vcr_cassettes/deepl_rephrase.yml",
101
- "spec/fixtures/vcr_cassettes/deepl_translate.yml",
102
- "spec/fixtures/vcr_cassettes/deepl_usage.yml",
103
- "spec/fixtures/vcr_cassettes/glossaries.yml",
104
- "spec/fixtures/vcr_cassettes/languages.yml",
105
- "spec/fixtures/vcr_cassettes/rephrase_texts.yml",
106
- "spec/fixtures/vcr_cassettes/style_rules.yml",
107
- "spec/fixtures/vcr_cassettes/translate_texts.yml",
108
- "spec/fixtures/vcr_cassettes/usage.yml",
109
108
  "spec/integration_tests/document_api_spec.rb",
109
+ "spec/integration_tests/document_error_paths_spec.rb",
110
+ "spec/integration_tests/glossary_api_spec.rb",
111
+ "spec/integration_tests/glossary_error_paths_spec.rb",
110
112
  "spec/integration_tests/integration_test_utils.rb",
113
+ "spec/integration_tests/languages_api_spec.rb",
114
+ "spec/integration_tests/languages_error_paths_spec.rb",
115
+ "spec/integration_tests/rephrase_api_spec.rb",
116
+ "spec/integration_tests/rephrase_error_paths_spec.rb",
117
+ "spec/integration_tests/smoke_test_spec.rb",
111
118
  "spec/integration_tests/style_rule_api_spec.rb",
119
+ "spec/integration_tests/style_rule_error_paths_spec.rb",
120
+ "spec/integration_tests/translate_api_spec.rb",
121
+ "spec/integration_tests/translate_error_paths_spec.rb",
122
+ "spec/integration_tests/translation_memory_api_spec.rb",
123
+ "spec/integration_tests/translation_memory_error_paths_spec.rb",
124
+ "spec/integration_tests/usage_api_spec.rb",
125
+ "spec/integration_tests/usage_error_paths_spec.rb",
112
126
  "spec/requests/extra_body_parameters_types_spec.rb",
113
127
  "spec/requests/glossary/create_spec.rb",
114
128
  "spec/requests/glossary/destroy_spec.rb",
@@ -118,23 +132,41 @@ Gem::Specification.new do |s|
118
132
  "spec/requests/glossary/list_spec.rb",
119
133
  "spec/requests/languages_spec.rb",
120
134
  "spec/requests/rephrase_spec.rb",
135
+ "spec/requests/style_rule/create_custom_instruction_spec.rb",
136
+ "spec/requests/style_rule/create_spec.rb",
137
+ "spec/requests/style_rule/destroy_custom_instruction_spec.rb",
138
+ "spec/requests/style_rule/destroy_spec.rb",
139
+ "spec/requests/style_rule/find_custom_instruction_spec.rb",
140
+ "spec/requests/style_rule/find_spec.rb",
141
+ "spec/requests/style_rule/list_spec.rb",
142
+ "spec/requests/style_rule/update_configured_rules_spec.rb",
143
+ "spec/requests/style_rule/update_custom_instruction_spec.rb",
144
+ "spec/requests/style_rule/update_spec.rb",
121
145
  "spec/requests/translate_spec.rb",
146
+ "spec/requests/translation_memory/list_spec.rb",
122
147
  "spec/requests/usage_spec.rb",
148
+ "spec/resources/custom_instruction_spec.rb",
123
149
  "spec/resources/glossary_spec.rb",
124
150
  "spec/resources/language_pair_spec.rb",
125
151
  "spec/resources/language_spec.rb",
152
+ "spec/resources/style_rule_spec.rb",
126
153
  "spec/resources/text_spec.rb",
154
+ "spec/resources/translation_memory_spec.rb",
127
155
  "spec/resources/usage_spec.rb",
128
- "spec/spec_helper.rb"
156
+ "spec/spec_helper.rb",
157
+ "spec/support/live_mock_server.rb",
158
+ "spec/support/managed_glossary.rb",
159
+ "spec/support/managed_style_rule.rb",
160
+ "spec/support/managed_translation_memory.rb"
129
161
  ]
130
162
  s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
131
163
  s.licenses = ["MIT".freeze]
132
- s.rubygems_version = "3.4.6".freeze
164
+ s.rubygems_version = "3.6.2".freeze
133
165
  s.summary = "Official Ruby library for the DeepL language translation API.".freeze
134
166
 
135
167
  s.specification_version = 4
136
168
 
137
- s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
138
- s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
169
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
170
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
139
171
  end
140
172
 
@@ -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
- input_file = File.open(input_file_path, 'rb')
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]))
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
@@ -8,8 +8,9 @@ module DeepL
8
8
  class Rephrase < Base
9
9
  attr_reader :text, :target_lang, :writing_style, :tone
10
10
 
11
- def initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
12
- super(api, options)
11
+ def initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}, # rubocop:disable Metrics/ParameterLists
12
+ additional_headers = {})
13
+ super(api, options, additional_headers)
13
14
  @text = text
14
15
  @target_lang = target_lang
15
16
  @writing_style = writing_style
@@ -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