deepl-rb 2.0.0 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -13
- data/.rubocop.yml +2 -1
- data/Gemfile +2 -0
- data/README.md +38 -17
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +8 -10
- data/lib/deepl.rb +3 -0
- data/lib/deepl/api.rb +2 -0
- data/lib/deepl/configuration.rb +4 -1
- data/lib/deepl/exceptions/authorization_failed.rb +2 -0
- data/lib/deepl/exceptions/bad_request.rb +2 -0
- data/lib/deepl/exceptions/error.rb +2 -0
- data/lib/deepl/exceptions/limit_exceeded.rb +2 -0
- data/lib/deepl/exceptions/quota_exceeded.rb +11 -0
- data/lib/deepl/exceptions/request_error.rb +4 -1
- data/lib/deepl/requests/base.rb +5 -4
- data/lib/deepl/requests/translate.rb +10 -3
- data/lib/deepl/requests/usage.rb +2 -0
- data/lib/deepl/resources/base.rb +2 -0
- data/lib/deepl/resources/text.rb +2 -0
- data/lib/deepl/resources/usage.rb +2 -0
- data/spec/api/api_spec.rb +2 -0
- data/spec/api/configuration_spec.rb +5 -1
- data/spec/api/deepl_spec.rb +4 -1
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +2 -2
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +1 -1
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +52 -13
- data/spec/fixtures/vcr_cassettes/usage.yml +1 -1
- data/spec/requests/translate_spec.rb +74 -1
- data/spec/requests/usage_spec.rb +2 -0
- data/spec/resources/text_spec.rb +2 -0
- data/spec/resources/usage_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +7 -8
- data/Gemfile.lock +0 -113
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 83485dc84bdce1dd11492bc0eb141825202b624e903cc747cc7bcc2f0afbc74e
|
4
|
+
data.tar.gz: 2f39d5af1a2926e123fa2fb1e3a3cae247546234f6382a0fc185f3e0fb5d7599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44bb0eb91abfea54a199830b26abdf52b275badcf3cad7ca0a905cd2bfef7360cd3ced29690047438f263c46dfa71e2ce9c34abab09b30f4af25565aac7309d4
|
7
|
+
data.tar.gz: df542383415d3c0eecb848d29e01c0c1e8ef2b8d7e272ce224383251ea1ca876edb4f6cc65f8c78f9978621f918cb75e946737a9bffc2a40fc8e87506bc5e5f3
|
data/.circleci/config.yml
CHANGED
@@ -3,26 +3,14 @@ jobs:
|
|
3
3
|
build:
|
4
4
|
working_directory: ~/deepl-rb
|
5
5
|
docker:
|
6
|
-
- image: circleci/ruby:2.
|
6
|
+
- image: circleci/ruby:2.7
|
7
7
|
steps:
|
8
8
|
- checkout
|
9
9
|
|
10
|
-
# Restore bundle cache
|
11
|
-
- type: cache-restore
|
12
|
-
name: Restore bundle cache
|
13
|
-
key: deepl-rb-bundle-{{ checksum "Gemfile.lock" }}
|
14
|
-
|
15
10
|
- run:
|
16
11
|
name: Bundle Install
|
17
12
|
command: bundle install --path vendor/bundle
|
18
13
|
|
19
|
-
# Store bundle cache
|
20
|
-
- type: cache-save
|
21
|
-
name: Store bundle cache
|
22
|
-
key: deepl-rb-bundle-{{ checksum "Gemfile.lock" }}
|
23
|
-
paths:
|
24
|
-
- vendor/bundle
|
25
|
-
|
26
14
|
# Run rspec
|
27
15
|
- type: shell
|
28
16
|
command: |
|
data/.rubocop.yml
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
AllCops:
|
4
4
|
DisplayCopNames: true
|
5
|
+
NewCops: enable
|
5
6
|
Exclude:
|
6
7
|
- deepl-rb.gemspec
|
7
8
|
- vendor/**/*
|
@@ -11,7 +12,7 @@ Metrics/BlockLength:
|
|
11
12
|
- "**/*_spec.rb"
|
12
13
|
|
13
14
|
Metrics/LineLength:
|
14
|
-
Max:
|
15
|
+
Max: 100
|
15
16
|
|
16
17
|
Style/Documentation:
|
17
18
|
Enabled: false
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/deepl-rb.svg)](https://badge.fury.io/rb/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
|
|
5
|
-
A simple ruby wrapper for the [DeepL translation API (
|
5
|
+
A simple ruby wrapper for the [DeepL translation API (v2)](https://www.deepl.com/api.html).
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -35,12 +35,13 @@ DeepL.configure do |config|
|
|
35
35
|
end
|
36
36
|
```
|
37
37
|
|
38
|
-
You can also configure the
|
38
|
+
You can also configure the API host and the API version:
|
39
39
|
|
40
40
|
```rb
|
41
41
|
DeepL.configure do |config|
|
42
42
|
config.auth_key = 'your-api-token'
|
43
43
|
config.host = 'https://test-api.deepl.com' # Default value is 'https://api.deepl.com'
|
44
|
+
config.version = 'v1' # Default value is 'v2'
|
44
45
|
end
|
45
46
|
```
|
46
47
|
|
@@ -86,15 +87,18 @@ Here's a list of available language codes:
|
|
86
87
|
| `DE` | German
|
87
88
|
| `FR` | French
|
88
89
|
| `ES` | Spanish
|
90
|
+
| `PT` | Portuguese
|
89
91
|
| `IT` | Italian
|
90
92
|
| `NL` | Dutch
|
91
93
|
| `PL` | Polish
|
94
|
+
| `RU` | Russian
|
92
95
|
|
93
|
-
You can also use custom query parameters, like `tag_handling` or `
|
96
|
+
You can also use custom query parameters, like `tag_handling`, `split_sentences`, `non_splitting_tags` or `ignore_tags`:
|
94
97
|
|
95
98
|
```rb
|
96
99
|
translation = DeepL.translate '<p>A sample</p>', 'EN', 'ES',
|
97
|
-
tag_handling: 'xml', split_sentences: false
|
100
|
+
tag_handling: 'xml', split_sentences: false,
|
101
|
+
non_splitting_tags: 'h1', ignore_tags: %w[code pre]
|
98
102
|
|
99
103
|
puts translation.text
|
100
104
|
# => "<p>Una muestra</p>"
|
@@ -104,8 +108,10 @@ The following parameters will be automatically converted:
|
|
104
108
|
|
105
109
|
| Parameter | Conversion
|
106
110
|
| --------------------- | ---------------
|
107
|
-
| `preserve_formatting` |
|
108
|
-
| `split_sentences` |
|
111
|
+
| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
|
112
|
+
| `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
|
113
|
+
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
114
|
+
| `ignore_tags` | Converts arrays to strings joining by commas
|
109
115
|
|
110
116
|
### Usage
|
111
117
|
|
@@ -124,11 +130,12 @@ puts usage.character_limit
|
|
124
130
|
|
125
131
|
You can capture and process exceptions that may be raised during API calls. These are all the possible exceptions:
|
126
132
|
|
127
|
-
| Exception class |
|
133
|
+
| Exception class | Description |
|
128
134
|
| --------------- | ----------- |
|
129
|
-
| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your auth_key value. |
|
135
|
+
| `DeepL::Exceptions::AuthorizationFailed` | The authorization process has failed. Check your `auth_key` value. |
|
130
136
|
| `DeepL::Exceptions::BadRequest` | Something is wrong in your request. Check `exception.message` for more information. |
|
131
137
|
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
138
|
+
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
|
132
139
|
| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
|
133
140
|
|
134
141
|
An exampling of handling a generic exception:
|
@@ -142,9 +149,31 @@ rescue DeepL::Exceptions::RequestError => e
|
|
142
149
|
puts "Response body: #{e.response.body}"
|
143
150
|
puts "Request body: #{e.request.body}"
|
144
151
|
end
|
152
|
+
```
|
153
|
+
|
154
|
+
## Integrations
|
155
|
+
|
156
|
+
### Ruby on Rails
|
157
|
+
|
158
|
+
You may use this gem as a standalone service by creating an initializer on your
|
159
|
+
`config/initializers` folder with your DeepL configuration. For example:
|
145
160
|
|
161
|
+
```rb
|
162
|
+
# config/initializers/deepl.rb
|
163
|
+
DeepL.configure do |config|
|
164
|
+
# Your configuration goes here
|
165
|
+
end
|
146
166
|
```
|
147
167
|
|
168
|
+
Since the DeepL service is defined globally, you can use service anywhere in your code
|
169
|
+
(controllers, models, views, jobs, plain ruby objects… you name it).
|
170
|
+
|
171
|
+
### i18n-tasks
|
172
|
+
|
173
|
+
You may also take a look at [`i18n-tasks`](https://github.com/glebm/i18n-tasks), which is a gem
|
174
|
+
that helps you find and manage missing and unused translations. `deepl-rb` is used as one of the
|
175
|
+
backend services to translate content.
|
176
|
+
|
148
177
|
## Development
|
149
178
|
|
150
179
|
Clone the repository, and install its dependencies:
|
@@ -160,11 +189,3 @@ To run tests (rspec and rubocop), use
|
|
160
189
|
```
|
161
190
|
bundle exec rake test
|
162
191
|
```
|
163
|
-
|
164
|
-
## Contributors
|
165
|
-
|
166
|
-
This project has been developed by:
|
167
|
-
|
168
|
-
| Avatar | Name | Nickname | Email |
|
169
|
-
| ------ | ---- | -------- | ----- |
|
170
|
-
| ![](http://www.gravatar.com/avatar/2ae6d81e0605177ba9e17b19f54e6b6c.jpg?s=64) | Daniel Herzog | Wikiti | [info@danielherzog.es](mailto:info@danielherzog.es)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.3
|
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
|
+
# stub: deepl-rb 2.2.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "2.
|
9
|
+
s.version = "2.2.3"
|
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 = "
|
14
|
+
s.date = "2020-11-14"
|
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 = [
|
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
|
|
22
22
|
".circleci/config.yml",
|
23
23
|
".rubocop.yml",
|
24
24
|
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
25
|
"LICENSE.md",
|
27
26
|
"README.md",
|
28
27
|
"Rakefile",
|
@@ -35,6 +34,7 @@ Gem::Specification.new do |s|
|
|
35
34
|
"lib/deepl/exceptions/bad_request.rb",
|
36
35
|
"lib/deepl/exceptions/error.rb",
|
37
36
|
"lib/deepl/exceptions/limit_exceeded.rb",
|
37
|
+
"lib/deepl/exceptions/quota_exceeded.rb",
|
38
38
|
"lib/deepl/exceptions/request_error.rb",
|
39
39
|
"lib/deepl/requests/base.rb",
|
40
40
|
"lib/deepl/requests/translate.rb",
|
@@ -57,17 +57,15 @@ Gem::Specification.new do |s|
|
|
57
57
|
]
|
58
58
|
s.homepage = "http://github.com/wikiti/deepl-rb".freeze
|
59
59
|
s.licenses = ["MIT".freeze]
|
60
|
-
s.rubygems_version = "
|
60
|
+
s.rubygems_version = "3.1.2".freeze
|
61
61
|
s.summary = "A simple ruby wrapper for the DeepL API".freeze
|
62
62
|
|
63
63
|
if s.respond_to? :specification_version then
|
64
64
|
s.specification_version = 4
|
65
|
+
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
else
|
69
|
-
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
70
|
-
end
|
67
|
+
if s.respond_to? :add_runtime_dependency then
|
68
|
+
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
71
69
|
else
|
72
70
|
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
73
71
|
end
|
data/lib/deepl.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# -- Dependencies
|
2
4
|
require 'json'
|
3
5
|
require 'net/http'
|
@@ -8,6 +10,7 @@ require 'deepl/exceptions/request_error'
|
|
8
10
|
require 'deepl/exceptions/authorization_failed'
|
9
11
|
require 'deepl/exceptions/bad_request'
|
10
12
|
require 'deepl/exceptions/limit_exceeded'
|
13
|
+
require 'deepl/exceptions/quota_exceeded'
|
11
14
|
|
12
15
|
# -- Requests
|
13
16
|
require 'deepl/requests/base'
|
data/lib/deepl/api.rb
CHANGED
data/lib/deepl/configuration.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeepL
|
2
4
|
class Configuration
|
3
|
-
ATTRIBUTES = %i[auth_key host].freeze
|
5
|
+
ATTRIBUTES = %i[auth_key host version].freeze
|
4
6
|
|
5
7
|
attr_accessor(*ATTRIBUTES)
|
6
8
|
|
@@ -8,6 +10,7 @@ module DeepL
|
|
8
10
|
data.each { |key, value| send("#{key}=", value) }
|
9
11
|
@auth_key ||= ENV['DEEPL_AUTH_KEY']
|
10
12
|
@host ||= 'https://api.deepl.com'
|
13
|
+
@version ||= 'v2'
|
11
14
|
end
|
12
15
|
|
13
16
|
def validate!
|
@@ -1,15 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeepL
|
2
4
|
module Exceptions
|
3
5
|
class RequestError < Error
|
4
6
|
attr_reader :request, :response
|
5
7
|
|
6
8
|
def initialize(request, response)
|
9
|
+
super()
|
7
10
|
@request = request
|
8
11
|
@response = response
|
9
12
|
end
|
10
13
|
|
11
14
|
def message
|
12
|
-
'
|
15
|
+
'Unknown error.'
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
data/lib/deepl/requests/base.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeepL
|
2
4
|
module Requests
|
3
5
|
class Base
|
4
|
-
API_VERSION = 'v1'.freeze
|
5
|
-
|
6
6
|
attr_reader :api, :response, :options
|
7
7
|
|
8
8
|
def initialize(api, options = {})
|
@@ -34,7 +34,7 @@ module DeepL
|
|
34
34
|
|
35
35
|
def post(payload)
|
36
36
|
request = Net::HTTP::Post.new(uri.request_uri)
|
37
|
-
request.set_form_data(payload.
|
37
|
+
request.set_form_data(payload.compact)
|
38
38
|
response = http.request(request)
|
39
39
|
|
40
40
|
validate_response!(request, response)
|
@@ -64,6 +64,7 @@ module DeepL
|
|
64
64
|
when '400' then raise Exceptions::BadRequest.new(request, response)
|
65
65
|
when '403' then raise Exceptions::AuthorizationFailed.new(request, response)
|
66
66
|
when '429' then raise Exceptions::LimitExceeded.new(request, response)
|
67
|
+
when '456' then raise Exceptions::QuotaExceeded.new(request, response)
|
67
68
|
else raise Exceptions::RequestError.new(request, response)
|
68
69
|
end
|
69
70
|
end
|
@@ -73,7 +74,7 @@ module DeepL
|
|
73
74
|
end
|
74
75
|
|
75
76
|
def url
|
76
|
-
"#{host}/#{
|
77
|
+
"#{host}/#{api.configuration.version}/#{path}"
|
77
78
|
end
|
78
79
|
|
79
80
|
def uri
|
@@ -1,12 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DeepL
|
2
4
|
module Requests
|
3
5
|
class Translate < Base
|
6
|
+
BOOLEAN_CONVERSION = { true => '1', false => '0' }.freeze
|
7
|
+
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(', ') : value }.freeze
|
4
8
|
OPTIONS_CONVERSIONS = {
|
5
|
-
split_sentences:
|
6
|
-
preserve_formatting:
|
9
|
+
split_sentences: BOOLEAN_CONVERSION,
|
10
|
+
preserve_formatting: BOOLEAN_CONVERSION,
|
11
|
+
non_splitting_tags: ARRAY_CONVERSION,
|
12
|
+
ignore_tags: ARRAY_CONVERSION
|
7
13
|
}.freeze
|
8
14
|
|
9
|
-
attr_reader :text, :source_lang, :target_lang
|
15
|
+
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :non_splitting_tags
|
10
16
|
|
11
17
|
def initialize(api, text, source_lang, target_lang, options = {})
|
12
18
|
super(api, options)
|
@@ -27,6 +33,7 @@ module DeepL
|
|
27
33
|
def tweak_parameters!
|
28
34
|
OPTIONS_CONVERSIONS.each do |param, converter|
|
29
35
|
next unless option?(param) && converter[option(param)]
|
36
|
+
|
30
37
|
set_option(param, converter[option(param)])
|
31
38
|
end
|
32
39
|
end
|
data/lib/deepl/requests/usage.rb
CHANGED
data/lib/deepl/resources/base.rb
CHANGED
data/lib/deepl/resources/text.rb
CHANGED
data/spec/api/api_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe DeepL::Configuration do
|
@@ -9,15 +11,17 @@ describe DeepL::Configuration do
|
|
9
11
|
it 'should use default attributes' do
|
10
12
|
expect(subject.auth_key).to eq(ENV['DEEPL_AUTH_KEY'])
|
11
13
|
expect(subject.host).to eq('https://api.deepl.com')
|
14
|
+
expect(subject.version).to eq('v2')
|
12
15
|
end
|
13
16
|
end
|
14
17
|
|
15
18
|
context 'When using custom configuration attributes' do
|
16
|
-
let(:attributes) { { auth_key: 'SAMPLE', host: 'http://www.example.org' } }
|
19
|
+
let(:attributes) { { auth_key: 'SAMPLE', host: 'http://www.example.org', version: 'v1' } }
|
17
20
|
|
18
21
|
it 'should use custom attributes' do
|
19
22
|
expect(subject.auth_key).to eq(attributes[:auth_key])
|
20
23
|
expect(subject.host).to eq(attributes[:host])
|
24
|
+
expect(subject.version).to eq(attributes[:version])
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/spec/api/deepl_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe DeepL do
|
@@ -15,12 +17,13 @@ describe DeepL do
|
|
15
17
|
|
16
18
|
context 'When providing a valid configuration' do
|
17
19
|
let(:configuration) do
|
18
|
-
DeepL::Configuration.new(auth_key: 'VALID', host: 'http://www.example.org')
|
20
|
+
DeepL::Configuration.new(auth_key: 'VALID', host: 'http://www.example.org', version: 'v1')
|
19
21
|
end
|
20
22
|
before do
|
21
23
|
subject.configure do |config|
|
22
24
|
config.auth_key = configuration.auth_key
|
23
25
|
config.host = configuration.host
|
26
|
+
config.version = configuration.version
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://api.deepl.com/
|
5
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN¶m=fake
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: text=Sample&source_lang=EN&target_lang=ES
|
@@ -35,6 +35,6 @@ http_interactions:
|
|
35
35
|
body:
|
36
36
|
encoding: UTF-8
|
37
37
|
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"}]}'
|
38
|
-
http_version:
|
38
|
+
http_version:
|
39
39
|
recorded_at: Tue, 08 May 2018 16:31:33 GMT
|
40
40
|
recorded_with: VCR 4.0.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://api.deepl.com/
|
5
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: text=Sample+text&source_lang=EN&target_lang=ES
|
@@ -34,12 +34,13 @@ http_interactions:
|
|
34
34
|
- "*"
|
35
35
|
body:
|
36
36
|
encoding: UTF-8
|
37
|
-
string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
|
38
|
-
|
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
|
42
|
-
uri: https://api.deepl.com/
|
43
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
43
44
|
body:
|
44
45
|
encoding: US-ASCII
|
45
46
|
string: text=Sample&text=Word&source_lang=EN&target_lang=ES
|
@@ -72,11 +73,11 @@ 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
|
79
|
-
uri: https://api.deepl.com/
|
80
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
80
81
|
body:
|
81
82
|
encoding: US-ASCII
|
82
83
|
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
@@ -110,11 +111,11 @@ 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
|
117
|
-
uri: https://api.deepl.com/
|
118
|
+
uri: https://api.deepl.com/v2/translate?auth_key=invalid
|
118
119
|
body:
|
119
120
|
encoding: US-ASCII
|
120
121
|
string: text=Sample+text&source_lang=EN&target_lang=ES
|
@@ -143,11 +144,11 @@ 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
|
150
|
-
uri: https://api.deepl.com/
|
151
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
151
152
|
body:
|
152
153
|
encoding: US-ASCII
|
153
154
|
string: source_lang=EN&target_lang=ES
|
@@ -176,11 +177,11 @@ 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
|
183
|
-
uri: https://api.deepl.com/
|
184
|
+
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
184
185
|
body:
|
185
186
|
encoding: US-ASCII
|
186
187
|
string: text=Sample+text&source_lang=EN
|
@@ -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/v2/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,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe DeepL::Requests::Translate do
|
6
|
+
let(:tags_str) { 'p, strong, span' }
|
7
|
+
let(:tags_array) { %w[p strong span] }
|
8
|
+
|
4
9
|
let(:api) { build_deepl_api }
|
5
10
|
let(:text) { 'Sample text' }
|
6
11
|
let(:source_lang) { 'EN' }
|
7
12
|
let(:target_lang) { 'ES' }
|
8
|
-
|
13
|
+
let(:options) { {} }
|
14
|
+
subject { DeepL::Requests::Translate.new(api, text, source_lang, target_lang, options) }
|
9
15
|
|
10
16
|
describe '#initialize' do
|
11
17
|
context 'When building a request' do
|
@@ -14,6 +20,60 @@ describe DeepL::Requests::Translate do
|
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
23
|
+
context 'when using `non_splitting_tags` options' do
|
24
|
+
it 'should work with a nil values' do
|
25
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: nil)
|
26
|
+
expect(request.options[:non_splitting_tags]).to eq(nil)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should work with a blank list' do
|
30
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: '')
|
31
|
+
expect(request.options[:non_splitting_tags]).to eq('')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should work with a comma-separated list' do
|
35
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_str)
|
36
|
+
expect(request.options[:non_splitting_tags]).to eq(tags_str)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should convert arrays to strings' do
|
40
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_array)
|
41
|
+
expect(request.options[:non_splitting_tags]).to eq(tags_str)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should leave strings as they are' do
|
45
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, non_splitting_tags: tags_str)
|
46
|
+
expect(request.options[:non_splitting_tags]).to eq(tags_str)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when using `ignore_tags` options' do
|
51
|
+
it 'should work with a nil values' do
|
52
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: nil)
|
53
|
+
expect(request.options[:ignore_tags]).to eq(nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should work with a blank list' do
|
57
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: '')
|
58
|
+
expect(request.options[:ignore_tags]).to eq('')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should work with a comma-separated list' do
|
62
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_str)
|
63
|
+
expect(request.options[:ignore_tags]).to eq(tags_str)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should convert arrays to strings' do
|
67
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_array)
|
68
|
+
expect(request.options[:ignore_tags]).to eq(tags_str)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should leave strings as they are' do
|
72
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, ignore_tags: tags_str)
|
73
|
+
expect(request.options[:ignore_tags]).to eq(tags_str)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
17
77
|
context 'when using `split_sentences` options' do
|
18
78
|
it 'should convert `true` to `1`' do
|
19
79
|
request = DeepL::Requests::Translate.new(api, nil, nil, nil, split_sentences: true)
|
@@ -101,6 +161,19 @@ describe DeepL::Requests::Translate do
|
|
101
161
|
end
|
102
162
|
end
|
103
163
|
|
164
|
+
context 'When performing a valid request and passing a variable' do
|
165
|
+
let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
|
166
|
+
let(:options) { { ignore_tags: 'code, span' } }
|
167
|
+
|
168
|
+
it 'should return a text object' do
|
169
|
+
text = subject.request
|
170
|
+
|
171
|
+
expect(text).to be_a(DeepL::Resources::Text)
|
172
|
+
expect(text.text).to eq('Bienvenido y <code>Hello great World</code> Buenos días!')
|
173
|
+
expect(text.detected_source_language).to eq('EN')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
104
177
|
context 'When performing a bad request' do
|
105
178
|
context 'When using an invalid token' do
|
106
179
|
let(:api) do
|
data/spec/requests/usage_spec.rb
CHANGED
data/spec/resources/text_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Herzog
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|
@@ -36,7 +36,6 @@ files:
|
|
36
36
|
- ".circleci/config.yml"
|
37
37
|
- ".rubocop.yml"
|
38
38
|
- Gemfile
|
39
|
-
- Gemfile.lock
|
40
39
|
- LICENSE.md
|
41
40
|
- README.md
|
42
41
|
- Rakefile
|
@@ -49,6 +48,7 @@ files:
|
|
49
48
|
- lib/deepl/exceptions/bad_request.rb
|
50
49
|
- lib/deepl/exceptions/error.rb
|
51
50
|
- lib/deepl/exceptions/limit_exceeded.rb
|
51
|
+
- lib/deepl/exceptions/quota_exceeded.rb
|
52
52
|
- lib/deepl/exceptions/request_error.rb
|
53
53
|
- lib/deepl/requests/base.rb
|
54
54
|
- lib/deepl/requests/translate.rb
|
@@ -72,7 +72,7 @@ homepage: http://github.com/wikiti/deepl-rb
|
|
72
72
|
licenses:
|
73
73
|
- MIT
|
74
74
|
metadata: {}
|
75
|
-
post_install_message:
|
75
|
+
post_install_message:
|
76
76
|
rdoc_options: []
|
77
77
|
require_paths:
|
78
78
|
- lib
|
@@ -87,9 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
requirements: []
|
90
|
-
|
91
|
-
|
92
|
-
signing_key:
|
90
|
+
rubygems_version: 3.1.2
|
91
|
+
signing_key:
|
93
92
|
specification_version: 4
|
94
93
|
summary: A simple ruby wrapper for the DeepL API
|
95
94
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: https://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.5.2)
|
5
|
-
public_suffix (>= 2.0.2, < 4.0)
|
6
|
-
ast (2.3.0)
|
7
|
-
builder (3.2.3)
|
8
|
-
codecov (0.1.10)
|
9
|
-
json
|
10
|
-
simplecov
|
11
|
-
url
|
12
|
-
crack (0.4.3)
|
13
|
-
safe_yaml (~> 1.0.0)
|
14
|
-
descendants_tracker (0.0.4)
|
15
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
16
|
-
diff-lcs (1.3)
|
17
|
-
docile (1.1.5)
|
18
|
-
faraday (0.12.2)
|
19
|
-
multipart-post (>= 1.2, < 3)
|
20
|
-
git (1.3.0)
|
21
|
-
github_api (0.18.2)
|
22
|
-
addressable (~> 2.4)
|
23
|
-
descendants_tracker (~> 0.0.4)
|
24
|
-
faraday (~> 0.8)
|
25
|
-
hashie (~> 3.5, >= 3.5.2)
|
26
|
-
oauth2 (~> 1.0)
|
27
|
-
hashdiff (0.3.7)
|
28
|
-
hashie (3.5.7)
|
29
|
-
highline (1.7.10)
|
30
|
-
json (2.1.0)
|
31
|
-
juwelier (2.1.3)
|
32
|
-
builder
|
33
|
-
bundler (>= 1.13)
|
34
|
-
git (>= 1.2.5)
|
35
|
-
github_api
|
36
|
-
highline (>= 1.6.15)
|
37
|
-
nokogiri (>= 1.5.10)
|
38
|
-
rake
|
39
|
-
rdoc
|
40
|
-
semver
|
41
|
-
jwt (1.5.6)
|
42
|
-
mini_portile2 (2.3.0)
|
43
|
-
multi_json (1.12.2)
|
44
|
-
multi_xml (0.6.0)
|
45
|
-
multipart-post (2.0.0)
|
46
|
-
nokogiri (1.8.1)
|
47
|
-
mini_portile2 (~> 2.3.0)
|
48
|
-
oauth2 (1.4.0)
|
49
|
-
faraday (>= 0.8, < 0.13)
|
50
|
-
jwt (~> 1.0)
|
51
|
-
multi_json (~> 1.3)
|
52
|
-
multi_xml (~> 0.5)
|
53
|
-
rack (>= 1.2, < 3)
|
54
|
-
parallel (1.12.1)
|
55
|
-
parser (2.4.0.2)
|
56
|
-
ast (~> 2.3)
|
57
|
-
powerpack (0.1.1)
|
58
|
-
public_suffix (3.0.1)
|
59
|
-
rack (1.6.8)
|
60
|
-
rainbow (3.0.0)
|
61
|
-
rake (12.3.0)
|
62
|
-
rdoc (5.1.0)
|
63
|
-
rspec (3.7.0)
|
64
|
-
rspec-core (~> 3.7.0)
|
65
|
-
rspec-expectations (~> 3.7.0)
|
66
|
-
rspec-mocks (~> 3.7.0)
|
67
|
-
rspec-core (3.7.1)
|
68
|
-
rspec-support (~> 3.7.0)
|
69
|
-
rspec-expectations (3.7.0)
|
70
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
-
rspec-support (~> 3.7.0)
|
72
|
-
rspec-mocks (3.7.0)
|
73
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
-
rspec-support (~> 3.7.0)
|
75
|
-
rspec-support (3.7.0)
|
76
|
-
rubocop (0.52.1)
|
77
|
-
parallel (~> 1.10)
|
78
|
-
parser (>= 2.4.0.2, < 3.0)
|
79
|
-
powerpack (~> 0.1)
|
80
|
-
rainbow (>= 2.2.2, < 4.0)
|
81
|
-
ruby-progressbar (~> 1.7)
|
82
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
83
|
-
ruby-progressbar (1.9.0)
|
84
|
-
safe_yaml (1.0.4)
|
85
|
-
semver (1.0.1)
|
86
|
-
simplecov (0.15.1)
|
87
|
-
docile (~> 1.1.0)
|
88
|
-
json (>= 1.8, < 3)
|
89
|
-
simplecov-html (~> 0.10.0)
|
90
|
-
simplecov-html (0.10.2)
|
91
|
-
thread_safe (0.3.6)
|
92
|
-
unicode-display_width (1.3.0)
|
93
|
-
url (0.3.2)
|
94
|
-
vcr (4.0.0)
|
95
|
-
webmock (3.2.1)
|
96
|
-
addressable (>= 2.3.6)
|
97
|
-
crack (>= 0.3.2)
|
98
|
-
hashdiff
|
99
|
-
|
100
|
-
PLATFORMS
|
101
|
-
ruby
|
102
|
-
|
103
|
-
DEPENDENCIES
|
104
|
-
codecov
|
105
|
-
juwelier
|
106
|
-
rspec
|
107
|
-
rubocop
|
108
|
-
simplecov
|
109
|
-
vcr
|
110
|
-
webmock
|
111
|
-
|
112
|
-
BUNDLED WITH
|
113
|
-
1.16.0.pre.2
|