deepl-rb 3.6.0 → 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.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +27 -0
  3. data/.github/workflows/add_issues_to_kanban.yml +16 -0
  4. data/.gitlab-ci.yml +177 -0
  5. data/.rubocop.yml +51 -0
  6. data/CHANGELOG.md +40 -3
  7. data/CODE_OF_CONDUCT.md +132 -0
  8. data/CONTRIBUTING.md +37 -0
  9. data/Gemfile +24 -0
  10. data/README.md +153 -22
  11. data/Rakefile +58 -0
  12. data/SECURITY.md +58 -0
  13. data/VERSION +1 -0
  14. data/deepl-rb.gemspec +167 -0
  15. data/lib/deepl/api.rb +22 -0
  16. data/lib/deepl/configuration.rb +59 -0
  17. data/lib/deepl/constants/base_constant.rb +18 -0
  18. data/lib/deepl/constants/formality.rb +16 -0
  19. data/lib/deepl/constants/model_type.rb +14 -0
  20. data/lib/deepl/constants/split_sentences.rb +14 -0
  21. data/lib/deepl/constants/tag_handling.rb +13 -0
  22. data/lib/deepl/constants/tone.rb +20 -0
  23. data/lib/deepl/constants/writing_style.rb +20 -0
  24. data/lib/deepl/document_api.rb +121 -0
  25. data/lib/deepl/exceptions/authorization_failed.rb +14 -0
  26. data/lib/deepl/exceptions/bad_request.rb +16 -0
  27. data/lib/deepl/exceptions/document_translation_error.rb +15 -0
  28. data/lib/deepl/exceptions/error.rb +14 -0
  29. data/lib/deepl/exceptions/limit_exceeded.rb +18 -0
  30. data/lib/deepl/exceptions/not_found.rb +16 -0
  31. data/lib/deepl/exceptions/not_supported.rb +14 -0
  32. data/lib/deepl/exceptions/quota_exceeded.rb +14 -0
  33. data/lib/deepl/exceptions/request_entity_too_large.rb +15 -0
  34. data/lib/deepl/exceptions/request_error.rb +21 -0
  35. data/lib/deepl/exceptions/server_error.rb +18 -0
  36. data/lib/deepl/glossary_api.rb +38 -0
  37. data/lib/deepl/requests/base.rb +212 -0
  38. data/lib/deepl/requests/document/download.rb +44 -0
  39. data/lib/deepl/requests/document/get_status.rb +44 -0
  40. data/lib/deepl/requests/document/upload.rb +75 -0
  41. data/lib/deepl/requests/glossary/create.rb +59 -0
  42. data/lib/deepl/requests/glossary/destroy.rb +37 -0
  43. data/lib/deepl/requests/glossary/entries.rb +37 -0
  44. data/lib/deepl/requests/glossary/find.rb +38 -0
  45. data/lib/deepl/requests/glossary/language_pairs.rb +38 -0
  46. data/lib/deepl/requests/glossary/list.rb +37 -0
  47. data/lib/deepl/requests/languages.rb +37 -0
  48. data/lib/deepl/requests/rephrase.rb +55 -0
  49. data/lib/deepl/requests/style_rule/create.rb +46 -0
  50. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +45 -0
  51. data/lib/deepl/requests/style_rule/destroy.rb +39 -0
  52. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +40 -0
  53. data/lib/deepl/requests/style_rule/find.rb +40 -0
  54. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +41 -0
  55. data/lib/deepl/requests/style_rule/list.rb +59 -0
  56. data/lib/deepl/requests/style_rule/update.rb +42 -0
  57. data/lib/deepl/requests/style_rule/update_configured_rules.rb +41 -0
  58. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +47 -0
  59. data/lib/deepl/requests/translate.rb +106 -0
  60. data/lib/deepl/requests/translation_memory/list.rb +58 -0
  61. data/lib/deepl/requests/usage.rb +33 -0
  62. data/lib/deepl/resources/base.rb +17 -0
  63. data/lib/deepl/resources/document_handle.rb +57 -0
  64. data/lib/deepl/resources/document_translation_status.rb +54 -0
  65. data/lib/deepl/resources/glossary.rb +28 -0
  66. data/lib/deepl/resources/language.rb +30 -0
  67. data/lib/deepl/resources/language_pair.rb +23 -0
  68. data/lib/deepl/resources/style_rule.rb +86 -0
  69. data/lib/deepl/resources/text.rb +24 -0
  70. data/lib/deepl/resources/translation_memory.rb +25 -0
  71. data/lib/deepl/resources/usage.rb +27 -0
  72. data/lib/deepl/style_rule_api.rb +61 -0
  73. data/lib/deepl/translation_memory_api.rb +17 -0
  74. data/lib/deepl/utils/backoff_timer.rb +46 -0
  75. data/lib/deepl/utils/exception_builder.rb +34 -0
  76. data/lib/deepl.rb +175 -0
  77. data/lib/http_client_options.rb +22 -0
  78. data/lib/version.rb +8 -0
  79. data/spec/api/api_spec.rb +20 -0
  80. data/spec/api/configuration_spec.rb +122 -0
  81. data/spec/api/deepl_spec.rb +460 -0
  82. data/spec/constants/constants_spec.rb +158 -0
  83. data/spec/fixtures/vcr_cassettes/deepl_document.yml +95 -0
  84. data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +1214 -0
  85. data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +1163 -0
  86. data/spec/fixtures/vcr_cassettes/deepl_languages.yml +54 -0
  87. data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +87 -0
  88. data/spec/fixtures/vcr_cassettes/deepl_translate.yml +358 -0
  89. data/spec/fixtures/vcr_cassettes/deepl_usage.yml +129 -0
  90. data/spec/fixtures/vcr_cassettes/glossaries.yml +1702 -0
  91. data/spec/fixtures/vcr_cassettes/languages.yml +229 -0
  92. data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +401 -0
  93. data/spec/fixtures/vcr_cassettes/style_rules.yml +92 -0
  94. data/spec/fixtures/vcr_cassettes/style_rules_crud.yml +926 -0
  95. data/spec/fixtures/vcr_cassettes/translate_texts.yml +10630 -0
  96. data/spec/fixtures/vcr_cassettes/translation_memories.yml +74 -0
  97. data/spec/fixtures/vcr_cassettes/usage.yml +171 -0
  98. data/spec/integration_tests/document_api_spec.rb +178 -0
  99. data/spec/integration_tests/integration_test_utils.rb +170 -0
  100. data/spec/integration_tests/style_rule_api_spec.rb +135 -0
  101. data/spec/integration_tests/translation_memory_api_spec.rb +70 -0
  102. data/spec/requests/extra_body_parameters_types_spec.rb +82 -0
  103. data/spec/requests/glossary/create_spec.rb +65 -0
  104. data/spec/requests/glossary/destroy_spec.rb +66 -0
  105. data/spec/requests/glossary/entries_spec.rb +62 -0
  106. data/spec/requests/glossary/find_spec.rb +68 -0
  107. data/spec/requests/glossary/language_pairs_spec.rb +40 -0
  108. data/spec/requests/glossary/list_spec.rb +54 -0
  109. data/spec/requests/languages_spec.rb +68 -0
  110. data/spec/requests/rephrase_spec.rb +172 -0
  111. data/spec/requests/style_rule/create_custom_instruction_spec.rb +54 -0
  112. data/spec/requests/style_rule/create_spec.rb +45 -0
  113. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +54 -0
  114. data/spec/requests/style_rule/destroy_spec.rb +54 -0
  115. data/spec/requests/style_rule/find_custom_instruction_spec.rb +56 -0
  116. data/spec/requests/style_rule/find_spec.rb +56 -0
  117. data/spec/requests/style_rule/list_spec.rb +58 -0
  118. data/spec/requests/style_rule/update_configured_rules_spec.rb +52 -0
  119. data/spec/requests/style_rule/update_custom_instruction_spec.rb +58 -0
  120. data/spec/requests/style_rule/update_spec.rb +48 -0
  121. data/spec/requests/translate_spec.rb +492 -0
  122. data/spec/requests/translation_memory/list_spec.rb +61 -0
  123. data/spec/requests/usage_spec.rb +43 -0
  124. data/spec/resources/glossary_spec.rb +38 -0
  125. data/spec/resources/language_pair_spec.rb +23 -0
  126. data/spec/resources/language_spec.rb +45 -0
  127. data/spec/resources/text_spec.rb +23 -0
  128. data/spec/resources/translation_memory_spec.rb +35 -0
  129. data/spec/resources/usage_spec.rb +35 -0
  130. data/spec/spec_helper.rb +92 -0
  131. metadata +130 -3
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
+ ```
339
351
 
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).
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 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
+ )
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
- You can also pass a `StyleRule` object directly:
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
- style_rule = style_rules.first
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
- translation = DeepL.translate 'Hello World', 'EN', 'ES', style_rule: style_rule
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 ADDED
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ warn e.message
10
+ warn 'Run `bundle install` to install missing gems'
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'juwelier'
16
+ require_relative 'lib/version'
17
+
18
+ Juwelier::Tasks.new do |gem|
19
+ gem.name = 'deepl-rb'
20
+ gem.homepage = 'https://github.com/DeepLcom/deepl-rb'
21
+ gem.license = 'MIT'
22
+ gem.summary = 'Official Ruby library for the DeepL language translation API.'
23
+ gem.description =
24
+ 'Official Ruby library for the DeepL language translation API (v2). ' \
25
+ 'For more information, check this: https://www.deepl.com/docs/api-reference.html'
26
+ gem.version = DeepL::VERSION
27
+
28
+ gem.email = 'open-source@deepl.com'
29
+ gem.authors = ['DeepL SE']
30
+ gem.metadata = {
31
+ 'bug_tracker_uri' => 'https://github.com/DeepLcom/deepl-rb/issues',
32
+ 'changelog_uri' => 'https://github.com/DeepLcom/deepl-rb/blob/main/CHANGELOG.md',
33
+ 'documentation_uri' => 'https://github.com/DeepLcom/deepl-rb/blob/main/README.md',
34
+ 'homepage_uri' => 'https://github.com/DeepLcom/deepl-rb'
35
+ }
36
+ gem.files.exclude '.bumpversion.toml'
37
+ gem.files.exclude '.devcontainer/**/*'
38
+ gem.files.exclude '.github'
39
+ gem.files.exclude '.circleci'
40
+ gem.files.exclude 'catalog-info.yaml'
41
+ end
42
+
43
+ Juwelier::RubygemsDotOrgTasks.new
44
+
45
+ # Tests
46
+ require 'rspec/core/rake_task'
47
+ require 'rubocop/rake_task'
48
+
49
+ RuboCop::RakeTask.new
50
+ RSpec::Core::RakeTask.new(:spec)
51
+
52
+ desc 'Run all tests.'
53
+ task :test do
54
+ Rake::Task['spec'].invoke
55
+ Rake::Task['rubocop'].invoke
56
+ end
57
+
58
+ task default: :test
data/SECURITY.md ADDED
@@ -0,0 +1,58 @@
1
+ To report security concerns or vulnerabilities within deepl-rb, please email
2
+ us at [security@deepl.com](mailto:security@deepl.com).
3
+
4
+ You can send us PGP-encrypted email using the following PGP public key:
5
+
6
+ ```
7
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
8
+
9
+ mQINBF7WSmABEADzRUp22VY7bVfUWScKLi9o8BRSEL4u3aPn9WOQoRLQH0j3dNNQ
10
+ FQlwTPn/Ez6qreEl8mX0aE+eLCEykXqsrU/UaTSTslF+H6UQyuGLXkRm8Lblt93I
11
+ OEhL069fC7rm+/zJq72+hishBF8DXqa+Wt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57sqfDI+gkG8WljRY
43
+ yhsCL+xWiwDjtt/8kpk+W75EQmwPuctoS85Rm6hEpffewdQtb2XCEWpbta6hE1r1
44
+ kQARAQABiQI2BBgBCAAgFiEEa9MA8TeC1OEsNn357L3pjvIrjUEFAl7WSmACGwwA
45
+ CgkQ7L3pjvIrjUHFvg/9GnIW9SM/nYJpi1xZVWWGwQ+/kTceD50bv8kyvNaia/9m
46
+ HG6n83xHNTRBYnt8NtTqHvW0y20Cp3gUs2WxboDgCIb3+srI2ipwiaDJcq+rVr0f
47
+ XkCe5MryioKRbTFQ8OgvKh9GK/tYtqZakn7Q9596ajUjHOQV1+Uw/jywLYRlcbqI
48
+ zbxyNVWitxPs3Z7jUDAvhPOIOmhLFc+QxSYrs1W4ZEGnZ3+9utqzlEiMusy9Rq0T
49
+ /W/wrG6SckebjhrwWZJmy/hkW6V6LUX4++vCVV5+zwsvgEortCV8bhvLfqQDr/WN
50
+ fnmbNZtXJbyhTYbcYReOLeKidxO2lZEemnX6iOt5xCdoMcYU23xDT9+tE7Eh6Nfw
51
+ einZemBwfku5vxxPF73pOoQUCRq9tgvUrEq+3BqkqidhnFUOPi0J5726q1PBG65x
52
+ 5o+SQyvB3NA3al3mEH65z3V3/g0UHnhGcEMwVOXBkffgdKNhWYw59qhSVQnkiq0U
53
+ MG10g/RL7VdiISAFPTDmKWUaEDYosinKqOMHwcaVdJq9ssvPf89et6yP/ZkbLIHs
54
+ 2y3oiPonh2RMxi2OedlDz+Jp/A2o3qHmwNvBx/meGB0praGUonFVZTAA1EMS39Bi
55
+ NhG/L8giTyzA0mMkTJAPXtUVlRe5rEjORgYJsgRqZxEfpsJC9OkvYS4ayO0eCEs=
56
+ =jVHt
57
+ -----END PGP PUBLIC KEY BLOCK-----
58
+ ```%
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 3.7.0
data/deepl-rb.gemspec ADDED
@@ -0,0 +1,167 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: deepl-rb 3.7.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "deepl-rb".freeze
9
+ s.version = "3.7.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
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
+ s.require_paths = ["lib".freeze]
14
+ s.authors = ["DeepL SE".freeze]
15
+ s.date = "2026-05-14"
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
+ s.email = "open-source@deepl.com".freeze
18
+ s.extra_rdoc_files = [
19
+ "CHANGELOG.md",
20
+ "LICENSE.md",
21
+ "README.md",
22
+ "license_checker.sh"
23
+ ]
24
+ s.files = [
25
+ ".circleci/config.yml",
26
+ ".github/workflows/add_issues_to_kanban.yml",
27
+ ".gitlab-ci.yml",
28
+ ".rubocop.yml",
29
+ "CHANGELOG.md",
30
+ "CODE_OF_CONDUCT.md",
31
+ "CONTRIBUTING.md",
32
+ "Gemfile",
33
+ "LICENSE.md",
34
+ "README.md",
35
+ "Rakefile",
36
+ "SECURITY.md",
37
+ "VERSION",
38
+ "deepl-rb.gemspec",
39
+ "lib/deepl.rb",
40
+ "lib/deepl/api.rb",
41
+ "lib/deepl/configuration.rb",
42
+ "lib/deepl/constants/base_constant.rb",
43
+ "lib/deepl/constants/formality.rb",
44
+ "lib/deepl/constants/model_type.rb",
45
+ "lib/deepl/constants/split_sentences.rb",
46
+ "lib/deepl/constants/tag_handling.rb",
47
+ "lib/deepl/constants/tone.rb",
48
+ "lib/deepl/constants/writing_style.rb",
49
+ "lib/deepl/document_api.rb",
50
+ "lib/deepl/exceptions/authorization_failed.rb",
51
+ "lib/deepl/exceptions/bad_request.rb",
52
+ "lib/deepl/exceptions/document_translation_error.rb",
53
+ "lib/deepl/exceptions/error.rb",
54
+ "lib/deepl/exceptions/limit_exceeded.rb",
55
+ "lib/deepl/exceptions/not_found.rb",
56
+ "lib/deepl/exceptions/not_supported.rb",
57
+ "lib/deepl/exceptions/quota_exceeded.rb",
58
+ "lib/deepl/exceptions/request_entity_too_large.rb",
59
+ "lib/deepl/exceptions/request_error.rb",
60
+ "lib/deepl/exceptions/server_error.rb",
61
+ "lib/deepl/glossary_api.rb",
62
+ "lib/deepl/requests/base.rb",
63
+ "lib/deepl/requests/document/download.rb",
64
+ "lib/deepl/requests/document/get_status.rb",
65
+ "lib/deepl/requests/document/upload.rb",
66
+ "lib/deepl/requests/glossary/create.rb",
67
+ "lib/deepl/requests/glossary/destroy.rb",
68
+ "lib/deepl/requests/glossary/entries.rb",
69
+ "lib/deepl/requests/glossary/find.rb",
70
+ "lib/deepl/requests/glossary/language_pairs.rb",
71
+ "lib/deepl/requests/glossary/list.rb",
72
+ "lib/deepl/requests/languages.rb",
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",
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",
84
+ "lib/deepl/requests/translate.rb",
85
+ "lib/deepl/requests/translation_memory/list.rb",
86
+ "lib/deepl/requests/usage.rb",
87
+ "lib/deepl/resources/base.rb",
88
+ "lib/deepl/resources/document_handle.rb",
89
+ "lib/deepl/resources/document_translation_status.rb",
90
+ "lib/deepl/resources/glossary.rb",
91
+ "lib/deepl/resources/language.rb",
92
+ "lib/deepl/resources/language_pair.rb",
93
+ "lib/deepl/resources/style_rule.rb",
94
+ "lib/deepl/resources/text.rb",
95
+ "lib/deepl/resources/translation_memory.rb",
96
+ "lib/deepl/resources/usage.rb",
97
+ "lib/deepl/style_rule_api.rb",
98
+ "lib/deepl/translation_memory_api.rb",
99
+ "lib/deepl/utils/backoff_timer.rb",
100
+ "lib/deepl/utils/exception_builder.rb",
101
+ "lib/http_client_options.rb",
102
+ "lib/version.rb",
103
+ "license_checker.sh",
104
+ "spec/api/api_spec.rb",
105
+ "spec/api/configuration_spec.rb",
106
+ "spec/api/deepl_spec.rb",
107
+ "spec/constants/constants_spec.rb",
108
+ "spec/fixtures/vcr_cassettes/deepl_document.yml",
109
+ "spec/fixtures/vcr_cassettes/deepl_document_download.yml",
110
+ "spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
111
+ "spec/fixtures/vcr_cassettes/deepl_languages.yml",
112
+ "spec/fixtures/vcr_cassettes/deepl_rephrase.yml",
113
+ "spec/fixtures/vcr_cassettes/deepl_translate.yml",
114
+ "spec/fixtures/vcr_cassettes/deepl_usage.yml",
115
+ "spec/fixtures/vcr_cassettes/glossaries.yml",
116
+ "spec/fixtures/vcr_cassettes/languages.yml",
117
+ "spec/fixtures/vcr_cassettes/rephrase_texts.yml",
118
+ "spec/fixtures/vcr_cassettes/style_rules.yml",
119
+ "spec/fixtures/vcr_cassettes/style_rules_crud.yml",
120
+ "spec/fixtures/vcr_cassettes/translate_texts.yml",
121
+ "spec/fixtures/vcr_cassettes/translation_memories.yml",
122
+ "spec/fixtures/vcr_cassettes/usage.yml",
123
+ "spec/integration_tests/document_api_spec.rb",
124
+ "spec/integration_tests/integration_test_utils.rb",
125
+ "spec/integration_tests/style_rule_api_spec.rb",
126
+ "spec/integration_tests/translation_memory_api_spec.rb",
127
+ "spec/requests/extra_body_parameters_types_spec.rb",
128
+ "spec/requests/glossary/create_spec.rb",
129
+ "spec/requests/glossary/destroy_spec.rb",
130
+ "spec/requests/glossary/entries_spec.rb",
131
+ "spec/requests/glossary/find_spec.rb",
132
+ "spec/requests/glossary/language_pairs_spec.rb",
133
+ "spec/requests/glossary/list_spec.rb",
134
+ "spec/requests/languages_spec.rb",
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",
146
+ "spec/requests/translate_spec.rb",
147
+ "spec/requests/translation_memory/list_spec.rb",
148
+ "spec/requests/usage_spec.rb",
149
+ "spec/resources/glossary_spec.rb",
150
+ "spec/resources/language_pair_spec.rb",
151
+ "spec/resources/language_spec.rb",
152
+ "spec/resources/text_spec.rb",
153
+ "spec/resources/translation_memory_spec.rb",
154
+ "spec/resources/usage_spec.rb",
155
+ "spec/spec_helper.rb"
156
+ ]
157
+ s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
158
+ s.licenses = ["MIT".freeze]
159
+ s.rubygems_version = "3.4.10".freeze
160
+ s.summary = "Official Ruby library for the DeepL language translation API.".freeze
161
+
162
+ s.specification_version = 4
163
+
164
+ s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
165
+ s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
166
+ end
167
+
data/lib/deepl/api.rb ADDED
@@ -0,0 +1,22 @@
1
+ # Copyright 2018 Daniel Herzog
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ class API
8
+ attr_reader :configuration, :http_client
9
+
10
+ def initialize(configuration)
11
+ @configuration = configuration
12
+ configuration.validate!
13
+ uri = URI(configuration.host)
14
+ @http_client = Net::HTTP.new(uri.host, uri.port)
15
+ @http_client.use_ssl = uri.scheme == 'https'
16
+ end
17
+
18
+ def update_http_client(client)
19
+ @http_client = client
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,59 @@
1
+ # Copyright 2018 Daniel Herzog
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ class Configuration
8
+ ATTRIBUTES = %i[auth_key host logger max_doc_status_queries max_network_retries user_agent
9
+ version].freeze
10
+
11
+ attr_accessor(*ATTRIBUTES)
12
+
13
+ DEEPL_SERVER_URL = 'https://api.deepl.com'
14
+ DEEPL_SERVER_URL_FREE = 'https://api-free.deepl.com'
15
+ private_constant :DEEPL_SERVER_URL, :DEEPL_SERVER_URL_FREE
16
+
17
+ def initialize(data = {}, app_info_name = nil, app_info_version = nil, send_platform_info = true) # rubocop:disable all
18
+ data.each { |key, value| send("#{key}=", value) }
19
+ @auth_key ||= ENV.fetch('DEEPL_AUTH_KEY', nil)
20
+ @host ||= ENV.fetch('DEEPL_SERVER_URL', nil)
21
+ @host ||= if self.class.free_account_auth_key?(@auth_key)
22
+ DEEPL_SERVER_URL_FREE
23
+ else
24
+ DEEPL_SERVER_URL
25
+ end
26
+ @version ||= 'v2'
27
+ @user_agent ||= construct_user_agent(send_platform_info, app_info_name, app_info_version)
28
+ @max_network_retries ||= 5
29
+ @logger ||= nil
30
+ end
31
+
32
+ def validate!
33
+ raise Exceptions::Error, 'auth_key not provided' if auth_key.nil? || auth_key.empty?
34
+ end
35
+
36
+ def attributes
37
+ ATTRIBUTES.to_h { |attr| [attr, send(attr)] }
38
+ end
39
+
40
+ def ==(other)
41
+ attributes == other.attributes
42
+ end
43
+
44
+ def self.free_account_auth_key?(key)
45
+ key&.end_with?(':fx')
46
+ end
47
+
48
+ def construct_user_agent(send_platform_info, app_info_name, app_info_version)
49
+ library_info_str = "deepl-ruby/#{DeepL::VERSION}"
50
+ if send_platform_info
51
+ library_info_str += " (#{RbConfig::CONFIG['host_os']}) ruby/#{RUBY_VERSION}"
52
+ end
53
+ if app_info_name && app_info_version
54
+ library_info_str += " #{app_info_name}/#{app_info_version}"
55
+ end
56
+ library_info_str
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class BaseConstant
9
+ def self.options
10
+ constants.map { |const| const_get(const) }
11
+ end
12
+
13
+ def self.valid?(value)
14
+ options.include?(value)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class Formality < BaseConstant
9
+ DEFAULT = 'default'
10
+ MORE = 'more'
11
+ LESS = 'less'
12
+ PREFER_MORE = 'prefer_more'
13
+ PREFER_LESS = 'prefer_less'
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class ModelType < BaseConstant
9
+ QUALITY_OPTIMIZED = 'quality_optimized'
10
+ PREFER_QUALITY_OPTIMIZED = 'prefer_quality_optimized'
11
+ LATENCY_OPTIMIZED = 'latency_optimized'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class SplitSentences < BaseConstant
9
+ NO_SPLITTING = '0'
10
+ SPLIT_ON_PUNCTUATION_AND_NEWLINES = '1'
11
+ SPLIT_ON_PUNCTUATION_ONLY = 'nonewlines'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright 2025 DeepL SE (https://www.deepl.com)
2
+ # Use of this source code is governed by an MIT
3
+ # license that can be found in the LICENSE.md file.
4
+ # frozen_string_literal: true
5
+
6
+ module DeepL
7
+ module Constants
8
+ class TagHandling < BaseConstant
9
+ XML = 'xml'
10
+ HTML = 'html'
11
+ end
12
+ end
13
+ end