deepl-rb 2.5.0 → 2.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50a94f4bc3e0633bf578ae6fd53d794632e2b7a03b8d2a78b9678ed44289043c
4
- data.tar.gz: 74e5911707588b9fd75684bbdce7092b492deafc5c3cef4e47c2732006a3bfb9
3
+ metadata.gz: 9b243885998d697691ea44defaba15632cbe10a2738962c5befa1191b20edb53
4
+ data.tar.gz: 9e64eff8b57820a5f59cfc1afdde88dd16bac72f8f9de89979c1288bdc72132b
5
5
  SHA512:
6
- metadata.gz: 9700c6128ab06b432596131da46cbdb240c433baeecb2ece7b74860040818fd3a9e32cf9c4a9384a6a8875200c4aa69f0fa74f533ffc6a4aeb9b9736e76b577f
7
- data.tar.gz: 5a60db0a73691310159cfc92036c36e317f247f7bd0ece2b1002723068ffa531f43d4c96741e25e0fde4aff0fa1dc6c54596d6a91183c8ad4a75eaa62848153a
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.0
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.0 ruby lib
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.0"
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-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 = [
@@ -8,7 +8,7 @@ module DeepL
8
8
 
9
9
  def initialize(data = {})
10
10
  data.each { |key, value| send("#{key}=", value) }
11
- @auth_key ||= ENV['DEEPL_AUTH_KEY']
11
+ @auth_key ||= ENV.fetch('DEEPL_AUTH_KEY', nil)
12
12
  @host ||= 'https://api.deepl.com'
13
13
  @version ||= 'v2'
14
14
  end
@@ -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(', ') : value }.freeze
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, :non_splitting_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['DEEPL_AUTH_KEY'])
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
- - 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:
40
- '{"translations":[{"detected_source_language":"EN","text":"Texto de
41
- muestra"}]}'
42
- recorded_at: Mon, 17 May 2021 14:20:14 GMT
43
- - request:
44
- method: post
45
- uri: https://api-free.deepl.com/v2/translate
46
- body:
47
- encoding: US-ASCII
48
- string: text=Sample&text=Word&source_lang=EN&target_lang=ES
49
- headers:
50
- Authorization:
51
- - DeepL-Auth-Key VALID_TOKEN
52
- Accept-Encoding:
53
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
54
- Accept:
55
- - "*/*"
56
- User-Agent:
57
- - Ruby
58
- Content-Type:
59
- - application/x-www-form-urlencoded
60
- response:
61
- status:
62
- code: 200
63
- message: OK
64
- headers:
65
- Server:
66
- - nginx
67
- Date:
68
- - Mon, 17 May 2021 14:20:14 GMT
69
- Content-Type:
70
- - application/json
71
- Content-Length:
72
- - "120"
73
- Connection:
74
- - keep-alive
75
- Access-Control-Allow-Origin:
76
- - "*"
77
- body:
78
- encoding: UTF-8
79
- string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
80
- recorded_at: Mon, 17 May 2021 14:20:14 GMT
81
- - request:
82
- method: post
83
- uri: https://api-free.deepl.com/v2/translate?tag_handling=xml
84
- body:
85
- encoding: US-ASCII
86
- string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
87
- headers:
88
- Authorization:
89
- - DeepL-Auth-Key VALID_TOKEN
90
- Accept-Encoding:
91
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
92
- Accept:
93
- - "*/*"
94
- User-Agent:
95
- - Ruby
96
- Content-Type:
97
- - application/x-www-form-urlencoded
98
- response:
99
- status:
100
- code: 200
101
- message: OK
102
- headers:
103
- Server:
104
- - nginx
105
- Date:
106
- - Mon, 17 May 2021 14:20:15 GMT
107
- Content-Type:
108
- - application/json
109
- Content-Length:
110
- - "85"
111
- Connection:
112
- - keep-alive
113
- Access-Control-Allow-Origin:
114
- - "*"
115
- body:
116
- encoding: UTF-8
117
- string:
118
- '{"translations":[{"detected_source_language":"EN","text":"<p>Texto
119
- de muestra</p>"}]}'
120
- recorded_at: Mon, 17 May 2021 14:20:15 GMT
121
- - request:
122
- method: post
123
- uri: https://api-free.deepl.com/v2/translate
124
- body:
125
- encoding: US-ASCII
126
- string: text=Sample+text&source_lang=EN&target_lang=ES
127
- headers:
128
- Authorization:
129
- - DeepL-Auth-Key invalid
130
- Accept-Encoding:
131
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
132
- Accept:
133
- - "*/*"
134
- User-Agent:
135
- - Ruby
136
- Content-Type:
137
- - application/x-www-form-urlencoded
138
- response:
139
- status:
140
- code: 403
141
- message: Forbidden
142
- headers:
143
- Server:
144
- - nginx
145
- Date:
146
- - Mon, 17 May 2021 14:20:16 GMT
147
- Content-Length:
148
- - "0"
149
- Connection:
150
- - keep-alive
151
- Access-Control-Allow-Origin:
152
- - "*"
153
- body:
154
- encoding: UTF-8
155
- string: ""
156
- recorded_at: Mon, 17 May 2021 14:20:16 GMT
157
- - request:
158
- method: post
159
- uri: https://api-free.deepl.com/v2/translate
160
- body:
161
- encoding: US-ASCII
162
- string: source_lang=EN&target_lang=ES
163
- headers:
164
- Authorization:
165
- - DeepL-Auth-Key VALID_TOKEN
166
- Accept-Encoding:
167
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
168
- Accept:
169
- - "*/*"
170
- User-Agent:
171
- - Ruby
172
- Content-Type:
173
- - application/x-www-form-urlencoded
174
- response:
175
- status:
176
- code: 400
177
- message: Bad Request
178
- headers:
179
- Server:
180
- - nginx
181
- Date:
182
- - Mon, 17 May 2021 14:20:16 GMT
183
- Content-Length:
184
- - "45"
185
- Connection:
186
- - keep-alive
187
- Access-Control-Allow-Origin:
188
- - "*"
189
- body:
190
- encoding: UTF-8
191
- string: '{"message":"Parameter ''text'' not specified."}'
192
- recorded_at: Mon, 17 May 2021 14:20:16 GMT
193
- - request:
194
- method: post
195
- uri: https://api-free.deepl.com/v2/translate
196
- body:
197
- encoding: US-ASCII
198
- string: text=Sample+text&source_lang=EN
199
- headers:
200
- Authorization:
201
- - DeepL-Auth-Key VALID_TOKEN
202
- Accept-Encoding:
203
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
204
- Accept:
205
- - "*/*"
206
- User-Agent:
207
- - Ruby
208
- Content-Type:
209
- - application/x-www-form-urlencoded
210
- response:
211
- status:
212
- code: 400
213
- message: Bad Request
214
- headers:
215
- Server:
216
- - nginx
217
- Date:
218
- - Mon, 17 May 2021 14:20:17 GMT
219
- Content-Length:
220
- - "52"
221
- Connection:
222
- - keep-alive
223
- Access-Control-Allow-Origin:
224
- - "*"
225
- body:
226
- encoding: UTF-8
227
- string: '{"message":"Value for ''target_lang'' not supported."}'
228
- recorded_at: Mon, 17 May 2021 14:20:17 GMT
229
- - request:
230
- method: post
231
- uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&ignore_tags=code,span&tag_handling=xml
232
- body:
233
- encoding: US-ASCII
234
- string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
235
- headers:
236
- Accept-Encoding:
237
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
238
- Accept:
239
- - "*/*"
240
- User-Agent:
241
- - Ruby
242
- Content-Type:
243
- - application/x-www-form-urlencoded
244
- response:
245
- status:
246
- code: 200
247
- message: OK
248
- headers:
249
- Server:
250
- - nginx
251
- Date:
252
- - Mon, 17 May 2021 14:20:56 GMT
253
- Content-Type:
254
- - application/json
255
- Content-Length:
256
- - "121"
257
- Connection:
258
- - keep-alive
259
- Access-Control-Allow-Origin:
260
- - "*"
261
- body:
262
- encoding: ASCII-8BIT
263
- string: !binary |-
264
- eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
265
- recorded_at: Mon, 17 May 2021 14:20:56 GMT
266
- - request:
267
- method: post
268
- uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&glossary_id=123
269
- body:
270
- encoding: US-ASCII
271
- string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
272
- headers:
273
- Accept-Encoding:
274
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
275
- Accept:
276
- - "*/*"
277
- User-Agent:
278
- - Ruby
279
- Content-Type:
280
- - application/x-www-form-urlencoded
281
- response:
282
- status:
283
- code: 400
284
- message: Bad Request
285
- headers:
286
- Server:
287
- - nginx
288
- Date:
289
- - Tue, 28 Sep 2021 17:20:52 GMT
290
- Content-Type:
291
- - application/json
292
- Content-Length:
293
- - "51"
294
- Connection:
295
- - keep-alive
296
- Access-Control-Allow-Origin:
297
- - "*"
298
- body:
299
- encoding: UTF-8
300
- string: '{"message":"Value for ''termbaseId'' not supported."}'
301
- recorded_at: Tue, 28 Sep 2021 17:20:52 GMT
302
- - request:
303
- method: post
304
- uri: https://api-free.deepl.com/v2/translate?ignore_tags=code,span&tag_handling=xml
305
- body:
306
- encoding: US-ASCII
307
- string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
308
- headers:
309
- Authorization:
310
- - DeepL-Auth-Key VALID_TOKEN
311
- Accept-Encoding:
312
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
313
- Accept:
314
- - "*/*"
315
- User-Agent:
316
- - Ruby
317
- Content-Type:
318
- - application/x-www-form-urlencoded
319
- response:
320
- status:
321
- code: 200
322
- message: OK
323
- headers:
324
- Server:
325
- - nginx
326
- Date:
327
- - Thu, 17 Mar 2022 09:55:34 GMT
328
- Content-Type:
329
- - application/json
330
- Transfer-Encoding:
331
- - chunked
332
- Connection:
333
- - keep-alive
334
- Vary:
335
- - Accept-Encoding
336
- Access-Control-Allow-Origin:
337
- - "*"
338
- body:
339
- encoding: ASCII-8BIT
340
- string: !binary |-
341
- eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
342
- recorded_at: Thu, 17 Mar 2022 09:55:32 GMT
343
- recorded_with: VCR 6.0.0
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, strong, span' }
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: 'code,span' } }
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['DEEPL_AUTH_KEY'] }
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.0
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-06 00:00:00.000000000 Z
11
+ date: 2022-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier