deepl-rb 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +55 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +17 -6
- data/lib/deepl/constants/base_constant.rb +18 -0
- data/lib/deepl/constants/formality.rb +16 -0
- data/lib/deepl/constants/model_type.rb +14 -0
- data/lib/deepl/constants/split_sentences.rb +14 -0
- data/lib/deepl/constants/tag_handling.rb +13 -0
- data/lib/deepl/constants/tone.rb +20 -0
- data/lib/deepl/constants/writing_style.rb +20 -0
- data/lib/deepl/requests/rephrase.rb +54 -0
- data/lib/deepl.rb +10 -0
- data/spec/constants/constants_spec.rb +158 -0
- data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +401 -0
- data/spec/requests/rephrase_spec.rb +172 -0
- data/spec/requests/translate_spec.rb +23 -0
- data/spec/spec_helper.rb +6 -2
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47bf797967929a4b7775e21ce7021cdc1871283b3358cbb36d13a8f6f6b5ac6b
|
4
|
+
data.tar.gz: df4399cc6c552fb5c03b79b0566d2370101b58246bfd5e0b05d27c83e994ae6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4639c87e107dfa0a13b1bace938e9a3580fb15bb1e2f280267527e3d5d0c9b8913752b841bd095039f1e4f7d15b13813075131c0767216855bf5e7d28a4b81a1
|
7
|
+
data.tar.gz: 19743f57e84c550e5fe35b1d6c39f853df1d0d1d357eb8c0f061a0202831af8a557651f34f50dcad10928b45638a3a09b9ab64652fdadab6d6ad62ec3f2a1242
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
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
|
+
## [3.2.0]
|
8
|
+
### Added
|
9
|
+
* Added `rephrase` functionality to get a new version of submitted text with various possible styles or tones applied
|
10
|
+
* Added `DeepL::Constants` namespace and associated constant values for options possibilities
|
7
11
|
|
8
12
|
## [3.1.0]
|
9
13
|
### Added
|
@@ -50,7 +54,7 @@ The change in major version is only due to the change in maintainership, there i
|
|
50
54
|
### Fixed
|
51
55
|
* Make RequestEntityTooLarge error message more clear
|
52
56
|
|
53
|
-
|
57
|
+
[3.2.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.1.0...3.2.0
|
54
58
|
[3.1.0]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.2...v3.1.0
|
55
59
|
[3.0.2]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.1...v3.0.2
|
56
60
|
[3.0.1]: https://github.com/DeepLcom/deepl-rb/compare/v3.0.0...v3.0.1
|
data/README.md
CHANGED
@@ -168,6 +168,37 @@ The following parameters will be automatically converted:
|
|
168
168
|
| `glossary_id` | No conversion applied
|
169
169
|
| `context` | No conversion applied
|
170
170
|
|
171
|
+
### Rephrase Text
|
172
|
+
|
173
|
+
To rephrase or improve text, including changing the writing style or tone of the text, use the `rephrase` method:
|
174
|
+
|
175
|
+
```rb
|
176
|
+
rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN'
|
177
|
+
|
178
|
+
puts rephrased_text.class
|
179
|
+
# => DeepL::Resources::Text
|
180
|
+
puts rephrased_text.text
|
181
|
+
# => 'You get new rephrased text.'
|
182
|
+
```
|
183
|
+
|
184
|
+
As with translate, the text input can be a single string or an array of strings.
|
185
|
+
|
186
|
+
You can use the additional arguments to specify the writing style or tone you want for the rephrased text:
|
187
|
+
|
188
|
+
```rb
|
189
|
+
rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN', 'casual'
|
190
|
+
|
191
|
+
puts rephrased_text.text
|
192
|
+
# => 'You'll get new, rephrased text.'
|
193
|
+
```
|
194
|
+
|
195
|
+
```rb
|
196
|
+
rephrased_text = DeepL.rephrase 'you will acquire new rephrased text', 'EN', nil, 'friendly'
|
197
|
+
|
198
|
+
puts rephrased_text.text
|
199
|
+
# => 'You'll get to enjoy new, rephrased text!'
|
200
|
+
```
|
201
|
+
|
171
202
|
### Glossaries
|
172
203
|
|
173
204
|
To create a glossary, use the `glossaries.create` method. The glossary `entries` argument should be an array of text pairs. Each pair includes the source and the target translations.
|
@@ -389,6 +420,30 @@ end
|
|
389
420
|
|
390
421
|
This information is passed along when the library makes calls to the DeepL API. Both name and version are required. Please note that setting the `User-Agent` header via `deepl.configure` will override this setting, if you need to use this, please manually identify your Application in the `User-Agent` header.
|
391
422
|
|
423
|
+
## Options Constants
|
424
|
+
|
425
|
+
The available values for various possible options are provided under the `DeepL::Constants` namespace. The currently available options are
|
426
|
+
|
427
|
+
`TagHandling`
|
428
|
+
`SplitSentences`
|
429
|
+
`ModelType`
|
430
|
+
`Formality`
|
431
|
+
`WritingStyle`
|
432
|
+
`Tone`
|
433
|
+
|
434
|
+
To view all the possible options for a given constant, call `options`:
|
435
|
+
|
436
|
+
```rb
|
437
|
+
all_available_tones = DeepL::Constants::Tones.options
|
438
|
+
```
|
439
|
+
|
440
|
+
To check if a given string is a possible option for a given constant, call `valid?`:
|
441
|
+
|
442
|
+
```rb
|
443
|
+
DeepL::Constants::Tones.valid?('friendly') # true
|
444
|
+
DeepL::Constants::Tones.valid?('rude') # false
|
445
|
+
```
|
446
|
+
|
392
447
|
## Integrations
|
393
448
|
|
394
449
|
### Ruby on Rails
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.2.0
|
data/deepl-rb.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deepl-rb 3.
|
5
|
+
# stub: deepl-rb 3.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "3.
|
9
|
+
s.version = "3.2.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 = "
|
15
|
+
s.date = "2025-01-15"
|
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 = [
|
@@ -39,6 +39,13 @@ Gem::Specification.new do |s|
|
|
39
39
|
"lib/deepl.rb",
|
40
40
|
"lib/deepl/api.rb",
|
41
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",
|
42
49
|
"lib/deepl/document_api.rb",
|
43
50
|
"lib/deepl/exceptions/authorization_failed.rb",
|
44
51
|
"lib/deepl/exceptions/bad_request.rb",
|
@@ -63,6 +70,7 @@ Gem::Specification.new do |s|
|
|
63
70
|
"lib/deepl/requests/glossary/language_pairs.rb",
|
64
71
|
"lib/deepl/requests/glossary/list.rb",
|
65
72
|
"lib/deepl/requests/languages.rb",
|
73
|
+
"lib/deepl/requests/rephrase.rb",
|
66
74
|
"lib/deepl/requests/translate.rb",
|
67
75
|
"lib/deepl/requests/usage.rb",
|
68
76
|
"lib/deepl/resources/base.rb",
|
@@ -80,6 +88,7 @@ Gem::Specification.new do |s|
|
|
80
88
|
"spec/api/api_spec.rb",
|
81
89
|
"spec/api/configuration_spec.rb",
|
82
90
|
"spec/api/deepl_spec.rb",
|
91
|
+
"spec/constants/constants_spec.rb",
|
83
92
|
"spec/fixtures/vcr_cassettes/deepl_document.yml",
|
84
93
|
"spec/fixtures/vcr_cassettes/deepl_document_download.yml",
|
85
94
|
"spec/fixtures/vcr_cassettes/deepl_glossaries.yml",
|
@@ -88,6 +97,7 @@ Gem::Specification.new do |s|
|
|
88
97
|
"spec/fixtures/vcr_cassettes/deepl_usage.yml",
|
89
98
|
"spec/fixtures/vcr_cassettes/glossaries.yml",
|
90
99
|
"spec/fixtures/vcr_cassettes/languages.yml",
|
100
|
+
"spec/fixtures/vcr_cassettes/rephrase_texts.yml",
|
91
101
|
"spec/fixtures/vcr_cassettes/translate_texts.yml",
|
92
102
|
"spec/fixtures/vcr_cassettes/usage.yml",
|
93
103
|
"spec/integration_tests/document_api_spec.rb",
|
@@ -99,6 +109,7 @@ Gem::Specification.new do |s|
|
|
99
109
|
"spec/requests/glossary/language_pairs_spec.rb",
|
100
110
|
"spec/requests/glossary/list_spec.rb",
|
101
111
|
"spec/requests/languages_spec.rb",
|
112
|
+
"spec/requests/rephrase_spec.rb",
|
102
113
|
"spec/requests/translate_spec.rb",
|
103
114
|
"spec/requests/usage_spec.rb",
|
104
115
|
"spec/resources/glossary_spec.rb",
|
@@ -110,12 +121,12 @@ Gem::Specification.new do |s|
|
|
110
121
|
]
|
111
122
|
s.homepage = "https://github.com/DeepLcom/deepl-rb".freeze
|
112
123
|
s.licenses = ["MIT".freeze]
|
113
|
-
s.rubygems_version = "3.
|
124
|
+
s.rubygems_version = "3.5.3".freeze
|
114
125
|
s.summary = "Official Ruby library for the DeepL language translation API.".freeze
|
115
126
|
|
116
127
|
s.specification_version = 4
|
117
128
|
|
118
|
-
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
119
|
-
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
129
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0".freeze])
|
130
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0".freeze])
|
120
131
|
end
|
121
132
|
|
@@ -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
|
@@ -0,0 +1,20 @@
|
|
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 Tone < BaseConstant
|
9
|
+
DEFAULT = 'default'
|
10
|
+
ENTHUSIASTIC = 'enthusiastic'
|
11
|
+
FRIENDLY = 'friendly'
|
12
|
+
CONFIDENT = 'confident'
|
13
|
+
DIPLOMATIC = 'diplomatic'
|
14
|
+
PREFER_ENTHUSIASTIC = 'prefer_enthusiastic'
|
15
|
+
PREFER_FRIENDLY = 'prefer_friendly'
|
16
|
+
PREFER_CONFIDENT = 'prefer_confident'
|
17
|
+
PREFER_DIPLOMATIC = 'prefer_diplomatic'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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 WritingStyle < BaseConstant
|
9
|
+
DEFAULT = 'default'
|
10
|
+
SIMPLE = 'simple'
|
11
|
+
BUSINESS = 'business'
|
12
|
+
ACADEMIC = 'academic'
|
13
|
+
CASUAL = 'casual'
|
14
|
+
PREFER_SIMPLE = 'prefer_simple'
|
15
|
+
PREFER_BUSINESS = 'prefer_business'
|
16
|
+
PREFER_ACADEMIC = 'prefer_academic'
|
17
|
+
PREFER_CASUAL = 'prefer_casual'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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 Requests
|
8
|
+
class Rephrase < Base
|
9
|
+
attr_reader :text, :target_lang, :writing_style, :tone
|
10
|
+
|
11
|
+
def initialize(api, text, target_lang, writing_style = nil, tone = nil, options = {})
|
12
|
+
super(api, options)
|
13
|
+
@text = text
|
14
|
+
@target_lang = target_lang
|
15
|
+
@writing_style = writing_style
|
16
|
+
@tone = tone
|
17
|
+
end
|
18
|
+
|
19
|
+
def request
|
20
|
+
text_arrayified = text.is_a?(Array) ? text : [text]
|
21
|
+
payload = { text: text_arrayified, target_lang: target_lang }
|
22
|
+
payload[:writing_style] = writing_style unless writing_style.nil?
|
23
|
+
payload[:tone] = tone unless tone.nil?
|
24
|
+
build_texts(*execute_request_with_retries(post_request(payload)))
|
25
|
+
end
|
26
|
+
|
27
|
+
def details
|
28
|
+
"HTTP Headers: #{headers}\nPayload #{{ text: text, target_lang: target_lang,
|
29
|
+
writing_style: writing_style, tone: tone }}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"POST #{uri.request_uri}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def build_texts(request, response)
|
39
|
+
data = JSON.parse(response.body)
|
40
|
+
|
41
|
+
texts = data['improvements'].map do |improvement|
|
42
|
+
Resources::Text.new(improvement['text'], improvement['detected_source_language'], nil,
|
43
|
+
request, response)
|
44
|
+
end
|
45
|
+
|
46
|
+
texts.size == 1 ? texts.first : texts
|
47
|
+
end
|
48
|
+
|
49
|
+
def path
|
50
|
+
'write/rephrase'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/deepl.rb
CHANGED
@@ -34,6 +34,7 @@ require 'deepl/requests/glossary/list'
|
|
34
34
|
require 'deepl/requests/languages'
|
35
35
|
require 'deepl/requests/translate'
|
36
36
|
require 'deepl/requests/usage'
|
37
|
+
require 'deepl/requests/rephrase'
|
37
38
|
|
38
39
|
# -- Responses and resources
|
39
40
|
require 'deepl/resources/base'
|
@@ -49,6 +50,15 @@ require 'deepl/resources/usage'
|
|
49
50
|
require 'deepl/utils/exception_builder'
|
50
51
|
require 'deepl/utils/backoff_timer'
|
51
52
|
|
53
|
+
# -- Constants
|
54
|
+
require 'deepl/constants/base_constant'
|
55
|
+
require 'deepl/constants/formality'
|
56
|
+
require 'deepl/constants/model_type'
|
57
|
+
require 'deepl/constants/split_sentences'
|
58
|
+
require 'deepl/constants/tag_handling'
|
59
|
+
require 'deepl/constants/tone'
|
60
|
+
require 'deepl/constants/writing_style'
|
61
|
+
|
52
62
|
# -- HTTP Utils
|
53
63
|
require 'http_client_options'
|
54
64
|
|
@@ -0,0 +1,158 @@
|
|
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::Constants' do
|
9
|
+
describe DeepL::Constants::Tone do
|
10
|
+
subject(:tone) { described_class }
|
11
|
+
|
12
|
+
it 'includes all expected tone values' do # rubocop:disable RSpec/ExampleLength
|
13
|
+
expect(tone.options).to contain_exactly(
|
14
|
+
'confident',
|
15
|
+
'default',
|
16
|
+
'diplomatic',
|
17
|
+
'enthusiastic',
|
18
|
+
'friendly',
|
19
|
+
'prefer_confident',
|
20
|
+
'prefer_diplomatic',
|
21
|
+
'prefer_enthusiastic',
|
22
|
+
'prefer_friendly'
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'validates correct tone values' do
|
27
|
+
expect(tone.valid?('enthusiastic')).to be true
|
28
|
+
expect(tone.valid?('friendly')).to be true
|
29
|
+
expect(tone.valid?('confident')).to be true
|
30
|
+
expect(tone.valid?('diplomatic')).to be true
|
31
|
+
expect(tone.valid?('default')).to be true
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'invalidates incorrect tone values' do
|
35
|
+
expect(tone.valid?('angry')).to be false
|
36
|
+
expect(tone.valid?('')).to be false
|
37
|
+
expect(tone.valid?(nil)).to be false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe DeepL::Constants::WritingStyle do
|
42
|
+
subject(:writing_style) { described_class }
|
43
|
+
|
44
|
+
it 'includes all expected writing style values' do # rubocop:disable RSpec/ExampleLength
|
45
|
+
expect(writing_style.options).to contain_exactly(
|
46
|
+
'default',
|
47
|
+
'simple',
|
48
|
+
'business',
|
49
|
+
'academic',
|
50
|
+
'casual',
|
51
|
+
'prefer_academic',
|
52
|
+
'prefer_business',
|
53
|
+
'prefer_casual',
|
54
|
+
'prefer_simple'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'validates correct writing style values' do
|
59
|
+
expect(writing_style.valid?('simple')).to be true
|
60
|
+
expect(writing_style.valid?('business')).to be true
|
61
|
+
expect(writing_style.valid?('academic')).to be true
|
62
|
+
expect(writing_style.valid?('casual')).to be true
|
63
|
+
expect(writing_style.valid?('default')).to be true
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'invalidates incorrect writing style values' do
|
67
|
+
expect(writing_style.valid?('wordy')).to be false
|
68
|
+
expect(writing_style.valid?('')).to be false
|
69
|
+
expect(writing_style.valid?(nil)).to be false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe DeepL::Constants::TagHandling do
|
74
|
+
subject(:tag_handling) { described_class }
|
75
|
+
|
76
|
+
it 'includes all expected tag handling values' do
|
77
|
+
expect(tag_handling.options).to contain_exactly('xml', 'html')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'validates correct tag handling values' do
|
81
|
+
expect(tag_handling.valid?('xml')).to be true
|
82
|
+
expect(tag_handling.valid?('html')).to be true
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'invalidates incorrect tag handling values' do
|
86
|
+
expect(tag_handling.valid?('json')).to be false
|
87
|
+
expect(tag_handling.valid?('')).to be false
|
88
|
+
expect(tag_handling.valid?(nil)).to be false
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe DeepL::Constants::SplitSentences do
|
93
|
+
subject(:split_sentences) { described_class }
|
94
|
+
|
95
|
+
it 'includes all expected split sentences values' do
|
96
|
+
expect(split_sentences.options).to contain_exactly('0', '1', 'nonewlines')
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'validates correct split sentences values' do
|
100
|
+
expect(split_sentences.valid?('0')).to be true
|
101
|
+
expect(split_sentences.valid?('1')).to be true
|
102
|
+
expect(split_sentences.valid?('nonewlines')).to be true
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'invalidates incorrect split sentences values' do
|
106
|
+
expect(split_sentences.valid?('2')).to be false
|
107
|
+
expect(split_sentences.valid?('')).to be false
|
108
|
+
expect(split_sentences.valid?(nil)).to be false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe DeepL::Constants::ModelType do
|
113
|
+
subject(:model_type) { described_class }
|
114
|
+
|
115
|
+
it 'includes all expected model type values' do
|
116
|
+
expect(model_type.options).to contain_exactly(
|
117
|
+
'quality_optimized',
|
118
|
+
'prefer_quality_optimized',
|
119
|
+
'latency_optimized'
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'validates correct model type values' do
|
124
|
+
expect(model_type.valid?('quality_optimized')).to be true
|
125
|
+
expect(model_type.valid?('prefer_quality_optimized')).to be true
|
126
|
+
expect(model_type.valid?('latency_optimized')).to be true
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'invalidates incorrect model type values' do
|
130
|
+
expect(model_type.valid?('speed_optimized')).to be false
|
131
|
+
expect(model_type.valid?('')).to be false
|
132
|
+
expect(model_type.valid?(nil)).to be false
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe DeepL::Constants::Formality do
|
137
|
+
subject(:formality) { described_class }
|
138
|
+
|
139
|
+
it 'includes all expected formality values' do
|
140
|
+
expect(formality.options).to contain_exactly('default', 'more', 'less', 'prefer_more',
|
141
|
+
'prefer_less')
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'validates correct formality values' do
|
145
|
+
expect(formality.valid?('default')).to be true
|
146
|
+
expect(formality.valid?('more')).to be true
|
147
|
+
expect(formality.valid?('less')).to be true
|
148
|
+
expect(formality.valid?('prefer_more')).to be true
|
149
|
+
expect(formality.valid?('prefer_less')).to be true
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'invalidates incorrect formality values' do
|
153
|
+
expect(formality.valid?('neutral')).to be false
|
154
|
+
expect(formality.valid?('')).to be false
|
155
|
+
expect(formality.valid?(nil)).to be false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,401 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
9
|
+
himself transformed."],"target_lang":"EN"}'
|
10
|
+
headers:
|
11
|
+
Authorization:
|
12
|
+
- DeepL-Auth-Key VALID_TOKEN
|
13
|
+
User-Agent:
|
14
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
15
|
+
Content-Type:
|
16
|
+
- application/json
|
17
|
+
Accept-Encoding:
|
18
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
19
|
+
Accept:
|
20
|
+
- "*/*"
|
21
|
+
response:
|
22
|
+
status:
|
23
|
+
code: 200
|
24
|
+
message: OK
|
25
|
+
headers:
|
26
|
+
Date:
|
27
|
+
- Fri, 10 Jan 2025 07:00:45 GMT
|
28
|
+
Content-Type:
|
29
|
+
- application/json; charset=utf-8
|
30
|
+
Transfer-Encoding:
|
31
|
+
- chunked
|
32
|
+
Vary:
|
33
|
+
- Accept-Encoding
|
34
|
+
X-Trace-Id:
|
35
|
+
- '09daf98547c94050b68e39cf38b0fe7d'
|
36
|
+
Strict-Transport-Security:
|
37
|
+
- max-age=63072000; includeSubDomains; preload
|
38
|
+
Server-Timing:
|
39
|
+
- l7_lb_tls;dur=95, l7_lb_idle;dur=3, l7_lb_receive;dur=0, l7_lb_total;dur=378
|
40
|
+
Access-Control-Expose-Headers:
|
41
|
+
- Server-Timing, X-Trace-ID
|
42
|
+
body:
|
43
|
+
encoding: ASCII-8BIT
|
44
|
+
string: '{"improvements":[{"text":"When Gregor Samsa awoke one morning from
|
45
|
+
troubled dreams, he found himself transformed.","detected_source_language":"en","target_language":"en-US"}]}'
|
46
|
+
recorded_at: Fri, 10 Jan 2025 07:00:45 GMT
|
47
|
+
- request:
|
48
|
+
method: post
|
49
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
53
|
+
himself transformed.","He lay on his armour-like back, and if he lifted his
|
54
|
+
head a little"],"target_lang":"EN"}'
|
55
|
+
headers:
|
56
|
+
Authorization:
|
57
|
+
- DeepL-Auth-Key VALID_TOKEN
|
58
|
+
User-Agent:
|
59
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
60
|
+
Content-Type:
|
61
|
+
- application/json
|
62
|
+
Accept-Encoding:
|
63
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
64
|
+
Accept:
|
65
|
+
- "*/*"
|
66
|
+
response:
|
67
|
+
status:
|
68
|
+
code: 200
|
69
|
+
message: OK
|
70
|
+
headers:
|
71
|
+
Date:
|
72
|
+
- Fri, 10 Jan 2025 07:00:45 GMT
|
73
|
+
Content-Type:
|
74
|
+
- application/json; charset=utf-8
|
75
|
+
Transfer-Encoding:
|
76
|
+
- chunked
|
77
|
+
Vary:
|
78
|
+
- Accept-Encoding
|
79
|
+
X-Trace-Id:
|
80
|
+
- df25db169c5f4c198ff7b5a319a16669
|
81
|
+
Strict-Transport-Security:
|
82
|
+
- max-age=63072000; includeSubDomains; preload
|
83
|
+
Server-Timing:
|
84
|
+
- l7_lb_tls;dur=95, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=423
|
85
|
+
Access-Control-Expose-Headers:
|
86
|
+
- Server-Timing, X-Trace-ID
|
87
|
+
body:
|
88
|
+
encoding: ASCII-8BIT
|
89
|
+
string: '{"improvements":[{"text":"When Gregor Samsa awoke one morning from
|
90
|
+
troubled dreams, he found himself transformed.","detected_source_language":"en","target_language":"en-US"},{"text":"He
|
91
|
+
lay on his armor-like back, and when he lifted his head a little","detected_source_language":"en","target_language":"en-US"}]}'
|
92
|
+
recorded_at: Fri, 10 Jan 2025 07:00:45 GMT
|
93
|
+
- request:
|
94
|
+
method: post
|
95
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
96
|
+
body:
|
97
|
+
encoding: UTF-8
|
98
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
99
|
+
himself transformed."],"target_lang":"EN","tone":"friendly"}'
|
100
|
+
headers:
|
101
|
+
Authorization:
|
102
|
+
- DeepL-Auth-Key VALID_TOKEN
|
103
|
+
User-Agent:
|
104
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
105
|
+
Content-Type:
|
106
|
+
- application/json
|
107
|
+
Accept-Encoding:
|
108
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
109
|
+
Accept:
|
110
|
+
- "*/*"
|
111
|
+
response:
|
112
|
+
status:
|
113
|
+
code: 200
|
114
|
+
message: OK
|
115
|
+
headers:
|
116
|
+
Date:
|
117
|
+
- Fri, 10 Jan 2025 07:00:46 GMT
|
118
|
+
Content-Type:
|
119
|
+
- application/json; charset=utf-8
|
120
|
+
Transfer-Encoding:
|
121
|
+
- chunked
|
122
|
+
Vary:
|
123
|
+
- Accept-Encoding
|
124
|
+
X-Trace-Id:
|
125
|
+
- 14fdbaa36544495a993136451b65e52b
|
126
|
+
Strict-Transport-Security:
|
127
|
+
- max-age=63072000; includeSubDomains; preload
|
128
|
+
Server-Timing:
|
129
|
+
- l7_lb_tls;dur=94, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=460
|
130
|
+
Access-Control-Expose-Headers:
|
131
|
+
- Server-Timing, X-Trace-ID
|
132
|
+
body:
|
133
|
+
encoding: ASCII-8BIT
|
134
|
+
string: '{"improvements":[{"text":"One morning, Gregor Samsa woke up from restless
|
135
|
+
dreams to find himself in a strange new form.","detected_source_language":"en","target_language":"en-US"}]}'
|
136
|
+
recorded_at: Fri, 10 Jan 2025 07:00:46 GMT
|
137
|
+
- request:
|
138
|
+
method: post
|
139
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
140
|
+
body:
|
141
|
+
encoding: UTF-8
|
142
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
143
|
+
himself transformed.","He lay on his armour-like back, and if he lifted his
|
144
|
+
head a little"],"target_lang":"EN","tone":"friendly"}'
|
145
|
+
headers:
|
146
|
+
Authorization:
|
147
|
+
- DeepL-Auth-Key VALID_TOKEN
|
148
|
+
User-Agent:
|
149
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
150
|
+
Content-Type:
|
151
|
+
- application/json
|
152
|
+
Accept-Encoding:
|
153
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
154
|
+
Accept:
|
155
|
+
- "*/*"
|
156
|
+
response:
|
157
|
+
status:
|
158
|
+
code: 200
|
159
|
+
message: OK
|
160
|
+
headers:
|
161
|
+
Date:
|
162
|
+
- Fri, 10 Jan 2025 07:00:46 GMT
|
163
|
+
Content-Type:
|
164
|
+
- application/json; charset=utf-8
|
165
|
+
Transfer-Encoding:
|
166
|
+
- chunked
|
167
|
+
Vary:
|
168
|
+
- Accept-Encoding
|
169
|
+
X-Trace-Id:
|
170
|
+
- a31d9cca4073414c9be843fffed914c3
|
171
|
+
Strict-Transport-Security:
|
172
|
+
- max-age=63072000; includeSubDomains; preload
|
173
|
+
Server-Timing:
|
174
|
+
- l7_lb_tls;dur=93, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=413
|
175
|
+
Access-Control-Expose-Headers:
|
176
|
+
- Server-Timing, X-Trace-ID
|
177
|
+
body:
|
178
|
+
encoding: ASCII-8BIT
|
179
|
+
string: '{"improvements":[{"text":"One morning, Gregor Samsa woke up from restless
|
180
|
+
dreams to find himself in a strange new form.","detected_source_language":"en","target_language":"en-US"},{"text":"He
|
181
|
+
was lying on his armor-like back, and if he lifted his head just a little
|
182
|
+
bit...","detected_source_language":"en","target_language":"en-US"}]}'
|
183
|
+
recorded_at: Fri, 10 Jan 2025 07:00:47 GMT
|
184
|
+
- request:
|
185
|
+
method: post
|
186
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
187
|
+
body:
|
188
|
+
encoding: UTF-8
|
189
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
190
|
+
himself transformed."],"target_lang":"EN","writing_style":"business"}'
|
191
|
+
headers:
|
192
|
+
Authorization:
|
193
|
+
- DeepL-Auth-Key VALID_TOKEN
|
194
|
+
User-Agent:
|
195
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
196
|
+
Content-Type:
|
197
|
+
- application/json
|
198
|
+
Accept-Encoding:
|
199
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
200
|
+
Accept:
|
201
|
+
- "*/*"
|
202
|
+
response:
|
203
|
+
status:
|
204
|
+
code: 200
|
205
|
+
message: OK
|
206
|
+
headers:
|
207
|
+
Date:
|
208
|
+
- Fri, 10 Jan 2025 07:00:47 GMT
|
209
|
+
Content-Type:
|
210
|
+
- application/json; charset=utf-8
|
211
|
+
Transfer-Encoding:
|
212
|
+
- chunked
|
213
|
+
Vary:
|
214
|
+
- Accept-Encoding
|
215
|
+
X-Trace-Id:
|
216
|
+
- 58d0bbf1167f40b2a62f87c2a6d7dda3
|
217
|
+
Strict-Transport-Security:
|
218
|
+
- max-age=63072000; includeSubDomains; preload
|
219
|
+
Server-Timing:
|
220
|
+
- l7_lb_tls;dur=98, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=385
|
221
|
+
Access-Control-Expose-Headers:
|
222
|
+
- Server-Timing, X-Trace-ID
|
223
|
+
body:
|
224
|
+
encoding: ASCII-8BIT
|
225
|
+
string: '{"improvements":[{"text":"Gregor Samsa awoke one morning, having had
|
226
|
+
disturbing dreams, to find himself transformed.","detected_source_language":"en","target_language":"en-US"}]}'
|
227
|
+
recorded_at: Fri, 10 Jan 2025 07:00:47 GMT
|
228
|
+
- request:
|
229
|
+
method: post
|
230
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
231
|
+
body:
|
232
|
+
encoding: UTF-8
|
233
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
234
|
+
himself transformed.","He lay on his armour-like back, and if he lifted his
|
235
|
+
head a little"],"target_lang":"EN","writing_style":"business"}'
|
236
|
+
headers:
|
237
|
+
Authorization:
|
238
|
+
- DeepL-Auth-Key VALID_TOKEN
|
239
|
+
User-Agent:
|
240
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
241
|
+
Content-Type:
|
242
|
+
- application/json
|
243
|
+
Accept-Encoding:
|
244
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
245
|
+
Accept:
|
246
|
+
- "*/*"
|
247
|
+
response:
|
248
|
+
status:
|
249
|
+
code: 200
|
250
|
+
message: OK
|
251
|
+
headers:
|
252
|
+
Date:
|
253
|
+
- Fri, 10 Jan 2025 07:00:48 GMT
|
254
|
+
Content-Type:
|
255
|
+
- application/json; charset=utf-8
|
256
|
+
Transfer-Encoding:
|
257
|
+
- chunked
|
258
|
+
Vary:
|
259
|
+
- Accept-Encoding
|
260
|
+
X-Trace-Id:
|
261
|
+
- 37a69ff78833465cbc9ddadd4f9aca36
|
262
|
+
Strict-Transport-Security:
|
263
|
+
- max-age=63072000; includeSubDomains; preload
|
264
|
+
Server-Timing:
|
265
|
+
- l7_lb_tls;dur=96, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=374
|
266
|
+
Access-Control-Expose-Headers:
|
267
|
+
- Server-Timing, X-Trace-ID
|
268
|
+
body:
|
269
|
+
encoding: ASCII-8BIT
|
270
|
+
string: '{"improvements":[{"text":"Gregor Samsa awoke one morning, having had
|
271
|
+
disturbing dreams, to find himself transformed.","detected_source_language":"en","target_language":"en-US"},{"text":"He
|
272
|
+
was positioned on his back, which was similar to armor. If he lifted his head
|
273
|
+
slightly,","detected_source_language":"en","target_language":"en-US"}]}'
|
274
|
+
recorded_at: Fri, 10 Jan 2025 07:00:48 GMT
|
275
|
+
- request:
|
276
|
+
method: post
|
277
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
278
|
+
body:
|
279
|
+
encoding: UTF-8
|
280
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
281
|
+
himself transformed."],"target_lang":"EN","writing_style":"angry"}'
|
282
|
+
headers:
|
283
|
+
Authorization:
|
284
|
+
- DeepL-Auth-Key VALID_TOKEN
|
285
|
+
User-Agent:
|
286
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
287
|
+
Content-Type:
|
288
|
+
- application/json
|
289
|
+
Accept-Encoding:
|
290
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
291
|
+
Accept:
|
292
|
+
- "*/*"
|
293
|
+
response:
|
294
|
+
status:
|
295
|
+
code: 400
|
296
|
+
message: Bad Request
|
297
|
+
headers:
|
298
|
+
Date:
|
299
|
+
- Fri, 10 Jan 2025 07:00:48 GMT
|
300
|
+
Content-Type:
|
301
|
+
- application/json; charset=utf-8
|
302
|
+
Transfer-Encoding:
|
303
|
+
- chunked
|
304
|
+
X-Trace-Id:
|
305
|
+
- b406cc026c004d4c80d76131df636d8a
|
306
|
+
Strict-Transport-Security:
|
307
|
+
- max-age=63072000; includeSubDomains; preload
|
308
|
+
Server-Timing:
|
309
|
+
- l7_lb_tls;dur=98, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=109
|
310
|
+
Access-Control-Expose-Headers:
|
311
|
+
- Server-Timing, X-Trace-ID
|
312
|
+
body:
|
313
|
+
encoding: UTF-8
|
314
|
+
string: '{"message":"Bad request. Reason: Unsupported value for field writing_style."}'
|
315
|
+
recorded_at: Fri, 10 Jan 2025 07:00:48 GMT
|
316
|
+
- request:
|
317
|
+
method: post
|
318
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
319
|
+
body:
|
320
|
+
encoding: UTF-8
|
321
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
322
|
+
himself transformed."],"target_lang":"EN","writing_style":"business","tone":"friendly"}'
|
323
|
+
headers:
|
324
|
+
Authorization:
|
325
|
+
- DeepL-Auth-Key VALID_TOKEN
|
326
|
+
User-Agent:
|
327
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
328
|
+
Content-Type:
|
329
|
+
- application/json
|
330
|
+
Accept-Encoding:
|
331
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
332
|
+
Accept:
|
333
|
+
- "*/*"
|
334
|
+
response:
|
335
|
+
status:
|
336
|
+
code: 400
|
337
|
+
message: Bad Request
|
338
|
+
headers:
|
339
|
+
Date:
|
340
|
+
- Fri, 10 Jan 2025 07:00:48 GMT
|
341
|
+
Content-Type:
|
342
|
+
- application/json; charset=utf-8
|
343
|
+
Transfer-Encoding:
|
344
|
+
- chunked
|
345
|
+
X-Trace-Id:
|
346
|
+
- 1b7680d714c24de49ded702b382c69b0
|
347
|
+
Strict-Transport-Security:
|
348
|
+
- max-age=63072000; includeSubDomains; preload
|
349
|
+
Server-Timing:
|
350
|
+
- l7_lb_tls;dur=98, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=105
|
351
|
+
Access-Control-Expose-Headers:
|
352
|
+
- Server-Timing, X-Trace-ID
|
353
|
+
body:
|
354
|
+
encoding: UTF-8
|
355
|
+
string: '{"message":"Bad request. Reason: Both writing_style and tone defined.
|
356
|
+
Currently only style OR tone can be chosen for a single request.."}'
|
357
|
+
recorded_at: Fri, 10 Jan 2025 07:00:48 GMT
|
358
|
+
- request:
|
359
|
+
method: post
|
360
|
+
uri: https://api.deepl.com/v2/write/rephrase
|
361
|
+
body:
|
362
|
+
encoding: UTF-8
|
363
|
+
string: '{"text":["As Gregor Samsa awoke one morning from uneasy dreams he found
|
364
|
+
himself transformed."],"target_lang":"EN"}'
|
365
|
+
headers:
|
366
|
+
Authorization:
|
367
|
+
- DeepL-Auth-Key invalid
|
368
|
+
User-Agent:
|
369
|
+
- deepl-ruby/3.0.2 (darwin24) ruby/3.3.0
|
370
|
+
Content-Type:
|
371
|
+
- application/json
|
372
|
+
Accept-Encoding:
|
373
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
374
|
+
Accept:
|
375
|
+
- "*/*"
|
376
|
+
response:
|
377
|
+
status:
|
378
|
+
code: 403
|
379
|
+
message: Forbidden
|
380
|
+
headers:
|
381
|
+
Date:
|
382
|
+
- Fri, 10 Jan 2025 07:00:48 GMT
|
383
|
+
Content-Type:
|
384
|
+
- application/json; charset=utf-8
|
385
|
+
Transfer-Encoding:
|
386
|
+
- chunked
|
387
|
+
Vary:
|
388
|
+
- Accept-Encoding
|
389
|
+
X-Trace-Id:
|
390
|
+
- 568ef89e665f499ebcbc62b90ba09019
|
391
|
+
Strict-Transport-Security:
|
392
|
+
- max-age=63072000; includeSubDomains; preload
|
393
|
+
Server-Timing:
|
394
|
+
- l7_lb_tls;dur=121, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=132
|
395
|
+
Access-Control-Expose-Headers:
|
396
|
+
- Server-Timing, X-Trace-ID
|
397
|
+
body:
|
398
|
+
encoding: ASCII-8BIT
|
399
|
+
string: '{"message":"Invalid API key."}'
|
400
|
+
recorded_at: Fri, 10 Jan 2025 07:00:48 GMT
|
401
|
+
recorded_with: VCR 6.3.1
|
@@ -0,0 +1,172 @@
|
|
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
|
+
subject(:rephrase) { described_class.new(api, text, target_lang, writing_style, tone, 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(:text) do
|
19
|
+
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.'
|
20
|
+
end
|
21
|
+
let(:target_lang) { 'EN' }
|
22
|
+
let(:writing_style) { nil }
|
23
|
+
let(:tone) { nil }
|
24
|
+
let(:options) { {} }
|
25
|
+
|
26
|
+
describe '#request' do
|
27
|
+
around do |example|
|
28
|
+
VCR.use_cassette('rephrase_texts') { example.call }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without a style or tone applied' do
|
32
|
+
context 'with a string as input' do
|
33
|
+
it 'returns a valid response as a DeepL Text resource' do
|
34
|
+
original_length = text.length
|
35
|
+
response_text = rephrase.request
|
36
|
+
|
37
|
+
expect(response_text).to be_a(DeepL::Resources::Text)
|
38
|
+
expect(response_text.text.length).not_to eq(original_length)
|
39
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'with an array of texts as input' do
|
44
|
+
let(:text) do
|
45
|
+
[
|
46
|
+
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
47
|
+
'He lay on his armour-like back, and if he lifted his head a little'
|
48
|
+
]
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns a valid response as an array of DeepL Text resources' do
|
52
|
+
response_texts = rephrase.request
|
53
|
+
|
54
|
+
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
55
|
+
response_texts.each_with_index do |response_text, index|
|
56
|
+
expect(response_text.text.length).not_to eq(text[index].length)
|
57
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with a valid tone applied' do
|
64
|
+
let(:tone) { 'friendly' }
|
65
|
+
|
66
|
+
context 'with a string as input' do
|
67
|
+
it 'returns a valid response with a string as text input' do
|
68
|
+
original_length = text.length
|
69
|
+
response_text = rephrase.request
|
70
|
+
|
71
|
+
expect(response_text).to be_a(DeepL::Resources::Text)
|
72
|
+
expect(response_text.text.length).not_to eq(original_length)
|
73
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'with an array of texts as input' do
|
78
|
+
let(:text) do
|
79
|
+
[
|
80
|
+
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
81
|
+
'He lay on his armour-like back, and if he lifted his head a little'
|
82
|
+
]
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'returns an array of valid text objects' do
|
86
|
+
response_texts = rephrase.request
|
87
|
+
|
88
|
+
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
89
|
+
response_texts.each_with_index do |response_text, index|
|
90
|
+
expect(response_text.text.length).not_to eq(text[index].length)
|
91
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'with a valid writing style applied' do
|
98
|
+
let(:writing_style) { 'business' }
|
99
|
+
|
100
|
+
context 'with a string as input' do
|
101
|
+
it 'returns a valid response with a string as text input' do
|
102
|
+
original_length = text.length
|
103
|
+
response_text = rephrase.request
|
104
|
+
|
105
|
+
expect(response_text).to be_a(DeepL::Resources::Text)
|
106
|
+
expect(response_text.text.length).not_to eq(original_length)
|
107
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'with an array of texts as input' do
|
112
|
+
let(:text) do
|
113
|
+
[
|
114
|
+
'As Gregor Samsa awoke one morning from uneasy dreams he found himself transformed.',
|
115
|
+
'He lay on his armour-like back, and if he lifted his head a little'
|
116
|
+
]
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns an array of valid text objects' do
|
120
|
+
response_texts = rephrase.request
|
121
|
+
|
122
|
+
expect(response_texts).to all(be_a(DeepL::Resources::Text))
|
123
|
+
response_texts.each_with_index do |response_text, index|
|
124
|
+
expect(response_text.text.length).not_to eq(text[index].length)
|
125
|
+
expect(response_text.detected_source_language.upcase).to eq('EN')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'with a writing style or tone from the provided constants applied' do
|
132
|
+
let(:writing_style) { DeepL::Constants::WritingStyle::BUSINESS }
|
133
|
+
let(:tone) { DeepL::Constants::Tone::FRIENDLY }
|
134
|
+
|
135
|
+
it 'has the correct writing style and tone applied' do
|
136
|
+
expect(rephrase.writing_style).to eq('business')
|
137
|
+
expect(rephrase.tone).to eq('friendly')
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'with an invalid writing style applied' do
|
142
|
+
let(:writing_style) { 'angry' }
|
143
|
+
|
144
|
+
it 'raises a bad request error' do
|
145
|
+
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when both writing style and tone are applied' do
|
150
|
+
let(:writing_style) { 'business' }
|
151
|
+
let(:tone) { 'friendly' }
|
152
|
+
|
153
|
+
it 'raises a bad request error' do
|
154
|
+
expect { rephrase.request }.to raise_error(DeepL::Exceptions::BadRequest)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'when performing a bad request' do
|
159
|
+
context 'when using an invalid token' do
|
160
|
+
let(:api) do
|
161
|
+
api = build_deepl_api
|
162
|
+
api.configuration.auth_key = 'invalid'
|
163
|
+
api
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'raises an unauthorized error' do
|
167
|
+
expect { rephrase.request }.to raise_error(DeepL::Exceptions::AuthorizationFailed)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -121,6 +121,17 @@ describe DeepL::Requests::Translate do
|
|
121
121
|
request = described_class.new(api, nil, nil, nil, split_sentences: '1')
|
122
122
|
expect(request.options[:split_sentences]).to eq('1')
|
123
123
|
end
|
124
|
+
|
125
|
+
it 'works with provided constants' do
|
126
|
+
request = described_class.new(
|
127
|
+
api,
|
128
|
+
nil,
|
129
|
+
nil,
|
130
|
+
nil,
|
131
|
+
split_sentences: DeepL::Constants::SplitSentences::SPLIT_ON_PUNCTUATION_AND_NEWLINES
|
132
|
+
)
|
133
|
+
expect(request.options[:split_sentences]).to eq('1')
|
134
|
+
end
|
124
135
|
end
|
125
136
|
|
126
137
|
context 'when using `preserve_formatting` options' do
|
@@ -189,6 +200,12 @@ describe DeepL::Requests::Translate do
|
|
189
200
|
request = described_class.new(api, nil, nil, nil, formality: 'more')
|
190
201
|
expect(request.options[:formality]).to eq('more')
|
191
202
|
end
|
203
|
+
|
204
|
+
it 'works with provided constants' do
|
205
|
+
request = described_class.new(api, nil, nil, nil,
|
206
|
+
formality: DeepL::Constants::Formality::MORE)
|
207
|
+
expect(request.options[:formality]).to eq('more')
|
208
|
+
end
|
192
209
|
end
|
193
210
|
|
194
211
|
context 'when using `model_type` options' do
|
@@ -201,6 +218,12 @@ describe DeepL::Requests::Translate do
|
|
201
218
|
request = described_class.new(api, nil, nil, nil, model_type: 'latency_optimized')
|
202
219
|
expect(request.options[:model_type]).to eq('latency_optimized')
|
203
220
|
end
|
221
|
+
|
222
|
+
it 'works with provided constants' do
|
223
|
+
request = described_class.new(api, nil, nil, nil,
|
224
|
+
model_type: DeepL::Constants::ModelType::LATENCY_OPTIMIZED)
|
225
|
+
expect(request.options[:model_type]).to eq('latency_optimized')
|
226
|
+
end
|
204
227
|
end
|
205
228
|
end
|
206
229
|
|
data/spec/spec_helper.rb
CHANGED
@@ -57,9 +57,13 @@ VCR.configure do |config|
|
|
57
57
|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
58
58
|
config.hook_into :webmock
|
59
59
|
config.filter_sensitive_data('VALID_TOKEN') { ENV.fetch('DEEPL_AUTH_KEY', nil) }
|
60
|
+
|
61
|
+
# to record new or missing VCR cassettes, call rspec like this:
|
62
|
+
# $ VCR_RECORD_MODE=new_episodes bundle exec rspec
|
63
|
+
|
64
|
+
record_mode = ENV['VCR_RECORD_MODE'] ? ENV['VCR_RECORD_MODE'].to_sym : :none
|
60
65
|
config.default_cassette_options = {
|
61
|
-
|
62
|
-
# record: :new_episodes,
|
66
|
+
record: record_mode,
|
63
67
|
match_requests_on: [:method, uri_ignoring_deepl_api_subdomain, :body,
|
64
68
|
headers_ignoring_user_agent]
|
65
69
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deepl-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DeepL SE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|
@@ -66,6 +66,13 @@ files:
|
|
66
66
|
- lib/deepl.rb
|
67
67
|
- lib/deepl/api.rb
|
68
68
|
- lib/deepl/configuration.rb
|
69
|
+
- lib/deepl/constants/base_constant.rb
|
70
|
+
- lib/deepl/constants/formality.rb
|
71
|
+
- lib/deepl/constants/model_type.rb
|
72
|
+
- lib/deepl/constants/split_sentences.rb
|
73
|
+
- lib/deepl/constants/tag_handling.rb
|
74
|
+
- lib/deepl/constants/tone.rb
|
75
|
+
- lib/deepl/constants/writing_style.rb
|
69
76
|
- lib/deepl/document_api.rb
|
70
77
|
- lib/deepl/exceptions/authorization_failed.rb
|
71
78
|
- lib/deepl/exceptions/bad_request.rb
|
@@ -90,6 +97,7 @@ files:
|
|
90
97
|
- lib/deepl/requests/glossary/language_pairs.rb
|
91
98
|
- lib/deepl/requests/glossary/list.rb
|
92
99
|
- lib/deepl/requests/languages.rb
|
100
|
+
- lib/deepl/requests/rephrase.rb
|
93
101
|
- lib/deepl/requests/translate.rb
|
94
102
|
- lib/deepl/requests/usage.rb
|
95
103
|
- lib/deepl/resources/base.rb
|
@@ -107,6 +115,7 @@ files:
|
|
107
115
|
- spec/api/api_spec.rb
|
108
116
|
- spec/api/configuration_spec.rb
|
109
117
|
- spec/api/deepl_spec.rb
|
118
|
+
- spec/constants/constants_spec.rb
|
110
119
|
- spec/fixtures/vcr_cassettes/deepl_document.yml
|
111
120
|
- spec/fixtures/vcr_cassettes/deepl_document_download.yml
|
112
121
|
- spec/fixtures/vcr_cassettes/deepl_glossaries.yml
|
@@ -115,6 +124,7 @@ files:
|
|
115
124
|
- spec/fixtures/vcr_cassettes/deepl_usage.yml
|
116
125
|
- spec/fixtures/vcr_cassettes/glossaries.yml
|
117
126
|
- spec/fixtures/vcr_cassettes/languages.yml
|
127
|
+
- spec/fixtures/vcr_cassettes/rephrase_texts.yml
|
118
128
|
- spec/fixtures/vcr_cassettes/translate_texts.yml
|
119
129
|
- spec/fixtures/vcr_cassettes/usage.yml
|
120
130
|
- spec/integration_tests/document_api_spec.rb
|
@@ -126,6 +136,7 @@ files:
|
|
126
136
|
- spec/requests/glossary/language_pairs_spec.rb
|
127
137
|
- spec/requests/glossary/list_spec.rb
|
128
138
|
- spec/requests/languages_spec.rb
|
139
|
+
- spec/requests/rephrase_spec.rb
|
129
140
|
- spec/requests/translate_spec.rb
|
130
141
|
- spec/requests/usage_spec.rb
|
131
142
|
- spec/resources/glossary_spec.rb
|
@@ -157,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
168
|
- !ruby/object:Gem::Version
|
158
169
|
version: '0'
|
159
170
|
requirements: []
|
160
|
-
rubygems_version: 3.
|
171
|
+
rubygems_version: 3.5.3
|
161
172
|
signing_key:
|
162
173
|
specification_version: 4
|
163
174
|
summary: Official Ruby library for the DeepL language translation API.
|