deepl-rb 3.0.2 → 3.2.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.
@@ -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
@@ -10237,4 +10237,136 @@ http_interactions:
10237
10237
  string: !binary |-
10238
10238
  eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IsKhRXNvIGVzIHBpY2FudGUhIn1dfQ==
10239
10239
  recorded_at: Wed, 25 Sep 2024 16:08:00 GMT
10240
+ - request:
10241
+ method: post
10242
+ uri: https://api.deepl.com/v2/translate
10243
+ body:
10244
+ encoding: UTF-8
10245
+ string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"quality_optimized"}'
10246
+ headers:
10247
+ Authorization:
10248
+ - DeepL-Auth-Key VALID_TOKEN
10249
+ User-Agent:
10250
+ - deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
10251
+ Content-Type:
10252
+ - application/json
10253
+ Accept-Encoding:
10254
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
10255
+ Accept:
10256
+ - "*/*"
10257
+ response:
10258
+ status:
10259
+ code: 200
10260
+ message: OK
10261
+ headers:
10262
+ Date:
10263
+ - Fri, 08 Nov 2024 15:57:39 GMT
10264
+ Content-Type:
10265
+ - application/json
10266
+ Transfer-Encoding:
10267
+ - chunked
10268
+ Vary:
10269
+ - Accept-Encoding
10270
+ Access-Control-Allow-Origin:
10271
+ - "*"
10272
+ Strict-Transport-Security:
10273
+ - max-age=63072000; includeSubDomains; preload
10274
+ Server-Timing:
10275
+ - l7_lb_tls;dur=89, l7_lb_idle;dur=0, l7_lb_receive;dur=0, l7_lb_total;dur=165
10276
+ Access-Control-Expose-Headers:
10277
+ - Server-Timing, X-Trace-ID
10278
+ X-Trace-Id:
10279
+ - 7d71b768eebc41da8c5b820c33e7cdc1
10280
+ body:
10281
+ encoding: ASCII-8BIT
10282
+ string: '{"translations":[{"detected_source_language":"EN","text":"Mustertext","model_type_used":"quality_optimized"}]}'
10283
+ recorded_at: Fri, 08 Nov 2024 15:57:39 GMT
10284
+ - request:
10285
+ method: post
10286
+ uri: https://api.deepl.com/v2/translate
10287
+ body:
10288
+ encoding: UTF-8
10289
+ string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"prefer_quality_optimized"}'
10290
+ headers:
10291
+ Authorization:
10292
+ - DeepL-Auth-Key VALID_TOKEN
10293
+ User-Agent:
10294
+ - deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
10295
+ Content-Type:
10296
+ - application/json
10297
+ Accept-Encoding:
10298
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
10299
+ Accept:
10300
+ - "*/*"
10301
+ response:
10302
+ status:
10303
+ code: 200
10304
+ message: OK
10305
+ headers:
10306
+ Date:
10307
+ - Mon, 11 Nov 2024 10:58:59 GMT
10308
+ Content-Type:
10309
+ - application/json
10310
+ Transfer-Encoding:
10311
+ - chunked
10312
+ Vary:
10313
+ - Accept-Encoding
10314
+ Access-Control-Allow-Origin:
10315
+ - "*"
10316
+ Strict-Transport-Security:
10317
+ - max-age=63072000; includeSubDomains; preload
10318
+ Server-Timing:
10319
+ - l7_lb_tls;dur=98, l7_lb_idle;dur=1, l7_lb_receive;dur=0, l7_lb_total;dur=320
10320
+ Access-Control-Expose-Headers:
10321
+ - Server-Timing, X-Trace-ID
10322
+ X-Trace-Id:
10323
+ - 0fa07be47b3b458ebf50268ca2efe7fe
10324
+ body:
10325
+ encoding: ASCII-8BIT
10326
+ string: '{"translations":[{"detected_source_language":"EN","text":"Mustertext","model_type_used":"quality_optimized"}]}'
10327
+ recorded_at: Mon, 11 Nov 2024 10:58:59 GMT
10328
+ - request:
10329
+ method: post
10330
+ uri: https://api.deepl.com/v2/translate
10331
+ body:
10332
+ encoding: UTF-8
10333
+ string: '{"text":["Sample text"],"source_lang":"EN","target_lang":"DE","model_type":"latency_optimized"}'
10334
+ headers:
10335
+ Authorization:
10336
+ - DeepL-Auth-Key VALID_TOKEN
10337
+ User-Agent:
10338
+ - deepl-ruby/3.0.2 (darwin22) ruby/3.2.1
10339
+ Content-Type:
10340
+ - application/json
10341
+ Accept-Encoding:
10342
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
10343
+ Accept:
10344
+ - "*/*"
10345
+ response:
10346
+ status:
10347
+ code: 200
10348
+ message: OK
10349
+ headers:
10350
+ Date:
10351
+ - Fri, 15 Nov 2024 11:35:22 GMT
10352
+ Content-Type:
10353
+ - application/json
10354
+ Transfer-Encoding:
10355
+ - chunked
10356
+ Vary:
10357
+ - Accept-Encoding
10358
+ Access-Control-Allow-Origin:
10359
+ - "*"
10360
+ Strict-Transport-Security:
10361
+ - max-age=63072000; includeSubDomains; preload
10362
+ Server-Timing:
10363
+ - l7_lb_tls;dur=136, l7_lb_idle;dur=2, l7_lb_receive;dur=0, l7_lb_total;dur=156
10364
+ Access-Control-Expose-Headers:
10365
+ - Server-Timing, X-Trace-ID
10366
+ X-Trace-Id:
10367
+ - de2645cb65c3418db54e3bdefd35fe52
10368
+ body:
10369
+ encoding: ASCII-8BIT
10370
+ string: '{"translations":[{"detected_source_language":"EN","text":"Beispieltext","model_type_used":"latency_optimized"}]}'
10371
+ recorded_at: Fri, 15 Nov 2024 11:35:22 GMT
10240
10372
  recorded_with: VCR 6.2.0
@@ -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