deepl-rb 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13a3bbfea258695f87a655395197001cef339a23
4
- data.tar.gz: 683f5b706dee4a5b8f23d1c02b8a081ec452e46e
3
+ metadata.gz: 7c3fdd20441317600a911a02659531c6595949ac
4
+ data.tar.gz: 54818a5de28df31e33f2cf8434834177fbe71989
5
5
  SHA512:
6
- metadata.gz: cc8cb5c628c1c146f3f29c84425205175a714301a8978db7f0c1d3559503f8d3206855502055b02021bdbe90cdcddeab9b28088c4599178e5b4271c1a539ddfe
7
- data.tar.gz: e9daaaed2529971d5cd5813ff593a99a4950f559d280dee881b7fd7fc356b7fc0cfbc88a25978414e46cda54872f0180d23b848df49c7106f3867d45af1b6e19
6
+ metadata.gz: e389b2270f9cc4584bbe5e77cf6d1f7f6aa087d23a4aa649afe8507c3f0be484685813c161e72d9b30acba49a67277e116ec141b7943216cc1eef399d703edd6
7
+ data.tar.gz: 1dc00e5ba9ab6622f1bcd0fad1b4df2eef7258dcf1ee667ad6c9b7d647975c4eced8f4a37db192c96df020a395124bc48ab599f5dd2a05da23fa8452907bf12f
@@ -11,7 +11,7 @@ Metrics/BlockLength:
11
11
  - "**/*_spec.rb"
12
12
 
13
13
  Metrics/LineLength:
14
- Max: 120
14
+ Max: 100
15
15
 
16
16
  Style/Documentation:
