deepl-rb 3.0.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,30 @@ 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
209
+ end
210
+
211
+ context 'when using `model_type` options' do
212
+ it 'works with a nil value' do
213
+ request = described_class.new(api, nil, nil, nil, model_type: nil)
214
+ expect(request.options[:model_type]).to be_nil
215
+ end
216
+
217
+ it 'works with a string' do
218
+ request = described_class.new(api, nil, nil, nil, model_type: 'latency_optimized')
219
+ expect(request.options[:model_type]).to eq('latency_optimized')
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
192
227
  end
193
228
  end
194
229
 
@@ -316,6 +351,21 @@ describe DeepL::Requests::Translate do
316
351
  end
317
352
  end
318
353
 
354
+ context 'when performing a request with a model type' do
355
+ let(:target_lang) { 'DE' }
356
+
357
+ %w[quality_optimized latency_optimized prefer_quality_optimized].each do |model_type_str|
358
+ it "translates correctly with #{model_type_str} models" do
359
+ options = { model_type: model_type_str }
360
+ translate = described_class.new(api, text, source_lang, target_lang, options)
361
+ res = translate.request
362
+ expect(res).to be_a(DeepL::Resources::Text)
363
+ expected_model_type = model_type_str.sub(/^prefer_/, '')
364
+ expect(res.model_type_used).to eq(expected_model_type)
365
+ end
366
+ end
367
+ end
368
+
319
369
  context 'when performing a bad request' do
320
370
  context 'when using an invalid token' do
321
371
  let(:api) do
@@ -6,7 +6,7 @@
6
6
  require 'spec_helper'
7
7
 
8
8
  describe DeepL::Resources::Text do
9
- subject(:text) { described_class.new('Target', 'es', nil, nil) }
9
+ subject(:text) { described_class.new('Target', 'es', nil, nil, nil) }
10
10
 
11
11
  describe '#initialize' do
12
12
  context 'when building a basic object' do
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
- # Uncomment this line when adding new tests, run the tests once, then comment it again
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.0.2
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: 2024-10-02 00:00:00.000000000 Z
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.4.6
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.