deepl-rb 3.9.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -1
  3. data/CHANGELOG.md +741 -18
  4. data/Gemfile +4 -0
  5. data/README.md +1001 -327
  6. data/Rakefile +29 -7
  7. data/VERSION +1 -1
  8. data/deepl-rb.gemspec +75 -88
  9. data/lib/deepl/admin_client.rb +208 -0
  10. data/lib/deepl/api.rb +18 -8
  11. data/lib/deepl/app_info.rb +19 -0
  12. data/lib/deepl/client.rb +1284 -0
  13. data/lib/deepl/configuration.rb +27 -32
  14. data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
  15. data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
  16. data/lib/deepl/constants/document_status_code.rb +17 -0
  17. data/lib/deepl/constants/language_include.rb +17 -0
  18. data/lib/deepl/constants/language_resource_name.rb +21 -0
  19. data/lib/deepl/constants/tag_handling_version.rb +14 -0
  20. data/lib/deepl/exceptions/authorization_failed.rb +1 -1
  21. data/lib/deepl/exceptions/bad_request.rb +1 -3
  22. data/lib/deepl/exceptions/connection_error.rb +40 -0
  23. data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
  24. data/lib/deepl/exceptions/document_translation_error.rb +17 -1
  25. data/lib/deepl/exceptions/error.rb +13 -1
  26. data/lib/deepl/exceptions/limit_exceeded.rb +1 -1
  27. data/lib/deepl/exceptions/not_found.rb +8 -3
  28. data/lib/deepl/exceptions/quota_exceeded.rb +1 -1
  29. data/lib/deepl/exceptions/request_entity_too_large.rb +1 -2
  30. data/lib/deepl/exceptions/request_error.rb +26 -2
  31. data/lib/deepl/exceptions/server_error.rb +9 -2
  32. data/lib/deepl/exceptions/translation_memory_job_error.rb +32 -0
  33. data/lib/deepl/exceptions/validation_error.rb +15 -0
  34. data/lib/deepl/requests/admin/base.rb +94 -0
  35. data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
  36. data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
  37. data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
  38. data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
  39. data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
  40. data/lib/deepl/requests/base.rb +313 -65
  41. data/lib/deepl/requests/correct.rb +51 -0
  42. data/lib/deepl/requests/document/download.rb +11 -3
  43. data/lib/deepl/requests/document/get_status.rb +2 -2
  44. data/lib/deepl/requests/document/upload.rb +56 -20
  45. data/lib/deepl/requests/glossary/base.rb +30 -0
  46. data/lib/deepl/requests/glossary/create.rb +18 -18
  47. data/lib/deepl/requests/glossary/destroy.rb +4 -16
  48. data/lib/deepl/requests/glossary/entries.rb +6 -14
  49. data/lib/deepl/requests/glossary/find.rb +3 -13
  50. data/lib/deepl/requests/glossary/language_pairs.rb +22 -6
  51. data/lib/deepl/requests/glossary/list.rb +2 -2
  52. data/lib/deepl/requests/language_resources.rb +41 -0
  53. data/lib/deepl/requests/languages.rb +25 -6
  54. data/lib/deepl/requests/languages_for_resource.rb +56 -0
  55. data/lib/deepl/requests/multilingual_glossary/create.rb +45 -0
  56. data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
  57. data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +55 -0
  58. data/lib/deepl/requests/multilingual_glossary/entries.rb +68 -0
  59. data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
  60. data/lib/deepl/requests/multilingual_glossary/helpers.rb +71 -0
  61. data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
  62. data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
  63. data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
  64. data/lib/deepl/requests/rephrase.rb +8 -10
  65. data/lib/deepl/requests/spoken_terms/create.rb +42 -0
  66. data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
  67. data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +42 -0
  68. data/lib/deepl/requests/spoken_terms/entries.rb +47 -0
  69. data/lib/deepl/requests/spoken_terms/find.rb +35 -0
  70. data/lib/deepl/requests/spoken_terms/helpers.rb +74 -0
  71. data/lib/deepl/requests/spoken_terms/list.rb +35 -0
  72. data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
  73. data/lib/deepl/requests/spoken_terms/update.rb +40 -0
  74. data/lib/deepl/requests/style_profile/base.rb +83 -0
  75. data/lib/deepl/requests/style_profile/create.rb +40 -0
  76. data/lib/deepl/requests/style_profile/destroy.rb +34 -0
  77. data/lib/deepl/requests/style_profile/find.rb +33 -0
  78. data/lib/deepl/requests/style_profile/list.rb +43 -0
  79. data/lib/deepl/requests/style_profile/update.rb +35 -0
  80. data/lib/deepl/requests/style_rule/create.rb +24 -0
  81. data/lib/deepl/requests/style_rule/create_custom_instruction.rb +11 -2
  82. data/lib/deepl/requests/style_rule/destroy.rb +4 -2
  83. data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
  84. data/lib/deepl/requests/style_rule/find.rb +4 -2
  85. data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
  86. data/lib/deepl/requests/style_rule/helpers.rb +44 -0
  87. data/lib/deepl/requests/style_rule/list.rb +3 -1
  88. data/lib/deepl/requests/style_rule/update.rb +5 -2
  89. data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
  90. data/lib/deepl/requests/style_rule/update_custom_instruction.rb +7 -3
  91. data/lib/deepl/requests/translate.rb +43 -27
  92. data/lib/deepl/requests/translation_memory/base.rb +1 -4
  93. data/lib/deepl/requests/translation_memory/create_export.rb +7 -2
  94. data/lib/deepl/requests/translation_memory/create_import.rb +11 -1
  95. data/lib/deepl/requests/translation_memory/destroy.rb +1 -1
  96. data/lib/deepl/requests/translation_memory/find.rb +1 -1
  97. data/lib/deepl/requests/translation_memory/find_job.rb +1 -1
  98. data/lib/deepl/requests/translation_memory/list.rb +4 -3
  99. data/lib/deepl/requests/translation_memory/segments.rb +5 -4
  100. data/lib/deepl/requests/translation_memory/storage_base.rb +37 -9
  101. data/lib/deepl/requests/translation_memory/upload_file.rb +1 -1
  102. data/lib/deepl/requests/usage.rb +28 -1
  103. data/lib/deepl/requests/write_improvements.rb +42 -0
  104. data/lib/deepl/resources/admin_usage_report.rb +73 -0
  105. data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
  106. data/lib/deepl/resources/developer_key.rb +57 -0
  107. data/lib/deepl/resources/document_handle.rb +8 -34
  108. data/lib/deepl/resources/document_translation_status.rb +14 -7
  109. data/lib/deepl/resources/language.rb +5 -3
  110. data/lib/deepl/resources/language_resource.rb +57 -0
  111. data/lib/deepl/resources/language_support.rb +56 -0
  112. data/lib/deepl/resources/multilingual_glossary.rb +112 -0
  113. data/lib/deepl/resources/spoken_terms.rb +61 -0
  114. data/lib/deepl/resources/style_profile.rb +44 -0
  115. data/lib/deepl/resources/style_rule.rb +4 -23
  116. data/lib/deepl/resources/text.rb +18 -2
  117. data/lib/deepl/resources/translation_memory.rb +8 -2
  118. data/lib/deepl/resources/translation_memory_import.rb +1 -1
  119. data/lib/deepl/resources/translation_memory_job.rb +26 -7
  120. data/lib/deepl/resources/translation_memory_segments.rb +8 -6
  121. data/lib/deepl/resources/usage.rb +61 -5
  122. data/lib/deepl/utils/client_builder.rb +89 -0
  123. data/lib/deepl/utils/document_poller.rb +70 -0
  124. data/lib/deepl/utils/exception_builder.rb +3 -2
  125. data/lib/deepl/utils/glossary_entries.rb +30 -0
  126. data/lib/deepl/utils/http_client_builder.rb +116 -0
  127. data/lib/deepl/utils/number_parser.rb +34 -0
  128. data/lib/deepl/utils/output_path.rb +25 -0
  129. data/lib/deepl/utils/term_validator.rb +33 -0
  130. data/lib/deepl/utils/time_parser.rb +14 -0
  131. data/lib/deepl/utils/translation_memory_operations.rb +230 -0
  132. data/lib/deepl.rb +68 -108
  133. data/lib/http_client_options.rb +21 -1
  134. data/lib/version.rb +1 -1
  135. data/upgrading_to_v4.md +374 -0
  136. metadata +84 -85
  137. data/.circleci/config.yml +0 -27
  138. data/.github/workflows/add_issues_to_kanban.yml +0 -16
  139. data/.gitlab-ci.yml +0 -179
  140. data/lib/deepl/document_api.rb +0 -131
  141. data/lib/deepl/exceptions/not_supported.rb +0 -14
  142. data/lib/deepl/glossary_api.rb +0 -38
  143. data/lib/deepl/style_rule_api.rb +0 -61
  144. data/lib/deepl/translation_memory_api.rb +0 -309
  145. data/license_checker.sh +0 -8
  146. data/spec/api/api_spec.rb +0 -20
  147. data/spec/api/configuration_spec.rb +0 -122
  148. data/spec/api/deepl_spec.rb +0 -262
  149. data/spec/constants/constants_spec.rb +0 -158
  150. data/spec/integration_tests/document_api_spec.rb +0 -211
  151. data/spec/integration_tests/document_error_paths_spec.rb +0 -33
  152. data/spec/integration_tests/glossary_api_spec.rb +0 -114
  153. data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
  154. data/spec/integration_tests/integration_test_utils.rb +0 -178
  155. data/spec/integration_tests/languages_api_spec.rb +0 -54
  156. data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
  157. data/spec/integration_tests/rephrase_api_spec.rb +0 -90
  158. data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
  159. data/spec/integration_tests/smoke_test_spec.rb +0 -24
  160. data/spec/integration_tests/style_rule_api_spec.rb +0 -117
  161. data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
  162. data/spec/integration_tests/translate_api_spec.rb +0 -117
  163. data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
  164. data/spec/integration_tests/translation_memory_api_spec.rb +0 -244
  165. data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -87
  166. data/spec/integration_tests/usage_api_spec.rb +0 -29
  167. data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
  168. data/spec/requests/document/upload_spec.rb +0 -130
  169. data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
  170. data/spec/requests/glossary/create_spec.rb +0 -44
  171. data/spec/requests/glossary/destroy_spec.rb +0 -27
  172. data/spec/requests/glossary/entries_spec.rb +0 -27
  173. data/spec/requests/glossary/find_spec.rb +0 -28
  174. data/spec/requests/glossary/language_pairs_spec.rb +0 -27
  175. data/spec/requests/glossary/list_spec.rb +0 -27
  176. data/spec/requests/languages_spec.rb +0 -27
  177. data/spec/requests/rephrase_spec.rb +0 -46
  178. data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
  179. data/spec/requests/style_rule/create_spec.rb +0 -29
  180. data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
  181. data/spec/requests/style_rule/destroy_spec.rb +0 -27
  182. data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
  183. data/spec/requests/style_rule/find_spec.rb +0 -28
  184. data/spec/requests/style_rule/list_spec.rb +0 -27
  185. data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
  186. data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
  187. data/spec/requests/style_rule/update_spec.rb +0 -29
  188. data/spec/requests/translate_spec.rb +0 -338
  189. data/spec/requests/translation_memory/create_export_spec.rb +0 -37
  190. data/spec/requests/translation_memory/create_import_spec.rb +0 -61
  191. data/spec/requests/translation_memory/destroy_spec.rb +0 -36
  192. data/spec/requests/translation_memory/download_export_spec.rb +0 -54
  193. data/spec/requests/translation_memory/find_job_spec.rb +0 -37
  194. data/spec/requests/translation_memory/find_spec.rb +0 -36
  195. data/spec/requests/translation_memory/list_spec.rb +0 -27
  196. data/spec/requests/translation_memory/segments_spec.rb +0 -58
  197. data/spec/requests/translation_memory/upload_file_spec.rb +0 -55
  198. data/spec/requests/usage_spec.rb +0 -27
  199. data/spec/resources/custom_instruction_spec.rb +0 -32
  200. data/spec/resources/glossary_spec.rb +0 -38
  201. data/spec/resources/language_pair_spec.rb +0 -23
  202. data/spec/resources/language_spec.rb +0 -45
  203. data/spec/resources/style_rule_spec.rb +0 -68
  204. data/spec/resources/text_spec.rb +0 -23
  205. data/spec/resources/translation_memory_export_spec.rb +0 -38
  206. data/spec/resources/translation_memory_import_spec.rb +0 -30
  207. data/spec/resources/translation_memory_job_spec.rb +0 -109
  208. data/spec/resources/translation_memory_segments_spec.rb +0 -78
  209. data/spec/resources/translation_memory_spec.rb +0 -52
  210. data/spec/resources/usage_spec.rb +0 -35
  211. data/spec/spec_helper.rb +0 -62
  212. data/spec/support/live_mock_server.rb +0 -12
  213. data/spec/support/managed_glossary.rb +0 -65
  214. data/spec/support/managed_style_rule.rb +0 -17
  215. data/spec/support/managed_translation_memory.rb +0 -55