17
17
  Enabled: false
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/deepl-rb) [![Dependency Status](https://gemnasium.com/badges/github.com/wikiti/deepl-rb.svg)](https://gemnasium.com/github.com/wikiti/deepl-rb) [![CircleCI](https://circleci.com/gh/wikiti/deepl-rb.svg?style=shield)](https://circleci.com/gh/wikiti/deepl-rb) [![CodeCov](https://codecov.io/gh/wikiti/deepl-rb/branch/master/graph/badge.svg?token=SHLgQNlZ4o)](https://codecov.io/gh/wikiti/deepl-rb)
1
+ [![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/deepl-rb) [![CircleCI](https://circleci.com/gh/wikiti/deepl-rb.svg?style=shield)](https://circleci.com/gh/wikiti/deepl-rb) [![CodeCov](https://codecov.io/gh/wikiti/deepl-rb/branch/master/graph/badge.svg?token=SHLgQNlZ4o)](https://codecov.io/gh/wikiti/deepl-rb)
2
2
 
3
3
  # DeepL for ruby
4
4
 
@@ -90,11 +90,12 @@ Here's a list of available language codes:
90
90
  | `NL` | Dutch
91
91
  | `PL` | Polish
92
92
 
93
- You can also use custom query parameters, like `tag_handling` or `split_sentences`:
93
+ You can also use custom query parameters, like `tag_handling`, `split_sentences`, `non_splitting_tags` or `ignore_tags`:
94
94
 
95
95
  ```rb
96
96
  translation = DeepL.translate '<p>A sample</p>', 'EN', 'ES',
97
- tag_handling: 'xml', split_sentences: false
97
+ tag_handling: 'xml', split_sentences: false,
98
+ non_splitting_tags: 'h1', ignore_tags: %w[code pre]
98
99
 
99
100
  puts translation.text
100
101
  # => "<p>Una muestra</p>"
@@ -104,8 +105,10 @@ The following parameters will be automatically converted:
104
105
 
105
106
  | Parameter | Conversion
106
107
  | --------------------- | ---------------
107
- | `preserve_formatting` | Convertes `false` to `'0'` and `true` to `'1'`
108
- | `split_sentences` | Convertes `false` to `'0'` and `true` to `'1'`
108
+ | `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
109
+ | `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
110
+ | `non_splitting_tags` | Converts arrays to strings joining by commas
111
+ | `ignore_tags` | Converts arrays to strings joining by commas
109
112
 
110
113
  ### Usage
111
114
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.1.0
@@ -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.0.0 ruby lib
5
+ # stub: deepl-rb 2.1.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "deepl-rb".freeze
9
- s.version = "2.0.0"
9
+ s.version = "2.1.0"
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 = "2018-05-08"
14
+ s.date = "2018-07-24"
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 = [
@@ -1,12 +1,16 @@
1
1
  module DeepL
2
2
  module Requests
3
3
  class Translate < Base
4
+ BOOLEAN_CONVERSION = { true => '1', false => '0' }.freeze
5
+ ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(', ') : value }.freeze
4
6
  OPTIONS_CONVERSIONS = {
5
- split_sentences: { true => '1', false => '0' },
6
- preserve_formatting: { true => '1', false => '0' }
7
+ split_sentences: BOOLEAN_CONVERSION,
8
+ preserve_formatting: BOOLEAN_CONVERSION,
9
+ non_splitting_tags: ARRAY_CONVERSION,
10
+ ignore_tags: ARRAY_CONVERSION
7
11
  }.freeze
8
12
 
9
- attr_reader :text, :source_lang, :target_lang
13
+ attr_reader :text, :source_lang, :target_lang, :ignore_tags, :non_splitting_tags
10
14
 
11
15
  def initialize(api, text, source_lang, target_lang, options = {})
12
16
  super(api, options)
@@ -34,8 +34,9 @@ http_interactions:
34
34
  - "*"
35
35
  body:
36
36
  encoding: UTF-8
37
- string: '{"translations":[{"detected_source_language":"EN","text":"Texto de muestra"}]}'
38
- http_version:
37
+ string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
38
+ muestra"}]}'
39
+ http_version:
39
40
  recorded_at: Tue, 08 May 2018 16:31:34 GMT
40
41
  - request:
41
42
  method: post
@@ -72,7 +73,7 @@ http_interactions:
72
73
  body:
73
74
  encoding: UTF-8
74
75
  string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
75
- http_version:
76
+ http_version:
76
77
  recorded_at: Tue, 08 May 2018 16:31:35 GMT
77
78
  - request:
78
79
  method: post
@@ -110,7 +111,7 @@ http_interactions:
110
111
  encoding: UTF-8
111
112
  string: '{"translations":[{"detected_source_language":"EN","text":"<p>Texto
112
113
  de muestra</p>"}]}'
113
- http_version:
114
+ http_version:
114
115
  recorded_at: Tue, 08 May 2018 16:31:36 GMT
115
116
  - request:
116
117
  method: post
@@ -143,7 +144,7 @@ http_interactions:
143
144
  body:
144
145
  encoding: UTF-8
145
146
  string: ''
146
- http_version:
147
+ http_version:
147
148
  recorded_at: Tue, 08 May 2018 16:31:37 GMT
148
149
  - request:
149
150
  method: post
@@ -176,7 +177,7 @@ http_interactions:
176
177
  body:
177
178
  encoding: UTF-8
178
179
  string: '{"message":"Parameter ''text'' not specified."}'
179
- http_version:
180
+ http_version:
180
181
  recorded_at: Tue, 08 May 2018 16:31:37 GMT
181
182
  - request:
182
183
  method: post
@@ -209,6 +210,44 @@ http_interactions:
209
210
  body:
210
211
  encoding: UTF-8
211
212
  string: '{"message":"Parameter ''target_lang'' not specified."}'
212
- http_version:
213
+ http_version:
213
214
  recorded_at: Tue, 08 May 2018 16:31:37 GMT
215
+ - request:
216
+ method: post
217
+ uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN&ignore_tags=code,%20span
218
+ body:
219
+ encoding: US-ASCII
220
+ string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
221
+ headers:
222
+ Accept-Encoding:
223
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
224
+ Accept:
225
+ - "*/*"
226
+ User-Agent:
227
+ - Ruby
228
+ Content-Type:
229
+ - application/x-www-form-urlencoded
230
+ response:
231
+ status:
232
+ code: 200
233
+ message: OK
234
+ headers:
235
+ Server:
236
+ - nginx
237
+ Date:
238
+ - Tue, 24 Jul 2018 16:13:51 GMT
239
+ Content-Type:
240
+ - application/json
241
+ Content-Length:
242
+ - '119'
243
+ Connection:
244
+ - keep-alive
245
+ Access-Control-Allow-Origin:
246
+ - "*"
247
+ body:
248
+ encoding: ASCII-8BIT
249
+ string: !binary |-
250
+ eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gQnVlbm9zIGTDrWFzISJ9XX0=
251
+ http_version:
252
+ recorded_at: Tue, 24 Jul 2018 16:13:49 GMT
214
253
  recorded_with: VCR 4.0.0
@@ -1,11 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DeepL::Requests::Translate do
4
+ let(:tags_str) { 'p, strong, span' }
5
+ let(:tags_array) { %w[p strong span] }
6
+
4
7
  let(:api) { build_deepl_api }
5
8
  let(:text) { 'Sample text' }
6
9
  let(:source_lang) { 'EN' }
7
10
  let(:target_lang) { 'ES' }
8
- subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang) }
11
+ let(:options) { {} }
12
+ subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
9
13
 
10
14
  describe '#initialize' do
11
15
  context 'When building a request' do
@@ -14,6 +18,60 @@ describe DeepL::Requests::Translate do
14
18
  end
15
19
  end
16
20
 
21
+ context 'when using `non_splitting_tags` options' do
22
+ it 'should work with a nil values' do
23
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: nil)
24
+ expect(request.options[:non_splitting_tags]).to eq(nil)
25
+ end
26
+
27
+ it 'should work with a blank list' do
28
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: '')
29
+ expect(request.options[:non_splitting_tags]).to eq('')
30
+ end
31
+
32
+ it 'should work with a comma-separated list' do
33
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_str)
34
+ expect(request.options[:non_splitting_tags]).to eq(tags_str)
35
+ end
36
+
37
+ it 'should convert arrays to strings' do
38
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_array)
39
+ expect(request.options[:non_splitting_tags]).to eq(tags_str)
40
+ end
41
+
42
+ it 'should leave strings as they are' do
43
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_str)
44
+ expect(request.options[:non_splitting_tags]).to eq(tags_str)
45
+ end
46
+ end
47
+
48
+ context 'when using `ignore_tags` options' do
49
+ it 'should work with a nil values' do
50
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: nil)
51
+ expect(request.options[:ignore_tags]).to eq(nil)
52
+ end
53
+
54
+ it 'should work with a blank list' do
55
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: '')
56
+ expect(request.options[:ignore_tags]).to eq('')
57
+ end
58
+
59
+ it 'should work with a comma-separated list' do
60
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_str)
61
+ expect(request.options[:ignore_tags]).to eq(tags_str)
62
+ end
63
+
64
+ it 'should convert arrays to strings' do
65
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_array)
66
+ expect(request.options[:ignore_tags]).to eq(tags_str)
67
+ end
68
+
69
+ it 'should leave strings as they are' do
70
+ request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_str)
71
+ expect(request.options[:ignore_tags]).to eq(tags_str)
72
+ end
73
+ end
74
+
17
75
  context 'when using `split_sentences` options' do
18
76
  it 'should convert `true` to `1`' do
19
77
  request = DeepL::Requests::Translate.new(api, nil, nil, nil, split_sentences: true)
@@ -101,6 +159,19 @@ describe DeepL::Requests::Translate do
101
159
  end
102
160
  end
103
161
 
162
+ context 'When performing a valid request and passing a variable' do
163
+ let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
164
+ let(:options) { { ignore_tags: 'code, span' } }
165
+
166
+ it 'should return a text object' do
167
+ text = subject.request
168
+
169
+ expect(text).to be_a(DeepL::Resources::Text)
170
+ expect(text.text).to eq('Bienvenido y <code>Hello great World</code> Buenos días!')
171
+ expect(text.detected_source_language).to eq('EN')
172
+ end
173
+ end
174
+
104
175
  context 'When performing a bad request' do
105
176
  context 'When using an invalid token' do
106
177
  let(:api) do
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.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Herzog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-08 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: juwelier