deepl-rb 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +3 -3
- data/lib/deepl/configuration.rb +1 -1
- data/lib/deepl/requests/translate.rb +4 -2
- data/spec/api/configuration_spec.rb +1 -1
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +380 -341
- data/spec/requests/translate_spec.rb +74 -2
- data/spec/spec_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b243885998d697691ea44defaba15632cbe10a2738962c5befa1191b20edb53
|
4
|
+
data.tar.gz: 9e64eff8b57820a5f59cfc1afdde88dd16bac72f8f9de89979c1288bdc72132b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8058534d4022fe77f16c5cda86e4479a7081e7d446a53282a4742f5b4ece7e66f57f1bde6e83c30a0d6dc054477bd53e7b961147e61cd7abc815af7c4c65cc72
|
7
|
+
data.tar.gz: d07ddd8f131b597756fd00bb5e1a43bb4d4310ab3cd4650fdd2bcd4658066063280a58c8bd9c3e0cbb5399adb1013654a89aebf7cbe5fa3fe515b7b714309194
|
data/README.md
CHANGED
@@ -128,6 +128,7 @@ The following parameters will be automatically converted:
|
|
128
128
|
| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
|
129
129
|
| `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
|
130
130
|
| `outline_detection` | Converts `false` to `'0'` and `true` to `'1'`
|
131
|
+
| `splitting_tags` | Converts arrays to strings joining by commas
|
131
132
|
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
132
133
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
133
134
|
| `formality` | No conversion applied
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.1
|
data/deepl-rb.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
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 2.5.
|
5
|
+
# stub: deepl-rb 2.5.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "2.5.
|
9
|
+
s.version = "2.5.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Daniel Herzog".freeze]
|
14
|
-
s.date = "2022-06-
|
14
|
+
s.date = "2022-06-22"
|
15
15
|
s.description = "A simple ruby wrapper for the DeepL translation API (v1). For more information, check this: https://www.deepl.com/docs/api-reference.html".freeze
|
16
16
|
s.email = "info@danielherzog.es".freeze
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/deepl/configuration.rb
CHANGED
@@ -4,16 +4,18 @@ module DeepL
|
|
4
4
|
module Requests
|
5
5
|
class Translate < Base
|
6
6
|
BOOLEAN_CONVERSION = { true => '1', false => '0' }.freeze
|
7
|
-
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',
|
7
|
+
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',') : value }.freeze
|
8
8
|
OPTIONS_CONVERSIONS = {
|
9
9
|
split_sentences: BOOLEAN_CONVERSION,
|
10
10
|
preserve_formatting: BOOLEAN_CONVERSION,
|
11
11
|
outline_detection: BOOLEAN_CONVERSION,
|
12
|
+
splitting_tags: ARRAY_CONVERSION,
|
12
13
|
non_splitting_tags: ARRAY_CONVERSION,
|
13
14
|
ignore_tags: ARRAY_CONVERSION
|
14
15
|
}.freeze
|
15
16
|
|
16
|
-
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :
|
17
|
+
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
|
18
|
+
:non_splitting_tags
|
17
19
|
|
18
20
|
def initialize(api, text, source_lang, target_lang, options = {})
|
19
21
|
super(api, options)
|
@@ -9,7 +9,7 @@ describe DeepL::Configuration do
|
|
9
9
|
describe '#initialize' do
|
10
10
|
context 'When using default configuration attributes' do
|
11
11
|
it 'should use default attributes' do
|
12
|
-
expect(subject.auth_key).to eq(ENV
|
12
|
+
expect(subject.auth_key).to eq(ENV.fetch('DEEPL_AUTH_KEY', nil))
|
13
13
|
expect(subject.host).to eq('https://api.deepl.com')
|
14
14
|
expect(subject.version).to eq('v2')
|
15
15
|
end
|
@@ -1,343 +1,382 @@
|
|
1
1
|
---
|
2
2
|
http_interactions:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://api-free.deepl.com/v2/translate
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: text=Sample+text&source_lang=EN&target_lang=ES
|
9
|
+
headers:
|
10
|
+
Authorization:
|
11
|
+
- DeepL-Auth-Key VALID_TOKEN
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
User-Agent:
|
17
|
+
- Ruby
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
response:
|
21
|
+
status:
|
22
|
+
code: 200
|
23
|
+
message: OK
|
24
|
+
headers:
|
25
|
+
Server:
|
26
|
+
- nginx
|
27
|
+
Date:
|
28
|
+
- Mon, 17 May 2021 14:20:14 GMT
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Content-Length:
|
32
|
+
- '78'
|
33
|
+
Connection:
|
34
|
+
- keep-alive
|
35
|
+
Access-Control-Allow-Origin:
|
36
|
+
- "*"
|
37
|
+
body:
|
38
|
+
encoding: UTF-8
|
39
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
|
40
|
+
muestra"}]}'
|
41
|
+
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
42
|
+
- request:
|
43
|
+
method: post
|
44
|
+
uri: https://api-free.deepl.com/v2/translate
|
45
|
+
body:
|
46
|
+
encoding: US-ASCII
|
47
|
+
string: text=Sample&text=Word&source_lang=EN&target_lang=ES
|
48
|
+
headers:
|
49
|
+
Authorization:
|
50
|
+
- DeepL-Auth-Key VALID_TOKEN
|
51
|
+
Accept-Encoding:
|
52
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
53
|
+
Accept:
|
54
|
+
- "*/*"
|
55
|
+
User-Agent:
|
56
|
+
- Ruby
|
57
|
+
Content-Type:
|
58
|
+
- application/x-www-form-urlencoded
|
59
|
+
response:
|
60
|
+
status:
|
61
|
+
code: 200
|
62
|
+
message: OK
|
63
|
+
headers:
|
64
|
+
Server:
|
65
|
+
- nginx
|
66
|
+
Date:
|
67
|
+
- Mon, 17 May 2021 14:20:14 GMT
|
68
|
+
Content-Type:
|
69
|
+
- application/json
|
70
|
+
Content-Length:
|
71
|
+
- '120'
|
72
|
+
Connection:
|
73
|
+
- keep-alive
|
74
|
+
Access-Control-Allow-Origin:
|
75
|
+
- "*"
|
76
|
+
body:
|
77
|
+
encoding: UTF-8
|
78
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
|
79
|
+
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
80
|
+
- request:
|
81
|
+
method: post
|
82
|
+
uri: https://api-free.deepl.com/v2/translate?tag_handling=xml
|
83
|
+
body:
|
84
|
+
encoding: US-ASCII
|
85
|
+
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
86
|
+
headers:
|
87
|
+
Authorization:
|
88
|
+
- DeepL-Auth-Key VALID_TOKEN
|
89
|
+
Accept-Encoding:
|
90
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
91
|
+
Accept:
|
92
|
+
- "*/*"
|
93
|
+
User-Agent:
|
94
|
+
- Ruby
|
95
|
+
Content-Type:
|
96
|
+
- application/x-www-form-urlencoded
|
97
|
+
response:
|
98
|
+
status:
|
99
|
+
code: 200
|
100
|
+
message: OK
|
101
|
+
headers:
|
102
|
+
Server:
|
103
|
+
- nginx
|
104
|
+
Date:
|
105
|
+
- Mon, 17 May 2021 14:20:15 GMT
|
106
|
+
Content-Type:
|
107
|
+
- application/json
|
108
|
+
Content-Length:
|
109
|
+
- '85'
|
110
|
+
Connection:
|
111
|
+
- keep-alive
|
112
|
+
Access-Control-Allow-Origin:
|
113
|
+
- "*"
|
114
|
+
body:
|
115
|
+
encoding: UTF-8
|
116
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"<p>Texto
|
117
|
+
de muestra</p>"}]}'
|
118
|
+
recorded_at: Mon, 17 May 2021 14:20:15 GMT
|
119
|
+
- request:
|
120
|
+
method: post
|
121
|
+
uri: https://api-free.deepl.com/v2/translate
|
122
|
+
body:
|
123
|
+
encoding: US-ASCII
|
124
|
+
string: text=Sample+text&source_lang=EN&target_lang=ES
|
125
|
+
headers:
|
126
|
+
Authorization:
|
127
|
+
- DeepL-Auth-Key invalid
|
128
|
+
Accept-Encoding:
|
129
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
130
|
+
Accept:
|
131
|
+
- "*/*"
|
132
|
+
User-Agent:
|
133
|
+
- Ruby
|
134
|
+
Content-Type:
|
135
|
+
- application/x-www-form-urlencoded
|
136
|
+
response:
|
137
|
+
status:
|
138
|
+
code: 403
|
139
|
+
message: Forbidden
|
140
|
+
headers:
|
141
|
+
Server:
|
142
|
+
- nginx
|
143
|
+
Date:
|
144
|
+
- Mon, 17 May 2021 14:20:16 GMT
|
145
|
+
Content-Length:
|
146
|
+
- '0'
|
147
|
+
Connection:
|
148
|
+
- keep-alive
|
149
|
+
Access-Control-Allow-Origin:
|
150
|
+
- "*"
|
151
|
+
body:
|
152
|
+
encoding: UTF-8
|
153
|
+
string: ''
|
154
|
+
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
155
|
+
- request:
|
156
|
+
method: post
|
157
|
+
uri: https://api-free.deepl.com/v2/translate
|
158
|
+
body:
|
159
|
+
encoding: US-ASCII
|
160
|
+
string: source_lang=EN&target_lang=ES
|
161
|
+
headers:
|
162
|
+
Authorization:
|
163
|
+
- DeepL-Auth-Key VALID_TOKEN
|
164
|
+
Accept-Encoding:
|
165
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
166
|
+
Accept:
|
167
|
+
- "*/*"
|
168
|
+
User-Agent:
|
169
|
+
- Ruby
|
170
|
+
Content-Type:
|
171
|
+
- application/x-www-form-urlencoded
|
172
|
+
response:
|
173
|
+
status:
|
174
|
+
code: 400
|
175
|
+
message: Bad Request
|
176
|
+
headers:
|
177
|
+
Server:
|
178
|
+
- nginx
|
179
|
+
Date:
|
180
|
+
- Mon, 17 May 2021 14:20:16 GMT
|
181
|
+
Content-Length:
|
182
|
+
- '45'
|
183
|
+
Connection:
|
184
|
+
- keep-alive
|
185
|
+
Access-Control-Allow-Origin:
|
186
|
+
- "*"
|
187
|
+
body:
|
188
|
+
encoding: UTF-8
|
189
|
+
string: '{"message":"Parameter ''text'' not specified."}'
|
190
|
+
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
191
|
+
- request:
|
192
|
+
method: post
|
193
|
+
uri: https://api-free.deepl.com/v2/translate
|
194
|
+
body:
|
195
|
+
encoding: US-ASCII
|
196
|
+
string: text=Sample+text&source_lang=EN
|
197
|
+
headers:
|
198
|
+
Authorization:
|
199
|
+
- DeepL-Auth-Key VALID_TOKEN
|
200
|
+
Accept-Encoding:
|
201
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
202
|
+
Accept:
|
203
|
+
- "*/*"
|
204
|
+
User-Agent:
|
205
|
+
- Ruby
|
206
|
+
Content-Type:
|
207
|
+
- application/x-www-form-urlencoded
|
208
|
+
response:
|
209
|
+
status:
|
210
|
+
code: 400
|
211
|
+
message: Bad Request
|
212
|
+
headers:
|
213
|
+
Server:
|
214
|
+
- nginx
|
215
|
+
Date:
|
216
|
+
- Mon, 17 May 2021 14:20:17 GMT
|
217
|
+
Content-Length:
|
218
|
+
- '52'
|
219
|
+
Connection:
|
220
|
+
- keep-alive
|
221
|
+
Access-Control-Allow-Origin:
|
222
|
+
- "*"
|
223
|
+
body:
|
224
|
+
encoding: UTF-8
|
225
|
+
string: '{"message":"Value for ''target_lang'' not supported."}'
|
226
|
+
recorded_at: Mon, 17 May 2021 14:20:17 GMT
|
227
|
+
- request:
|
228
|
+
method: post
|
229
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&ignore_tags=code,span&tag_handling=xml
|
230
|
+
body:
|
231
|
+
encoding: US-ASCII
|
232
|
+
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
233
|
+
headers:
|
234
|
+
Accept-Encoding:
|
235
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
236
|
+
Accept:
|
237
|
+
- "*/*"
|
238
|
+
User-Agent:
|
239
|
+
- Ruby
|
240
|
+
Content-Type:
|
241
|
+
- application/x-www-form-urlencoded
|
242
|
+
response:
|
243
|
+
status:
|
244
|
+
code: 200
|
245
|
+
message: OK
|
246
|
+
headers:
|
247
|
+
Server:
|
248
|
+
- nginx
|
249
|
+
Date:
|
250
|
+
- Mon, 17 May 2021 14:20:56 GMT
|
251
|
+
Content-Type:
|
252
|
+
- application/json
|
253
|
+
Content-Length:
|
254
|
+
- '121'
|
255
|
+
Connection:
|
256
|
+
- keep-alive
|
257
|
+
Access-Control-Allow-Origin:
|
258
|
+
- "*"
|
259
|
+
body:
|
260
|
+
encoding: ASCII-8BIT
|
261
|
+
string: !binary |-
|
262
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
|
263
|
+
recorded_at: Mon, 17 May 2021 14:20:56 GMT
|
264
|
+
- request:
|
265
|
+
method: post
|
266
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&glossary_id=123
|
267
|
+
body:
|
268
|
+
encoding: US-ASCII
|
269
|
+
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
270
|
+
headers:
|
271
|
+
Accept-Encoding:
|
272
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
273
|
+
Accept:
|
274
|
+
- "*/*"
|
275
|
+
User-Agent:
|
276
|
+
- Ruby
|
277
|
+
Content-Type:
|
278
|
+
- application/x-www-form-urlencoded
|
279
|
+
response:
|
280
|
+
status:
|
281
|
+
code: 400
|
282
|
+
message: Bad Request
|
283
|
+
headers:
|
284
|
+
Server:
|
285
|
+
- nginx
|
286
|
+
Date:
|
287
|
+
- Tue, 28 Sep 2021 17:20:52 GMT
|
288
|
+
Content-Type:
|
289
|
+
- application/json
|
290
|
+
Content-Length:
|
291
|
+
- '51'
|
292
|
+
Connection:
|
293
|
+
- keep-alive
|
294
|
+
Access-Control-Allow-Origin:
|
295
|
+
- "*"
|
296
|
+
body:
|
297
|
+
encoding: UTF-8
|
298
|
+
string: '{"message":"Value for ''termbaseId'' not supported."}'
|
299
|
+
recorded_at: Tue, 28 Sep 2021 17:20:52 GMT
|
300
|
+
- request:
|
301
|
+
method: post
|
302
|
+
uri: https://api-free.deepl.com/v2/translate?ignore_tags=code,span&tag_handling=xml
|
303
|
+
body:
|
304
|
+
encoding: US-ASCII
|
305
|
+
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
306
|
+
headers:
|
307
|
+
Authorization:
|
308
|
+
- DeepL-Auth-Key VALID_TOKEN
|
309
|
+
Accept-Encoding:
|
310
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
311
|
+
Accept:
|
312
|
+
- "*/*"
|
313
|
+
User-Agent:
|
314
|
+
- Ruby
|
315
|
+
Content-Type:
|
316
|
+
- application/x-www-form-urlencoded
|
317
|
+
response:
|
318
|
+
status:
|
319
|
+
code: 200
|
320
|
+
message: OK
|
321
|
+
headers:
|
322
|
+
Server:
|
323
|
+
- nginx
|
324
|
+
Date:
|
325
|
+
- Thu, 17 Mar 2022 09:55:34 GMT
|
326
|
+
Content-Type:
|
327
|
+
- application/json
|
328
|
+
Transfer-Encoding:
|
329
|
+
- chunked
|
330
|
+
Connection:
|
331
|
+
- keep-alive
|
332
|
+
Vary:
|
333
|
+
- Accept-Encoding
|
334
|
+
Access-Control-Allow-Origin:
|
335
|
+
- "*"
|
336
|
+
body:
|
337
|
+
encoding: ASCII-8BIT
|
338
|
+
string: !binary |-
|
339
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
|
340
|
+
recorded_at: Thu, 17 Mar 2022 09:55:32 GMT
|
341
|
+
- request:
|
342
|
+
method: post
|
343
|
+
uri: https://api-free.deepl.com/v2/translate?outline_detection=0&split_sentences=nonewlines&splitting_tags=title,par&tag_handling=xml
|
344
|
+
body:
|
345
|
+
encoding: US-ASCII
|
346
|
+
string: text=%3Cdocument%3E%0A++%3Cmeta%3E%0A++++%3Ctitle%3EA+document%27s+title%3C%2Ftitle%3E%0A++%3C%2Fmeta%3E%0A++%3Ccontent%3E%0A++++%3Cpar%3EThis+is+the+first+sentence.+Followed+by+a+second+one.%3C%2Fpar%3E%0A++++%3Cpar%3EThis+is+the+third+sentence.%3C%2Fpar%3E%0A++%3C%2Fcontent%3E%0A%3C%2Fdocument%3E%0A&source_lang=EN&target_lang=ES
|
347
|
+
headers:
|
348
|
+
Authorization:
|
349
|
+
- DeepL-Auth-Key VALID_TOKEN
|
350
|
+
Accept-Encoding:
|
351
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
352
|
+
Accept:
|
353
|
+
- "*/*"
|
354
|
+
User-Agent:
|
355
|
+
- Ruby
|
356
|
+
Content-Type:
|
357
|
+
- application/x-www-form-urlencoded
|
358
|
+
response:
|
359
|
+
status:
|
360
|
+
code: 200
|
361
|
+
message: OK
|
362
|
+
headers:
|
363
|
+
Server:
|
364
|
+
- nginx
|
365
|
+
Date:
|
366
|
+
- Wed, 22 Jun 2022 18:04:58 GMT
|
367
|
+
Content-Type:
|
368
|
+
- application/json
|
369
|
+
Transfer-Encoding:
|
370
|
+
- chunked
|
371
|
+
Connection:
|
372
|
+
- keep-alive
|
373
|
+
Vary:
|
374
|
+
- Accept-Encoding
|
375
|
+
Access-Control-Allow-Origin:
|
376
|
+
- "*"
|
377
|
+
body:
|
378
|
+
encoding: ASCII-8BIT
|
379
|
+
string: !binary |-
|
380
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6Ijxkb2N1bWVudD5cbiAgPG1ldGE+XG4gICAgPHRpdGxlPkVsIHTDrXR1bG8gZGUgdW4gZG9jdW1lbnRvPC90aXRsZT5cbiAgPC9tZXRhPlxuICA8Y29udGVudD5cbiAgICA8cGFyPkVzIGxhIHByaW1lcmEgZnJhc2UuIFNlZ3VpZG8gZGUgdW5hIHNlZ3VuZGEuPC9wYXI+XG4gICAgPHBhcj5Fc3RhIGVzIGxhIHRlcmNlcmEgZnJhc2UuPC9wYXI+XG4gIDwvY29udGVudD5cbjwvZG9jdW1lbnQ+XG4ifV19
|
381
|
+
recorded_at: Wed, 22 Jun 2022 18:04:56 GMT
|
382
|
+
recorded_with: VCR 6.1.0
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DeepL::Requests::Translate do
|
6
|
-
let(:tags_str) { 'p,
|
6
|
+
let(:tags_str) { 'p,strong,span' }
|
7
7
|
let(:tags_array) { %w[p strong span] }
|
8
8
|
|
9
9
|
let(:api) { build_deepl_api }
|
@@ -11,6 +11,7 @@ describe DeepL::Requests::Translate do
|
|
11
11
|
let(:source_lang) { 'EN' }
|
12
12
|
let(:target_lang) { 'ES' }
|
13
13
|
let(:options) { {} }
|
14
|
+
|
14
15
|
subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
|
15
16
|
|
16
17
|
describe '#initialize' do
|
@@ -20,6 +21,33 @@ describe DeepL::Requests::Translate do
|
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
24
|
+
context 'when using `splitting_tags` options' do
|
25
|
+
it 'should work with a nil values' do
|
26
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: nil)
|
27
|
+
expect(request.options[:splitting_tags]).to eq(nil)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should work with a blank list' do
|
31
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: '')
|
32
|
+
expect(request.options[:splitting_tags]).to eq('')
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should work with a comma-separated list' do
|
36
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
|
37
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should convert arrays to strings' do
|
41
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_array)
|
42
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should leave strings as they are' do
|
46
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, splitting_tags: tags_str)
|
47
|
+
expect(request.options[:splitting_tags]).to eq(tags_str)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
23
51
|
context 'when using `non_splitting_tags` options' do
|
24
52
|
it 'should work with a nil values' do
|
25
53
|
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: nil)
|
@@ -215,7 +243,7 @@ describe DeepL::Requests::Translate do
|
|
215
243
|
|
216
244
|
context 'When performing a valid request and passing a variable' do
|
217
245
|
let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
|
218
|
-
let(:options) { { tag_handling: 'xml', ignore_tags:
|
246
|
+
let(:options) { { tag_handling: 'xml', ignore_tags: %w[code span] } }
|
219
247
|
|
220
248
|
it 'should return a text object' do
|
221
249
|
text = subject.request
|
@@ -226,6 +254,50 @@ describe DeepL::Requests::Translate do
|
|
226
254
|
end
|
227
255
|
end
|
228
256
|
|
257
|
+
context 'When performing a valid request with an HTML document' do
|
258
|
+
let(:text) do
|
259
|
+
<<~XML
|
260
|
+
<document>
|
261
|
+
<meta>
|
262
|
+
<title>A document's title</title>
|
263
|
+
</meta>
|
264
|
+
<content>
|
265
|
+
<par>This is the first sentence. Followed by a second one.</par>
|
266
|
+
<par>This is the third sentence.</par>
|
267
|
+
</content>
|
268
|
+
</document>
|
269
|
+
XML
|
270
|
+
end
|
271
|
+
let(:options) do
|
272
|
+
{
|
273
|
+
tag_handling: 'xml',
|
274
|
+
split_sentences: 'nonewlines',
|
275
|
+
outline_detection: false,
|
276
|
+
splitting_tags: %w[title par]
|
277
|
+
}
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should return a text object' do
|
281
|
+
text = subject.request
|
282
|
+
|
283
|
+
expect(text).to be_a(DeepL::Resources::Text)
|
284
|
+
expect(text.text).to eq(
|
285
|
+
<<~XML
|
286
|
+
<document>
|
287
|
+
<meta>
|
288
|
+
<title>El título de un documento</title>
|
289
|
+
</meta>
|
290
|
+
<content>
|
291
|
+
<par>Es la primera frase. Seguido de una segunda.</par>
|
292
|
+
<par>Esta es la tercera frase.</par>
|
293
|
+
</content>
|
294
|
+
</document>
|
295
|
+
XML
|
296
|
+
)
|
297
|
+
expect(text.detected_source_language).to eq('EN')
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
229
301
|
context 'When performing a bad request' do
|
230
302
|
context 'When using an invalid token' do
|
231
303
|
let(:api) do
|
data/spec/spec_helper.rb
CHANGED
@@ -18,7 +18,7 @@ require 'vcr'
|
|
18
18
|
VCR.configure do |config|
|
19
19
|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
20
20
|
config.hook_into :webmock
|
21
|
-
config.filter_sensitive_data('VALID_TOKEN') { ENV
|
21
|
+
config.filter_sensitive_data('VALID_TOKEN') { ENV.fetch('DEEPL_AUTH_KEY', nil) }
|
22
22
|
config.default_cassette_options = {
|
23
23
|
# record: :new_episodes,
|
24
24
|
match_requests_on: %i[method uri body headers]
|
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: 2.5.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Herzog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|