@@ -1,29 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe 'DeepL.usage' do # rubocop:disable RSpec/DescribeClass
9
- describe 'happy path' do
10
- it 'returns a Usage resource with integer counters where count does not exceed limit' do
11
- usage = DeepL.usage
12
-
13
- expect(usage).to be_a(DeepL::Resources::Usage)
14
- expect(usage).to respond_to(:character_count, :character_limit)
15
- expect(usage.character_count).to be_an(Integer)
16
- expect(usage.character_limit).to be_an(Integer)
17
- expect(usage.character_count).to be <= usage.character_limit
18
- end
19
- end
20
-
21
- describe 'resource shape' do
22
- it 'exposes quota_exceeded? consistent with character_count vs character_limit' do
23
- usage = DeepL.usage
24
-
25
- expect(usage).to respond_to(:quota_exceeded?)
26
- expect(usage.quota_exceeded?).to eq(usage.character_count >= usage.character_limit)
27
- end
28
- end
29
- end
@@ -1,18 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe 'DeepL.usage error paths' do # rubocop:disable RSpec/DescribeClass
9
- include_context 'with a live mock server'
10
-
11
- describe 'authorization failures' do
12
- it 'raises AuthorizationFailed when the auth key is invalid' do
13
- request = DeepL::Requests::Usage.new(unauthorized_api)
14
-
15
- expect { request.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
16
- end
17
- end
18
- end
@@ -1,130 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Document::Upload do
9
- subject(:upload) do
10
- described_class.new(api, input_file_path, source_lang, target_lang, filename, options)
11
- end
12
-
13
- around do |tests|
14
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
15
- tests.call
16
- ENV.replace(tmp_env)
17
- end
18
-
19
- let(:api) { build_deepl_api }
20
- let(:input_file_path) { '/tmp/example.txt' }
21
- let(:source_lang) { 'EN' }
22
- let(:target_lang) { 'DE' }
23
- let(:filename) { 'example.txt' }
24
- let(:options) { {} }
25
- let(:input_file) { instance_double(File) }
26
-
27
- # Builds the multipart form data without performing any network or filesystem IO.
28
- def form_data
29
- upload.send(:build_base_form_data, input_file)
30
- end
31
-
32
- def form_value(form, key)
33
- field = form.find { |name, _| name == key }
34
- field&.last
35
- end
36
-
37
- describe '#initialize' do
38
- it 'creates a request object' do
39
- expect(upload).to be_a(described_class)
40
- end
41
- end
42
-
43
- describe 'building the upload form data' do
44
- context 'when using the `style_rule` option' do
45
- it 'does not append a `style_id` field when not provided' do
46
- expect(form_value(form_data, 'style_id')).to be_nil
47
- end
48
-
49
- it 'appends a `style_id` field from a style rule ID string' do
50
- options[:style_rule] = 'style-123'
51
- expect(form_value(form_data, 'style_id')).to eq('style-123')
52
- end
53
-
54
- it 'appends a `style_id` field from a StyleRule object' do
55
- options[:style_rule] =
56
- DeepL::Resources::StyleRule.new({ 'style_id' => 'style-obj' }, nil, nil)
57
- expect(form_value(form_data, 'style_id')).to eq('style-obj')
58
- end
59
- end
60
-
61
- context 'when using the `translation_memory` option' do
62
- it 'does not append a `translation_memory_id` field when not provided' do
63
- expect(form_value(form_data, 'translation_memory_id')).to be_nil
64
- end
65
-
66
- it 'appends a `translation_memory_id` field from a translation memory ID string' do
67
- options[:translation_memory] = 'tm-123'
68
- expect(form_value(form_data, 'translation_memory_id')).to eq('tm-123')
69
- end
70
-
71
- it 'appends a `translation_memory_id` field from a TranslationMemory object' do
72
- options[:translation_memory] =
73
- DeepL::Resources::TranslationMemory.new({ 'translation_memory_id' => 'tm-obj' }, nil, nil)
74
- expect(form_value(form_data, 'translation_memory_id')).to eq('tm-obj')
75
- end
76
-
77
- it 'appends a `translation_memory_threshold` field serialized to a string' do
78
- options[:translation_memory] = 'tm-123'
79
- options[:translation_memory_threshold] = 80
80
- form = form_data
81
- expect(form_value(form, 'translation_memory_id')).to eq('tm-123')
82
- expect(form_value(form, 'translation_memory_threshold')).to eq('80')
83
- end
84
-
85
- it 'does not append a `translation_memory_threshold` field when not provided' do
86
- options[:translation_memory] = 'tm-123'
87
- expect(form_value(form_data, 'translation_memory_threshold')).to be_nil
88
- end
89
- end
90
-
91
- context 'when using the `glossary_ids` option' do
92
- it 'does not append a `glossary_ids` field when not provided' do
93
- expect(form_value(form_data, 'glossary_ids')).to be_nil
94
- end
95
-
96
- it 'appends a comma-separated `glossary_ids` field from an array of IDs' do
97
- options[:glossary_ids] = %w[gid1 gid2 gid3]
98
- expect(form_value(form_data, 'glossary_ids')).to eq('gid1,gid2,gid3')
99
- end
100
-
101
- it 'appends `glossary_ids` from Glossary objects using their IDs' do
102
- options[:glossary_ids] = [
103
- DeepL::Resources::Glossary.new({ 'glossary_id' => 'gid-obj' }, nil, nil),
104
- 'gid-str'
105
- ]
106
- expect(form_value(form_data, 'glossary_ids')).to eq('gid-obj,gid-str')
107
- end
108
-
109
- it 'raises when combined with the singular `glossary_id` option' do
110
- options[:glossary_id] = 'single'
111
- options[:glossary_ids] = %w[gid1]
112
- expect { form_data }.to raise_error(ArgumentError, /cannot be used together/)
113
- end
114
-
115
- it 'raises when more than 5 glossary IDs are provided' do
116
- options[:glossary_ids] = %w[a b c d e f]
117
- expect { form_data }.to raise_error(ArgumentError, /maximum of 5 glossary IDs/)
118
- end
119
-
120
- context 'when `source_lang` is not set' do
121
- let(:source_lang) { nil }
122
-
123
- it 'raises because `glossary_ids` requires `source_lang`' do
124
- options[:glossary_ids] = %w[gid1]
125
- expect { form_data }.to raise_error(ArgumentError, /requires `source_lang`/)
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,82 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe 'DeepL::Requests::Base extra_body_parameters type preservation' do
9
- let(:api) { build_deepl_api }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- describe 'apply_extra_body_parameters_to_json' do
18
- it 'preserves boolean true' do
19
- request = DeepL::Requests::Translate.new(
20
- api, 'test', 'EN', 'ES',
21
- extra_body_parameters: { enable_beta_languages: true }
22
- )
23
-
24
- payload = {}
25
- request.send(:apply_extra_body_parameters_to_json, payload)
26
-
27
- expect(payload[:enable_beta_languages]).to be(true)
28
- expect(payload[:enable_beta_languages]).to be_a(TrueClass)
29
- end
30
-
31
- it 'preserves boolean false' do
32
- request = DeepL::Requests::Translate.new(
33
- api, 'test', 'EN', 'ES',
34
- extra_body_parameters: { some_flag: false }
35
- )
36
-
37
- payload = {}
38
- request.send(:apply_extra_body_parameters_to_json, payload)
39
-
40
- expect(payload[:some_flag]).to be(false)
41
- expect(payload[:some_flag]).to be_a(FalseClass)
42
- end
43
-
44
- it 'preserves integers' do
45
- request = DeepL::Requests::Translate.new(
46
- api, 'test', 'EN', 'ES',
47
- extra_body_parameters: { some_number: 42 }
48
- )
49
-
50
- payload = {}
51
- request.send(:apply_extra_body_parameters_to_json, payload)
52
-
53
- expect(payload[:some_number]).to eq(42)
54
- expect(payload[:some_number]).to be_a(Integer)
55
- end
56
-
57
- it 'preserves strings' do
58
- request = DeepL::Requests::Translate.new(
59
- api, 'test', 'EN', 'ES',
60
- extra_body_parameters: { some_string: 'hello' }
61
- )
62
-
63
- payload = {}
64
- request.send(:apply_extra_body_parameters_to_json, payload)
65
-
66
- expect(payload[:some_string]).to eq('hello')
67
- expect(payload[:some_string]).to be_a(String)
68
- end
69
-
70
- it 'allows overriding standard parameters' do
71
- request = DeepL::Requests::Translate.new(
72
- api, 'test', 'EN', 'ES',
73
- extra_body_parameters: { target_lang: 'FR' }
74
- )
75
-
76
- payload = { target_lang: 'ES' }
77
- request.send(:apply_extra_body_parameters_to_json, payload)
78
-
79
- expect(payload[:target_lang]).to eq('FR')
80
- end
81
- end
82
- end
@@ -1,44 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::Create do
9
- subject(:create) do
10
- described_class.new(api, name, source_lang, target_lang, entries, options)
11
- end
12
-
13
- around do |tests|
14
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
15
- tests.call
16
- ENV.replace(tmp_env)
17
- end
18
-
19
- let(:api) { build_deepl_api }
20
- let(:name) { 'Mi Glosario' }
21
- let(:source_lang) { 'EN' }
22
- let(:target_lang) { 'ES' }
23
- let(:entries) do
24
- [
25
- %w[Hello Hola],
26
- %w[World Mundo]
27
- ]
28
- end
29
- let(:options) { {} }
30
-
31
- describe '#initialize' do
32
- context 'when building a request' do
33
- it 'creates a request object' do
34
- expect(create).to be_a(described_class)
35
- end
36
-
37
- it 'sets the default value for the entries format if not specified' do
38
- request = described_class.new(api, name, source_lang, target_lang,
39
- entries, options)
40
- expect(request.entries_format).to eq('tsv')
41
- end
42
- end
43
- end
44
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::Destroy do
9
- subject(:destroy) { described_class.new(api, id) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(destroy).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::Entries do
9
- subject(:entries_obj) { described_class.new(api, id) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(entries_obj).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,28 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::Find do
9
- subject(:glossary_find) { described_class.new(api, id, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:id) { '9ab5dac2-b7b2-4b4a-808a-e8e305df5ecb' }
19
- let(:options) { {} }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(glossary_find).to be_a(described_class)
25
- end
26
- end
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::LanguagePairs do
9
- subject(:language_pairs_obj) { described_class.new(api, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:options) { {} }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(language_pairs_obj).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2022 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Glossary::List do
9
- subject(:glossary_list) { described_class.new(api, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:options) { {} }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(glossary_list).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2021 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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Languages do
9
- subject(:languages_obj) { described_class.new(api, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:options) { {} }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(languages_obj).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,46 +0,0 @@
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
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::Rephrase do
9
- around do |tests|
10
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
11
- tests.call
12
- ENV.replace(tmp_env)
13
- end
14
-
15
- let(:api) { build_deepl_api }
16
- let(:text) do
17
- 'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.'
18
- end
19
- let(:target_lang) { 'EN' }
20
-
21
- describe '#initialize' do
22
- context 'when passing additional headers' do
23
- it 'merges the headers into the request headers' do
24
- request = described_class.new(api, text, target_lang, nil, nil, {},
25
- { 'X-DeepL-Reporting-Tag' => 'my-tag' })
26
- expect(request.send(:headers)).to include('X-DeepL-Reporting-Tag' => 'my-tag')
27
- end
28
-
29
- it 'defaults to no additional headers' do
30
- request = described_class.new(api, text, target_lang)
31
- expect(request.send(:headers).keys).to contain_exactly('Authorization', 'User-Agent')
32
- end
33
- end
34
-
35
- context 'with a writing style and tone from the provided constants applied' do
36
- let(:writing_style) { DeepL::Constants::WritingStyle::BUSINESS }
37
- let(:tone) { DeepL::Constants::Tone::FRIENDLY }
38
-
39
- it 'has the correct writing style and tone applied' do
40
- request = described_class.new(api, text, target_lang, writing_style, tone)
41
- expect(request.writing_style).to eq('business')
42
- expect(request.tone).to eq('friendly')
43
- end
44
- end
45
- end
46
- end
@@ -1,30 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::StyleRule::CreateCustomInstruction do
9
- subject(:create_instruction) { described_class.new(api, style_id, label, prompt, nil, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
19
- let(:label) { 'Test Instruction' }
20
- let(:prompt) { 'Always use formal language' }
21
- let(:options) { {} }
22
-
23
- describe '#initialize' do
24
- context 'when building a request' do
25
- it 'creates a request object' do
26
- expect(create_instruction).to be_a(described_class)
27
- end
28
- end
29
- end
30
- end
@@ -1,29 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::StyleRule::Create do
9
- subject(:create) { described_class.new(api, name, language, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:name) { 'Test Style Rule' }
19
- let(:language) { 'en' }
20
- let(:options) { {} }
21
-
22
- describe '#initialize' do
23
- context 'when building a request' do
24
- it 'creates a request object' do
25
- expect(create).to be_a(described_class)
26
- end
27
- end
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::StyleRule::DestroyCustomInstruction do
9
- subject(:destroy_instruction) { described_class.new(api, style_id, instruction_id) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
19
- let(:instruction_id) { 'test-instruction-id' }
20
-
21
- describe '#initialize' do
22
- context 'when building a request' do
23
- it 'creates a request object' do
24
- expect(destroy_instruction).to be_a(described_class)
25
- end
26
- end
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::StyleRule::Destroy do
9
- subject(:destroy) { described_class.new(api, style_id) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
19
-
20
- describe '#initialize' do
21
- context 'when building a request' do
22
- it 'creates a request object' do
23
- expect(destroy).to be_a(described_class)
24
- end
25
- end
26
- end
27
- end
@@ -1,29 +0,0 @@
1
- # Copyright 2026 DeepL SE (https://www.deepl.com)
2
- # Use of this source code is governed by an MIT
3
- # license that can be found in the LICENSE.md file.
4
- # frozen_string_literal: true
5
-
6
- require 'spec_helper'
7
-
8
- describe DeepL::Requests::StyleRule::FindCustomInstruction do
9
- subject(:find_instruction) { described_class.new(api, style_id, instruction_id, options) }
10
-
11
- around do |tests|
12
- tmp_env = replace_env_preserving_deepl_vars_except_mock_server
13
- tests.call
14
- ENV.replace(tmp_env)
15
- end
16
-
17
- let(:api) { build_deepl_api }
18
- let(:style_id) { 'dca2e053-8ae5-45e6-a0d2-881156e7f4e4' }
19
- let(:instruction_id) { 'test-instruction-id' }
20
- let(:options) { {} }
21
-
22
- describe '#initialize' do
23
- context 'when building a request' do
24
- it 'creates a request object' do
25
- expect(find_instruction).to be_a(described_class)
26
- end
27
- end
28
- end
29
- end