deepl-rb 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.rubocop.yml +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +24 -24
- data/README.md +59 -11
- data/VERSION +1 -1
- data/deepl-rb.gemspec +17 -17
- data/lib/deepl.rb +2 -9
- data/lib/deepl/requests/base.rb +9 -4
- data/lib/deepl/requests/translate_text.rb +2 -2
- data/spec/api/deepl_spec.rb +3 -2
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +37 -0
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +43 -5
- data/spec/requests/translate_text_spec.rb +12 -0
- data/spec/spec_helper.rb +8 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1c91abf5249e9f0e384d543ed2d849adf9b3942
|
4
|
+
data.tar.gz: edd33d6c73e38b9b83372d8acbdd66bab5af0a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b549cc903c25708d605dc149136ff35d6cbd6b200d4e4c7e66773918fb4b291bf84e729fa9909de5ef32781c368ec6f04268bb21d1b585f8d37eeec5ca1745e
|
7
|
+
data.tar.gz: bd6317763f346f308aa7e0f1eb11f1fced3352ec1ea64e1cb323170e60f56601e0b2c5a00ce491afac7f4397550fbc6324bd203b07d4bc1a8728598a9cc4ac5d
|
data/.circleci/config.yml
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,6 +5,10 @@ GEM
|
|
5
5
|
public_suffix (>= 2.0.2, < 4.0)
|
6
6
|
ast (2.3.0)
|
7
7
|
builder (3.2.3)
|
8
|
+
codecov (0.1.10)
|
9
|
+
json
|
10
|
+
simplecov
|
11
|
+
url
|
8
12
|
crack (0.4.3)
|
9
13
|
safe_yaml (~> 1.0.0)
|
10
14
|
descendants_tracker (0.0.4)
|
@@ -21,24 +25,20 @@ GEM
|
|
21
25
|
hashie (~> 3.5, >= 3.5.2)
|
22
26
|
oauth2 (~> 1.0)
|
23
27
|
hashdiff (0.3.7)
|
24
|
-
hashie (3.5.
|
28
|
+
hashie (3.5.7)
|
25
29
|
highline (1.7.10)
|
26
30
|
json (2.1.0)
|
27
|
-
juwelier (2.
|
31
|
+
juwelier (2.1.3)
|
28
32
|
builder
|
29
|
-
bundler
|
30
|
-
git
|
33
|
+
bundler (>= 1.13)
|
34
|
+
git (>= 1.2.5)
|
31
35
|
github_api
|
32
|
-
highline
|
33
|
-
|
34
|
-
nokogiri
|
35
|
-
psych
|
36
|
+
highline (>= 1.6.15)
|
37
|
+
nokogiri (>= 1.5.10)
|
36
38
|
rake
|
37
39
|
rdoc
|
38
|
-
|
40
|
+
semver
|
39
41
|
jwt (1.5.6)
|
40
|
-
kamelcase (0.0.1)
|
41
|
-
semver2 (~> 3)
|
42
42
|
mini_portile2 (2.3.0)
|
43
43
|
multi_json (1.12.2)
|
44
44
|
multi_xml (0.6.0)
|
@@ -51,22 +51,20 @@ GEM
|
|
51
51
|
multi_json (~> 1.3)
|
52
52
|
multi_xml (~> 0.5)
|
53
53
|
rack (>= 1.2, < 3)
|
54
|
-
parallel (1.12.
|
54
|
+
parallel (1.12.1)
|
55
55
|
parser (2.4.0.2)
|
56
56
|
ast (~> 2.3)
|
57
57
|
powerpack (0.1.1)
|
58
|
-
psych (2.2.2)
|
59
58
|
public_suffix (3.0.1)
|
60
|
-
rack (
|
61
|
-
rainbow (
|
62
|
-
rake
|
59
|
+
rack (1.6.8)
|
60
|
+
rainbow (3.0.0)
|
63
61
|
rake (12.3.0)
|
64
|
-
rdoc (5.
|
62
|
+
rdoc (5.1.0)
|
65
63
|
rspec (3.7.0)
|
66
64
|
rspec-core (~> 3.7.0)
|
67
65
|
rspec-expectations (~> 3.7.0)
|
68
66
|
rspec-mocks (~> 3.7.0)
|
69
|
-
rspec-core (3.7.
|
67
|
+
rspec-core (3.7.1)
|
70
68
|
rspec-support (~> 3.7.0)
|
71
69
|
rspec-expectations (3.7.0)
|
72
70
|
diff-lcs (>= 1.2.0, < 2.0)
|
@@ -75,16 +73,16 @@ GEM
|
|
75
73
|
diff-lcs (>= 1.2.0, < 2.0)
|
76
74
|
rspec-support (~> 3.7.0)
|
77
75
|
rspec-support (3.7.0)
|
78
|
-
rubocop (0.
|
76
|
+
rubocop (0.52.1)
|
79
77
|
parallel (~> 1.10)
|
80
|
-
parser (>= 2.
|
78
|
+
parser (>= 2.4.0.2, < 3.0)
|
81
79
|
powerpack (~> 0.1)
|
82
|
-
rainbow (>= 2.2.2, <
|
80
|
+
rainbow (>= 2.2.2, < 4.0)
|
83
81
|
ruby-progressbar (~> 1.7)
|
84
82
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
85
83
|
ruby-progressbar (1.9.0)
|
86
84
|
safe_yaml (1.0.4)
|
87
|
-
|
85
|
+
semver (1.0.1)
|
88
86
|
simplecov (0.15.1)
|
89
87
|
docile (~> 1.1.0)
|
90
88
|
json (>= 1.8, < 3)
|
@@ -92,8 +90,9 @@ GEM
|
|
92
90
|
simplecov-html (0.10.2)
|
93
91
|
thread_safe (0.3.6)
|
94
92
|
unicode-display_width (1.3.0)
|
93
|
+
url (0.3.2)
|
95
94
|
vcr (4.0.0)
|
96
|
-
webmock (3.
|
95
|
+
webmock (3.2.1)
|
97
96
|
addressable (>= 2.3.6)
|
98
97
|
crack (>= 0.3.2)
|
99
98
|
hashdiff
|
@@ -102,6 +101,7 @@ PLATFORMS
|
|
102
101
|
ruby
|
103
102
|
|
104
103
|
DEPENDENCIES
|
104
|
+
codecov
|
105
105
|
juwelier
|
106
106
|
rspec
|
107
107
|
rubocop
|
@@ -110,4 +110,4 @@ DEPENDENCIES
|
|
110
110
|
webmock
|
111
111
|
|
112
112
|
BUNDLED WITH
|
113
|
-
1.
|
113
|
+
1.16.0.pre.2
|
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)
|
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)
|
2
2
|
|
3
3
|
# DeepL for ruby
|
4
4
|
|
@@ -10,6 +10,7 @@ Install this gem with
|
|
10
10
|
|
11
11
|
```sh
|
12
12
|
gem install deepl-rb
|
13
|
+
# Load it in your ruby file using `require 'deepl'`
|
13
14
|
```
|
14
15
|
|
15
16
|
Or add it to your Gemfile:
|
@@ -48,35 +49,82 @@ end
|
|
48
49
|
To translate a simple text, use the `translate` method:
|
49
50
|
|
50
51
|
```rb
|
51
|
-
|
52
|
+
translation = DeepL.translate 'This is my text', 'EN', 'ES'
|
52
53
|
|
53
|
-
puts
|
54
|
+
puts translation.class
|
54
55
|
# => DeepL::Resources::Text
|
55
|
-
puts
|
56
|
+
puts translation.text
|
56
57
|
# => 'Este es mi texto'
|
57
58
|
```
|
58
59
|
|
59
|
-
|
60
|
+
Enable auto-detect source language by skipping the source language with `nil`:
|
60
61
|
|
61
62
|
```rb
|
62
|
-
|
63
|
+
translation = DeepL.translate 'This is my text', nil, 'ES'
|
63
64
|
|
64
|
-
puts
|
65
|
+
puts translation.detected_source_language
|
65
66
|
# => 'EN'
|
66
67
|
```
|
67
68
|
|
68
|
-
|
69
|
+
Translate a list of texts by passing an array as an argument:
|
69
70
|
|
70
71
|
```rb
|
71
72
|
texts = ['Sample text', 'Another text']
|
72
|
-
|
73
|
+
translations = DeepL.translate texts, 'EN', 'ES'
|
73
74
|
|
74
|
-
puts
|
75
|
+
puts translations.class
|
75
76
|
# => Array
|
76
|
-
puts
|
77
|
+
puts translations.first.class
|
77
78
|
# => DeepL::Resources::Text
|
78
79
|
```
|
79
80
|
|
81
|
+
Here's a list of available language codes:
|
82
|
+
|
83
|
+
| Language code | Language
|
84
|
+
| --------------- | ---------------
|
85
|
+
| `EN` | English
|
86
|
+
| `DE` | German
|
87
|
+
| `FR` | French
|
88
|
+
| `ES` | Spanish
|
89
|
+
| `IT` | Italian
|
90
|
+
| `NL` | Dutch
|
91
|
+
| `PL` | Polish
|
92
|
+
|
93
|
+
You can also use custom query parameters, like `tag_handling`:
|
94
|
+
|
95
|
+
```rb
|
96
|
+
texts = ['Sample text',¡]
|
97
|
+
translation = DeepL.translate '<p>A sample</p>', 'EN', 'ES', tag_handling: true
|
98
|
+
|
99
|
+
puts translation.text
|
100
|
+
# => ""
|
101
|
+
```
|
102
|
+
|
103
|
+
### Handle exceptions
|
104
|
+
|
105
|
+
You can capture and process exceptions that may be raised during API calls. These are all the possible exceptions:
|
106
|
+
|
107
|
+
| Exception class | Descripcion |
|
108
|
+
| --------------- | ----------- |
|
109
|
+
| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your auth_key value. |
|
110
|
+
| `DeepL::Exceptions::BadRequest` | Something is wrong in your request. Check `exception.message` for more information. |
|
111
|
+
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
112
|
+
| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
|
113
|
+
|
114
|
+
An exampling of handling a generic exception:
|
115
|
+
|
116
|
+
```rb
|
117
|
+
def my_method
|
118
|
+
item = DeepL.translate 'This is my text', nil, 'ES'
|
119
|
+
rescue DeepL::Exceptions::RequestError => e
|
120
|
+
puts 'Oops!'
|
121
|
+
puts "Code: #{e.response.code}"
|
122
|
+
puts "Response body: #{e.response.body}"
|
123
|
+
puts "Request body: #{e.request.body}"
|
124
|
+
end
|
125
|
+
|
126
|
+
```
|
127
|
+
|
80
128
|
## Development
|
81
129
|
|
82
130
|
Clone the repository, and install its dependencies:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/deepl-rb.gemspec
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
# Generated by juwelier
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Juwelier::Tasks in
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: deepl-rb 0.0
|
5
|
+
# stub: deepl-rb 1.0.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
|
-
s.name = "deepl-rb"
|
9
|
-
s.version = "0.0
|
8
|
+
s.name = "deepl-rb"
|
9
|
+
s.version = "1.0.0"
|
10
10
|
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0"
|
12
|
-
s.require_paths = ["lib"
|
13
|
-
s.authors = ["Daniel Herzog"
|
14
|
-
s.date = "
|
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"
|
16
|
-
s.email = "info@danielherzog.es"
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Daniel Herzog"]
|
14
|
+
s.date = "2018-01-04"
|
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"
|
16
|
+
s.email = "info@danielherzog.es"
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.md",
|
19
19
|
"README.md"
|
@@ -49,21 +49,21 @@ Gem::Specification.new do |s|
|
|
49
49
|
"spec/resources/text_spec.rb",
|
50
50
|
"spec/spec_helper.rb"
|
51
51
|
]
|
52
|
-
s.homepage = "http://github.com/wikiti/deepl-rb"
|
53
|
-
s.licenses = ["MIT"
|
54
|
-
s.rubygems_version = "2.
|
55
|
-
s.summary = "A simple ruby wrapper for the DeepL API"
|
52
|
+
s.homepage = "http://github.com/wikiti/deepl-rb"
|
53
|
+
s.licenses = ["MIT"]
|
54
|
+
s.rubygems_version = "2.2.2"
|
55
|
+
s.summary = "A simple ruby wrapper for the DeepL API"
|
56
56
|
|
57
57
|
if s.respond_to? :specification_version then
|
58
58
|
s.specification_version = 4
|
59
59
|
|
60
60
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
|
-
s.add_development_dependency(%q<juwelier
|
61
|
+
s.add_development_dependency(%q<juwelier>, [">= 0"])
|
62
62
|
else
|
63
|
-
s.add_dependency(%q<juwelier
|
63
|
+
s.add_dependency(%q<juwelier>, [">= 0"])
|
64
64
|
end
|
65
65
|
else
|
66
|
-
s.add_dependency(%q<juwelier
|
66
|
+
s.add_dependency(%q<juwelier>, [">= 0"])
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/lib/deepl.rb
CHANGED
@@ -31,10 +31,9 @@ module DeepL
|
|
31
31
|
@api ||= API.new(configuration)
|
32
32
|
end
|
33
33
|
|
34
|
-
def translate(text, options = {})
|
34
|
+
def translate(text, source_lang, target_lang, options = {})
|
35
35
|
configure if @configuration.nil?
|
36
|
-
Requests::TranslateText.new(api, text,
|
37
|
-
fetch(options, :target_lang)).request
|
36
|
+
Requests::TranslateText.new(api, text, source_lang, target_lang, options).request
|
38
37
|
end
|
39
38
|
|
40
39
|
# -- Configuration
|
@@ -47,10 +46,4 @@ module DeepL
|
|
47
46
|
yield configuration if block_given?
|
48
47
|
configuration.validate!
|
49
48
|
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def fetch(hash, key)
|
54
|
-
hash[key.to_s] || hash[key.to_sym]
|
55
|
-
end
|
56
49
|
end
|
data/lib/deepl/requests/base.rb
CHANGED
@@ -3,10 +3,11 @@ module DeepL
|
|
3
3
|
class Base
|
4
4
|
API_VERSION = 'v1'.freeze
|
5
5
|
|
6
|
-
attr_reader :api, :response
|
6
|
+
attr_reader :api, :response, :options
|
7
7
|
|
8
|
-
def initialize(api)
|
8
|
+
def initialize(api, options = {})
|
9
9
|
@api = api
|
10
|
+
@options = options
|
10
11
|
end
|
11
12
|
|
12
13
|
def request
|
@@ -15,9 +16,13 @@ module DeepL
|
|
15
16
|
|
16
17
|
private
|
17
18
|
|
19
|
+
def option(name)
|
20
|
+
options[name.to_s] || options[name.to_sym]
|
21
|
+
end
|
22
|
+
|
18
23
|
def post(payload)
|
19
24
|
request = Net::HTTP::Post.new(uri.request_uri)
|
20
|
-
request.set_form_data(payload.
|
25
|
+
request.set_form_data(payload.reject { |_, v| v.nil? })
|
21
26
|
response = http.request(request)
|
22
27
|
|
23
28
|
validate_response!(request, response)
|
@@ -65,7 +70,7 @@ module DeepL
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def query_params
|
68
|
-
{ auth_key: api.configuration.auth_key }
|
73
|
+
{ auth_key: api.configuration.auth_key }.merge(options)
|
69
74
|
end
|
70
75
|
end
|
71
76
|
end
|
@@ -3,8 +3,8 @@ module DeepL
|
|
3
3
|
class TranslateText < Base
|
4
4
|
attr_reader :text, :source_lang, :target_lang
|
5
5
|
|
6
|
-
def initialize(api, text, source_lang, target_lang)
|
7
|
-
super(api)
|
6
|
+
def initialize(api, text, source_lang, target_lang, options = {})
|
7
|
+
super(api, options)
|
8
8
|
@text = text
|
9
9
|
@source_lang = source_lang
|
10
10
|
@target_lang = target_lang
|
data/spec/api/deepl_spec.rb
CHANGED
@@ -41,6 +41,7 @@ describe DeepL do
|
|
41
41
|
let(:input) { 'Sample' }
|
42
42
|
let(:source_lang) { 'EN' }
|
43
43
|
let(:target_lang) { 'ES' }
|
44
|
+
let(:options) { { param: 'fake' } }
|
44
45
|
|
45
46
|
around do |example|
|
46
47
|
VCR.use_cassette('deepl_translate') { example.call }
|
@@ -49,9 +50,9 @@ describe DeepL do
|
|
49
50
|
context 'When translating a text' do
|
50
51
|
it 'should create and call a request object' do
|
51
52
|
expect(DeepL::Requests::TranslateText).to receive(:new)
|
52
|
-
.with(subject.api, input, source_lang, target_lang).and_call_original
|
53
|
+
.with(subject.api, input, source_lang, target_lang, options).and_call_original
|
53
54
|
|
54
|
-
text = subject.translate(input, source_lang
|
55
|
+
text = subject.translate(input, source_lang, target_lang, options)
|
55
56
|
expect(text).to be_a(DeepL::Resources::Text)
|
56
57
|
end
|
57
58
|
end
|
@@ -107,4 +107,41 @@ http_interactions:
|
|
107
107
|
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"}]}'
|
108
108
|
http_version:
|
109
109
|
recorded_at: Sun, 10 Dec 2017 21:22:11 GMT
|
110
|
+
- request:
|
111
|
+
method: post
|
112
|
+
uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN¶m=fake
|
113
|
+
body:
|
114
|
+
encoding: US-ASCII
|
115
|
+
string: text=Sample&source_lang=EN&target_lang=ES
|
116
|
+
headers:
|
117
|
+
Accept-Encoding:
|
118
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
119
|
+
Accept:
|
120
|
+
- "*/*"
|
121
|
+
User-Agent:
|
122
|
+
- Ruby
|
123
|
+
Content-Type:
|
124
|
+
- application/x-www-form-urlencoded
|
125
|
+
response:
|
126
|
+
status:
|
127
|
+
code: 200
|
128
|
+
message: OK
|
129
|
+
headers:
|
130
|
+
Server:
|
131
|
+
- nginx
|
132
|
+
Date:
|
133
|
+
- Thu, 04 Jan 2018 18:08:31 GMT
|
134
|
+
Content-Type:
|
135
|
+
- application/json
|
136
|
+
Content-Length:
|
137
|
+
- '69'
|
138
|
+
Connection:
|
139
|
+
- keep-alive
|
140
|
+
Access-Control-Allow-Origin:
|
141
|
+
- "*"
|
142
|
+
body:
|
143
|
+
encoding: UTF-8
|
144
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"}]}'
|
145
|
+
http_version:
|
146
|
+
recorded_at: Thu, 04 Jan 2018 18:08:31 GMT
|
110
147
|
recorded_with: VCR 4.0.0
|
@@ -36,7 +36,7 @@ http_interactions:
|
|
36
36
|
encoding: UTF-8
|
37
37
|
string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
|
38
38
|
muestra"}]}'
|
39
|
-
http_version:
|
39
|
+
http_version:
|
40
40
|
recorded_at: Sun, 10 Dec 2017 20:34:26 GMT
|
41
41
|
- request:
|
42
42
|
method: post
|
@@ -73,7 +73,7 @@ http_interactions:
|
|
73
73
|
body:
|
74
74
|
encoding: UTF-8
|
75
75
|
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
|
76
|
-
http_version:
|
76
|
+
http_version:
|
77
77
|
recorded_at: Sun, 10 Dec 2017 20:34:26 GMT
|
78
78
|
- request:
|
79
79
|
method: post
|
@@ -106,7 +106,7 @@ http_interactions:
|
|
106
106
|
body:
|
107
107
|
encoding: UTF-8
|
108
108
|
string: ''
|
109
|
-
http_version:
|
109
|
+
http_version:
|
110
110
|
recorded_at: Sun, 10 Dec 2017 20:34:27 GMT
|
111
111
|
- request:
|
112
112
|
method: post
|
@@ -139,7 +139,7 @@ http_interactions:
|
|
139
139
|
body:
|
140
140
|
encoding: UTF-8
|
141
141
|
string: '{"message":"Parameter ''text'' not specified."}'
|
142
|
-
http_version:
|
142
|
+
http_version:
|
143
143
|
recorded_at: Sun, 10 Dec 2017 20:34:27 GMT
|
144
144
|
- request:
|
145
145
|
method: post
|
@@ -172,6 +172,44 @@ http_interactions:
|
|
172
172
|
body:
|
173
173
|
encoding: UTF-8
|
174
174
|
string: '{"message":"Parameter ''target_lang'' not specified."}'
|
175
|
-
http_version:
|
175
|
+
http_version:
|
176
176
|
recorded_at: Sun, 10 Dec 2017 20:34:28 GMT
|
177
|
+
- request:
|
178
|
+
method: post
|
179
|
+
uri: https://api.deepl.com/v1/translate?auth_key=VALID_TOKEN
|
180
|
+
body:
|
181
|
+
encoding: US-ASCII
|
182
|
+
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
183
|
+
headers:
|
184
|
+
Accept-Encoding:
|
185
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
186
|
+
Accept:
|
187
|
+
- "*/*"
|
188
|
+
User-Agent:
|
189
|
+
- Ruby
|
190
|
+
Content-Type:
|
191
|
+
- application/x-www-form-urlencoded
|
192
|
+
response:
|
193
|
+
status:
|
194
|
+
code: 200
|
195
|
+
message: OK
|
196
|
+
headers:
|
197
|
+
Server:
|
198
|
+
- nginx
|
199
|
+
Date:
|
200
|
+
- Thu, 04 Jan 2018 18:09:50 GMT
|
201
|
+
Content-Type:
|
202
|
+
- application/json
|
203
|
+
Content-Length:
|
204
|
+
- '85'
|
205
|
+
Connection:
|
206
|
+
- keep-alive
|
207
|
+
Access-Control-Allow-Origin:
|
208
|
+
- "*"
|
209
|
+
body:
|
210
|
+
encoding: UTF-8
|
211
|
+
string: '{"translations":[{"detected_source_language":"EN","text":"<p>Texto
|
212
|
+
de muestra</p>"}]}'
|
213
|
+
http_version:
|
214
|
+
recorded_at: Thu, 04 Jan 2018 18:09:49 GMT
|
177
215
|
recorded_with: VCR 4.0.0
|
@@ -45,6 +45,18 @@ describe DeepL::Requests::TranslateText do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
context 'When performing a valid request with tag handling' do
|
49
|
+
let(:text) { '<p>Sample text</p>' }
|
50
|
+
|
51
|
+
it 'should return a text object' do
|
52
|
+
text = subject.request
|
53
|
+
|
54
|
+
expect(text).to be_a(DeepL::Resources::Text)
|
55
|
+
expect(text.text).to eq('<p>Texto de muestra</p>')
|
56
|
+
expect(text.detected_source_language).to eq('EN')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
48
60
|
context 'When performing a bad request' do
|
49
61
|
context 'When using an invalid token' do
|
50
62
|
let(:api) do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,18 @@
|
|
1
|
-
|
1
|
+
# Coverage
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
require 'codecov'
|
6
|
+
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
2
7
|
|
8
|
+
# Load lib
|
3
9
|
require_relative '../lib/deepl'
|
4
10
|
|
5
11
|
# Lib config
|
6
12
|
ENV['DEEPL_AUTH_KEY'] ||= 'TEST-TOKEN'
|
7
13
|
|
8
14
|
# VCR tapes configuration
|
15
|
+
require 'vcr'
|
9
16
|
VCR.configure do |config|
|
10
17
|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
11
18
|
config.hook_into :webmock
|
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: 0.0
|
4
|
+
version: 1.0.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:
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.2.2
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: A simple ruby wrapper for the DeepL API
|