deepl-rb 2.2.3 → 2.4.0
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 +4 -4
- data/Gemfile +4 -0
- data/README.md +37 -16
- data/VERSION +1 -1
- data/deepl-rb.gemspec +12 -3
- data/lib/deepl/configuration.rb +1 -1
- data/lib/deepl/exceptions/bad_request.rb +2 -0
- data/lib/deepl/exceptions/not_supported.rb +11 -0
- data/lib/deepl/requests/languages.rb +30 -0
- data/lib/deepl/requests/translate.rb +1 -0
- data/lib/deepl/resources/language.rb +27 -0
- data/lib/deepl.rb +7 -0
- data/spec/api/configuration_spec.rb +1 -1
- data/spec/api/deepl_spec.rb +22 -0
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +41 -0
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +4 -5
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +10 -7
- data/spec/fixtures/vcr_cassettes/languages.yml +108 -0
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +105 -33
- data/spec/fixtures/vcr_cassettes/usage.yml +10 -7
- data/spec/requests/languages_spec.rb +58 -0
- data/spec/requests/translate_spec.rb +55 -3
- data/spec/resources/language_spec.rb +42 -0
- data/spec/resources/text_spec.rb +2 -2
- data/spec/resources/usage_spec.rb +3 -3
- data/spec/spec_helper.rb +1 -1
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f9236d354e5ca92bb03e6c8f34e9b332dff42c1bd985a80193b39f7509bbf99
|
4
|
+
data.tar.gz: d0796f1d303279647026c81a588f1d8442b526edc9c0f7be13252fff7cbd957b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c30aea5725784be6a7766bc9d7c8a0909338937352dfbe04254341d7355f12ffad801c14364b10a8b0eefccc52dd003783e22f3b9679f65767fb664b27b710f
|
7
|
+
data.tar.gz: 3a4b61ebfdd6f130ec1d24a0d7ee81c7cab1b783dfb7a6e113a2af91f4240863fe727c5a054b9487e3d4bd2af011d644d15b426ae46a1c435b89ade536cc7c6a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -40,11 +40,42 @@ You can also configure the API host and the API version:
|
|
40
40
|
```rb
|
41
41
|
DeepL.configure do |config|
|
42
42
|
config.auth_key = 'your-api-token'
|
43
|
-
config.host = 'https://
|
43
|
+
config.host = 'https://api-free.deepl.com' # Default value is 'https://api.deepl.com'
|
44
44
|
config.version = 'v1' # Default value is 'v2'
|
45
45
|
end
|
46
46
|
```
|
47
47
|
|
48
|
+
### Available languages
|
49
|
+
|
50
|
+
Available languages can be retrieved via API:
|
51
|
+
|
52
|
+
```rb
|
53
|
+
languages = DeepL.languages
|
54
|
+
|
55
|
+
puts languages.class
|
56
|
+
# => Array
|
57
|
+
puts languages.first.class
|
58
|
+
# => DeepL::Resources::Language
|
59
|
+
puts "#{languages.first.code} -> #{languages.first.name}"
|
60
|
+
# => "ES -> Spanish"
|
61
|
+
```
|
62
|
+
|
63
|
+
Note that source and target languages may be different, which can be retrieved by using the `type`
|
64
|
+
option:
|
65
|
+
|
66
|
+
```rb
|
67
|
+
puts DeepL.languages(type: :source).count
|
68
|
+
# => 24
|
69
|
+
puts DeepL.languages(type: :target).count
|
70
|
+
# => 26
|
71
|
+
```
|
72
|
+
|
73
|
+
All languages are also defined on the
|
74
|
+
[official API documentation](https://www.deepl.com/docs-api/translating-text/).
|
75
|
+
|
76
|
+
Note that target languages may include the `supports_formality` flag, which may be checked
|
77
|
+
using the `DeepL::Resources::Language#supports_formality?`.
|
78
|
+
|
48
79
|
### Translate
|
49
80
|
|
50
81
|
To translate a simple text, use the `translate` method:
|
@@ -79,20 +110,6 @@ puts translations.first.class
|
|
79
110
|
# => DeepL::Resources::Text
|
80
111
|
```
|
81
112
|
|
82
|
-
Here's a list of available language codes:
|
83
|
-
|
84
|
-
| Language code | Language
|
85
|
-
| --------------- | ---------------
|
86
|
-
| `EN` | English
|
87
|
-
| `DE` | German
|
88
|
-
| `FR` | French
|
89
|
-
| `ES` | Spanish
|
90
|
-
| `PT` | Portuguese
|
91
|
-
| `IT` | Italian
|
92
|
-
| `NL` | Dutch
|
93
|
-
| `PL` | Polish
|
94
|
-
| `RU` | Russian
|
95
|
-
|
96
113
|
You can also use custom query parameters, like `tag_handling`, `split_sentences`, `non_splitting_tags` or `ignore_tags`:
|
97
114
|
|
98
115
|
```rb
|
@@ -110,10 +127,13 @@ The following parameters will be automatically converted:
|
|
110
127
|
| --------------------- | ---------------
|
111
128
|
| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
|
112
129
|
| `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
|
130
|
+
| `outline_detection` | Converts `false` to `'0'` and `true` to `'1'`
|
113
131
|
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
114
132
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
133
|
+
| `formality` | No conversion applied
|
134
|
+
| `glossary_id` | No conversion applied
|
115
135
|
|
116
|
-
###
|
136
|
+
### Monitor usage
|
117
137
|
|
118
138
|
To check current API usage, use:
|
119
139
|
|
@@ -137,6 +157,7 @@ You can capture and process exceptions that may be raised during API calls. Thes
|
|
137
157
|
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
138
158
|
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
|
139
159
|
| `DeepL::Exceptions::RequestError` | An unkown request error. Check `exception.response` and `exception.request` for more information. |
|
160
|
+
| `DeepL::Exceptions::NotSupported` | The requested method or API endpoint is not supported. |
|
140
161
|
|
141
162
|
An exampling of handling a generic exception:
|
142
163
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.0
|
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.4.0 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.4.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 = "
|
14
|
+
s.date = "2022-01-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 = [
|
@@ -34,23 +34,30 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/deepl/exceptions/bad_request.rb",
|
35
35
|
"lib/deepl/exceptions/error.rb",
|
36
36
|
"lib/deepl/exceptions/limit_exceeded.rb",
|
37
|
+
"lib/deepl/exceptions/not_supported.rb",
|
37
38
|
"lib/deepl/exceptions/quota_exceeded.rb",
|
38
39
|
"lib/deepl/exceptions/request_error.rb",
|
39
40
|
"lib/deepl/requests/base.rb",
|
41
|
+
"lib/deepl/requests/languages.rb",
|
40
42
|
"lib/deepl/requests/translate.rb",
|
41
43
|
"lib/deepl/requests/usage.rb",
|
42
44
|
"lib/deepl/resources/base.rb",
|
45
|
+
"lib/deepl/resources/language.rb",
|
43
46
|
"lib/deepl/resources/text.rb",
|
44
47
|
"lib/deepl/resources/usage.rb",
|
45
48
|
"spec/api/api_spec.rb",
|
46
49
|
"spec/api/configuration_spec.rb",
|
47
50
|
"spec/api/deepl_spec.rb",
|
51
|
+
"spec/fixtures/vcr_cassettes/deepl_languages.yml",
|
48
52
|
"spec/fixtures/vcr_cassettes/deepl_translate.yml",
|
49
53
|
"spec/fixtures/vcr_cassettes/deepl_usage.yml",
|
54
|
+
"spec/fixtures/vcr_cassettes/languages.yml",
|
50
55
|
"spec/fixtures/vcr_cassettes/translate_texts.yml",
|
51
56
|
"spec/fixtures/vcr_cassettes/usage.yml",
|
57
|
+
"spec/requests/languages_spec.rb",
|
52
58
|
"spec/requests/translate_spec.rb",
|
53
59
|
"spec/requests/usage_spec.rb",
|
60
|
+
"spec/resources/language_spec.rb",
|
54
61
|
"spec/resources/text_spec.rb",
|
55
62
|
"spec/resources/usage_spec.rb",
|
56
63
|
"spec/spec_helper.rb"
|
@@ -66,8 +73,10 @@ Gem::Specification.new do |s|
|
|
66
73
|
|
67
74
|
if s.respond_to? :add_runtime_dependency then
|
68
75
|
s.add_development_dependency(%q<juwelier>.freeze, [">= 0"])
|
76
|
+
s.add_development_dependency(%q<byebug>.freeze, [">= 0"])
|
69
77
|
else
|
70
78
|
s.add_dependency(%q<juwelier>.freeze, [">= 0"])
|
79
|
+
s.add_dependency(%q<byebug>.freeze, [">= 0"])
|
71
80
|
end
|
72
81
|
end
|
73
82
|
|
data/lib/deepl/configuration.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Requests
|
5
|
+
class Languages < Base
|
6
|
+
def initialize(api, options = {})
|
7
|
+
super(api, options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def request
|
11
|
+
build_languages(*get)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def build_languages(request, response)
|
17
|
+
data = JSON.parse(response.body)
|
18
|
+
data.map do |language|
|
19
|
+
Resources::Language.new(language['language'], language['name'],
|
20
|
+
language['supports_formality'],
|
21
|
+
request, response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
'languages'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Resources
|
5
|
+
class Language < Base
|
6
|
+
attr_reader :code, :name
|
7
|
+
|
8
|
+
def initialize(code, name, supports_formality, *args)
|
9
|
+
super(*args)
|
10
|
+
|
11
|
+
@code = code
|
12
|
+
@name = name
|
13
|
+
@supports_formality = supports_formality
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{code} - #{name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def supports_formality?
|
21
|
+
return @supports_formality unless @supports_formality.nil?
|
22
|
+
|
23
|
+
raise Exceptions::NotSupported, 'Support formality is only available on target languages'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/deepl.rb
CHANGED
@@ -11,14 +11,17 @@ require 'deepl/exceptions/authorization_failed'
|
|
11
11
|
require 'deepl/exceptions/bad_request'
|
12
12
|
require 'deepl/exceptions/limit_exceeded'
|
13
13
|
require 'deepl/exceptions/quota_exceeded'
|
14
|
+
require 'deepl/exceptions/not_supported'
|
14
15
|
|
15
16
|
# -- Requests
|
16
17
|
require 'deepl/requests/base'
|
18
|
+
require 'deepl/requests/languages'
|
17
19
|
require 'deepl/requests/translate'
|
18
20
|
require 'deepl/requests/usage'
|
19
21
|
|
20
22
|
# -- Responses and resources
|
21
23
|
require 'deepl/resources/base'
|
24
|
+
require 'deepl/resources/language'
|
22
25
|
require 'deepl/resources/text'
|
23
26
|
require 'deepl/resources/usage'
|
24
27
|
|
@@ -36,6 +39,10 @@ module DeepL
|
|
36
39
|
@api ||= API.new(configuration)
|
37
40
|
end
|
38
41
|
|
42
|
+
def languages(options = {})
|
43
|
+
Requests::Languages.new(api, options).request
|
44
|
+
end
|
45
|
+
|
39
46
|
def translate(text, source_lang, target_lang, options = {})
|
40
47
|
configure if @configuration.nil?
|
41
48
|
Requests::Translate.new(api, text, source_lang, target_lang, options).request
|
@@ -16,7 +16,7 @@ describe DeepL::Configuration do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
context 'When using custom configuration attributes' do
|
19
|
-
let(:attributes) { { auth_key: 'SAMPLE', host: '
|
19
|
+
let(:attributes) { { auth_key: 'SAMPLE', host: 'https://api-free.deepl.com', version: 'v1' } }
|
20
20
|
|
21
21
|
it 'should use custom attributes' do
|
22
22
|
expect(subject.auth_key).to eq(attributes[:auth_key])
|
data/spec/api/deepl_spec.rb
CHANGED
@@ -47,6 +47,7 @@ describe DeepL do
|
|
47
47
|
let(:options) { { param: 'fake' } }
|
48
48
|
|
49
49
|
around do |example|
|
50
|
+
subject.configure { |config| config.host = 'https://api-free.deepl.com' }
|
50
51
|
VCR.use_cassette('deepl_translate') { example.call }
|
51
52
|
end
|
52
53
|
|
@@ -65,6 +66,7 @@ describe DeepL do
|
|
65
66
|
let(:options) { {} }
|
66
67
|
|
67
68
|
around do |example|
|
69
|
+
subject.configure { |config| config.host = 'https://api-free.deepl.com' }
|
68
70
|
VCR.use_cassette('deepl_usage') { example.call }
|
69
71
|
end
|
70
72
|
|
@@ -78,4 +80,24 @@ describe DeepL do
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
83
|
+
|
84
|
+
describe '#languages' do
|
85
|
+
let(:options) { { type: :target } }
|
86
|
+
|
87
|
+
around do |example|
|
88
|
+
subject.configure { |config| config.host = 'https://api-free.deepl.com' }
|
89
|
+
VCR.use_cassette('deepl_languages') { example.call }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'When checking languages' do
|
93
|
+
it 'should create and call a request object' do
|
94
|
+
expect(DeepL::Requests::Languages).to receive(:new)
|
95
|
+
.with(subject.api, options).and_call_original
|
96
|
+
|
97
|
+
languages = subject.languages(options)
|
98
|
+
expect(languages).to be_an(Array)
|
99
|
+
expect(languages.all? { |l| l.is_a?(DeepL::Resources::Language) }).to be_truthy
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
81
103
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-free.deepl.com/v2/languages?auth_key=VALID_TOKEN&type=target
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Mon, 17 May 2021 15:07:54 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '1667'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '[{"language":"BG","name":"Bulgarian","supports_formality":false},{"language":"CS","name":"Czech","supports_formality":false},{"language":"DA","name":"Danish","supports_formality":false},{"language":"DE","name":"German","supports_formality":true},{"language":"EL","name":"Greek","supports_formality":false},{"language":"EN-GB","name":"English
|
36
|
+
(British)","supports_formality":false},{"language":"EN-US","name":"English
|
37
|
+
(American)","supports_formality":false},{"language":"ES","name":"Spanish","supports_formality":true},{"language":"ET","name":"Estonian","supports_formality":false},{"language":"FI","name":"Finnish","supports_formality":false},{"language":"FR","name":"French","supports_formality":true},{"language":"HU","name":"Hungarian","supports_formality":false},{"language":"IT","name":"Italian","supports_formality":true},{"language":"JA","name":"Japanese","supports_formality":false},{"language":"LT","name":"Lithuanian","supports_formality":false},{"language":"LV","name":"Latvian","supports_formality":false},{"language":"NL","name":"Dutch","supports_formality":true},{"language":"PL","name":"Polish","supports_formality":true},{"language":"PT-BR","name":"Portuguese
|
38
|
+
(Brazilian)","supports_formality":true},{"language":"PT-PT","name":"Portuguese
|
39
|
+
(European)","supports_formality":true},{"language":"RO","name":"Romanian","supports_formality":false},{"language":"RU","name":"Russian","supports_formality":true},{"language":"SK","name":"Slovak","supports_formality":false},{"language":"SL","name":"Slovenian","supports_formality":false},{"language":"SV","name":"Swedish","supports_formality":false},{"language":"ZH","name":"Chinese","supports_formality":false}]'
|
40
|
+
recorded_at: Mon, 17 May 2021 15:07:54 GMT
|
41
|
+
recorded_with: VCR 6.0.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN¶m=fake
|
5
|
+
uri: https://api-free.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
|
@@ -23,7 +23,7 @@ http_interactions:
|
|
23
23
|
Server:
|
24
24
|
- nginx
|
25
25
|
Date:
|
26
|
-
-
|
26
|
+
- Mon, 17 May 2021 14:42:56 GMT
|
27
27
|
Content-Type:
|
28
28
|
- application/json
|
29
29
|
Content-Length:
|
@@ -35,6 +35,5 @@ http_interactions:
|
|
35
35
|
body:
|
36
36
|
encoding: UTF-8
|
37
37
|
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"}]}'
|
38
|
-
|
39
|
-
|
40
|
-
recorded_with: VCR 4.0.0
|
38
|
+
recorded_at: Mon, 17 May 2021 14:42:56 GMT
|
39
|
+
recorded_with: VCR 6.0.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api.deepl.com/v2/usage?auth_key=VALID_TOKEN
|
5
|
+
uri: https://api-free.deepl.com/v2/usage?auth_key=VALID_TOKEN
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -21,14 +21,17 @@ http_interactions:
|
|
21
21
|
Server:
|
22
22
|
- nginx
|
23
23
|
Date:
|
24
|
-
-
|
24
|
+
- Mon, 17 May 2021 14:18:28 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
25
27
|
Content-Length:
|
26
|
-
- '
|
28
|
+
- '48'
|
27
29
|
Connection:
|
28
30
|
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
29
33
|
body:
|
30
34
|
encoding: UTF-8
|
31
|
-
string: '{"character_count":
|
32
|
-
|
33
|
-
|
34
|
-
recorded_with: VCR 4.0.0
|
35
|
+
string: '{"character_count":303,"character_limit":500000}'
|
36
|
+
recorded_at: Mon, 17 May 2021 14:18:28 GMT
|
37
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,108 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-free.deepl.com/v2/languages?auth_key=VALID_TOKEN
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- nginx
|
23
|
+
Date:
|
24
|
+
- Mon, 17 May 2021 14:49:42 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
27
|
+
Content-Length:
|
28
|
+
- '845'
|
29
|
+
Connection:
|
30
|
+
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
33
|
+
body:
|
34
|
+
encoding: UTF-8
|
35
|
+
string: '[{"language":"BG","name":"Bulgarian"},{"language":"CS","name":"Czech"},{"language":"DA","name":"Danish"},{"language":"DE","name":"German"},{"language":"EL","name":"Greek"},{"language":"EN","name":"English"},{"language":"ES","name":"Spanish"},{"language":"ET","name":"Estonian"},{"language":"FI","name":"Finnish"},{"language":"FR","name":"French"},{"language":"HU","name":"Hungarian"},{"language":"IT","name":"Italian"},{"language":"JA","name":"Japanese"},{"language":"LT","name":"Lithuanian"},{"language":"LV","name":"Latvian"},{"language":"NL","name":"Dutch"},{"language":"PL","name":"Polish"},{"language":"PT","name":"Portuguese"},{"language":"RO","name":"Romanian"},{"language":"RU","name":"Russian"},{"language":"SK","name":"Slovak"},{"language":"SL","name":"Slovenian"},{"language":"SV","name":"Swedish"},{"language":"ZH","name":"Chinese"}]'
|
36
|
+
recorded_at: Mon, 17 May 2021 14:49:42 GMT
|
37
|
+
- request:
|
38
|
+
method: get
|
39
|
+
uri: https://api-free.deepl.com/v2/languages?auth_key=VALID_TOKEN&type=target
|
40
|
+
body:
|
41
|
+
encoding: US-ASCII
|
42
|
+
string: ''
|
43
|
+
headers:
|
44
|
+
Accept-Encoding:
|
45
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
46
|
+
Accept:
|
47
|
+
- "*/*"
|
48
|
+
User-Agent:
|
49
|
+
- Ruby
|
50
|
+
response:
|
51
|
+
status:
|
52
|
+
code: 200
|
53
|
+
message: OK
|
54
|
+
headers:
|
55
|
+
Server:
|
56
|
+
- nginx
|
57
|
+
Date:
|
58
|
+
- Mon, 17 May 2021 14:55:30 GMT
|
59
|
+
Content-Type:
|
60
|
+
- application/json
|
61
|
+
Content-Length:
|
62
|
+
- '1667'
|
63
|
+
Connection:
|
64
|
+
- keep-alive
|
65
|
+
Access-Control-Allow-Origin:
|
66
|
+
- "*"
|
67
|
+
body:
|
68
|
+
encoding: UTF-8
|
69
|
+
string: '[{"language":"BG","name":"Bulgarian","supports_formality":false},{"language":"CS","name":"Czech","supports_formality":false},{"language":"DA","name":"Danish","supports_formality":false},{"language":"DE","name":"German","supports_formality":true},{"language":"EL","name":"Greek","supports_formality":false},{"language":"EN-GB","name":"English
|
70
|
+
(British)","supports_formality":false},{"language":"EN-US","name":"English
|
71
|
+
(American)","supports_formality":false},{"language":"ES","name":"Spanish","supports_formality":true},{"language":"ET","name":"Estonian","supports_formality":false},{"language":"FI","name":"Finnish","supports_formality":false},{"language":"FR","name":"French","supports_formality":true},{"language":"HU","name":"Hungarian","supports_formality":false},{"language":"IT","name":"Italian","supports_formality":true},{"language":"JA","name":"Japanese","supports_formality":false},{"language":"LT","name":"Lithuanian","supports_formality":false},{"language":"LV","name":"Latvian","supports_formality":false},{"language":"NL","name":"Dutch","supports_formality":true},{"language":"PL","name":"Polish","supports_formality":true},{"language":"PT-BR","name":"Portuguese
|
72
|
+
(Brazilian)","supports_formality":true},{"language":"PT-PT","name":"Portuguese
|
73
|
+
(European)","supports_formality":true},{"language":"RO","name":"Romanian","supports_formality":false},{"language":"RU","name":"Russian","supports_formality":true},{"language":"SK","name":"Slovak","supports_formality":false},{"language":"SL","name":"Slovenian","supports_formality":false},{"language":"SV","name":"Swedish","supports_formality":false},{"language":"ZH","name":"Chinese","supports_formality":false}]'
|
74
|
+
recorded_at: Mon, 17 May 2021 14:55:30 GMT
|
75
|
+
- request:
|
76
|
+
method: get
|
77
|
+
uri: https://api-free.deepl.com/v2/languages?auth_key=VALID_TOKEN&type=invalid
|
78
|
+
body:
|
79
|
+
encoding: US-ASCII
|
80
|
+
string: ''
|
81
|
+
headers:
|
82
|
+
Accept-Encoding:
|
83
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
84
|
+
Accept:
|
85
|
+
- "*/*"
|
86
|
+
User-Agent:
|
87
|
+
- Ruby
|
88
|
+
response:
|
89
|
+
status:
|
90
|
+
code: 400
|
91
|
+
message: Bad Request
|
92
|
+
headers:
|
93
|
+
Server:
|
94
|
+
- nginx
|
95
|
+
Date:
|
96
|
+
- Mon, 17 May 2021 14:57:00 GMT
|
97
|
+
Content-Length:
|
98
|
+
- '82'
|
99
|
+
Connection:
|
100
|
+
- keep-alive
|
101
|
+
Access-Control-Allow-Origin:
|
102
|
+
- "*"
|
103
|
+
body:
|
104
|
+
encoding: UTF-8
|
105
|
+
string: '{"message":"Parameter ''type'' is invalid. ''source'' and ''target''
|
106
|
+
are valid values."}'
|
107
|
+
recorded_at: Mon, 17 May 2021 14:57:00 GMT
|
108
|
+
recorded_with: VCR 6.0.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: post
|
5
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
5
|
+
uri: https://api-free.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
|
@@ -23,11 +23,11 @@ http_interactions:
|
|
23
23
|
Server:
|
24
24
|
- nginx
|
25
25
|
Date:
|
26
|
-
-
|
26
|
+
- Mon, 17 May 2021 14:20:14 GMT
|
27
27
|
Content-Type:
|
28
28
|
- application/json
|
29
29
|
Content-Length:
|
30
|
-
- '
|
30
|
+
- '78'
|
31
31
|
Connection:
|
32
32
|
- keep-alive
|
33
33
|
Access-Control-Allow-Origin:
|
@@ -36,11 +36,10 @@ http_interactions:
|
|
36
36
|
encoding: UTF-8
|
37
37
|
string: '{"translations":[{"detected_source_language":"EN","text":"Texto de
|
38
38
|
muestra"}]}'
|
39
|
-
|
40
|
-
recorded_at: Tue, 08 May 2018 16:31:34 GMT
|
39
|
+
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
41
40
|
- request:
|
42
41
|
method: post
|
43
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
42
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
44
43
|
body:
|
45
44
|
encoding: US-ASCII
|
46
45
|
string: text=Sample&text=Word&source_lang=EN&target_lang=ES
|
@@ -61,7 +60,7 @@ http_interactions:
|
|
61
60
|
Server:
|
62
61
|
- nginx
|
63
62
|
Date:
|
64
|
-
-
|
63
|
+
- Mon, 17 May 2021 14:20:14 GMT
|
65
64
|
Content-Type:
|
66
65
|
- application/json
|
67
66
|
Content-Length:
|
@@ -73,11 +72,10 @@ http_interactions:
|
|
73
72
|
body:
|
74
73
|
encoding: UTF-8
|
75
74
|
string: '{"translations":[{"detected_source_language":"EN","text":"Muestra"},{"detected_source_language":"EN","text":"Palabra"}]}'
|
76
|
-
|
77
|
-
recorded_at: Tue, 08 May 2018 16:31:35 GMT
|
75
|
+
recorded_at: Mon, 17 May 2021 14:20:14 GMT
|
78
76
|
- request:
|
79
77
|
method: post
|
80
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
78
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&tag_handling=xml
|
81
79
|
body:
|
82
80
|
encoding: US-ASCII
|
83
81
|
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
@@ -98,7 +96,7 @@ http_interactions:
|
|
98
96
|
Server:
|
99
97
|
- nginx
|
100
98
|
Date:
|
101
|
-
-
|
99
|
+
- Mon, 17 May 2021 14:20:15 GMT
|
102
100
|
Content-Type:
|
103
101
|
- application/json
|
104
102
|
Content-Length:
|
@@ -111,11 +109,47 @@ http_interactions:
|
|
111
109
|
encoding: UTF-8
|
112
110
|
string: '{"translations":[{"detected_source_language":"EN","text":"<p>Texto
|
113
111
|
de muestra</p>"}]}'
|
114
|
-
|
115
|
-
recorded_at: Tue, 08 May 2018 16:31:36 GMT
|
112
|
+
recorded_at: Mon, 17 May 2021 14:20:15 GMT
|
116
113
|
- request:
|
117
114
|
method: post
|
118
|
-
uri: https://api.deepl.com/v2/translate?auth_key=
|
115
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&ignore_tags=code,span
|
116
|
+
body:
|
117
|
+
encoding: US-ASCII
|
118
|
+
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
119
|
+
headers:
|
120
|
+
Accept-Encoding:
|
121
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
122
|
+
Accept:
|
123
|
+
- "*/*"
|
124
|
+
User-Agent:
|
125
|
+
- Ruby
|
126
|
+
Content-Type:
|
127
|
+
- application/x-www-form-urlencoded
|
128
|
+
response:
|
129
|
+
status:
|
130
|
+
code: 200
|
131
|
+
message: OK
|
132
|
+
headers:
|
133
|
+
Server:
|
134
|
+
- nginx
|
135
|
+
Date:
|
136
|
+
- Mon, 17 May 2021 14:20:16 GMT
|
137
|
+
Content-Type:
|
138
|
+
- application/json
|
139
|
+
Content-Length:
|
140
|
+
- '119'
|
141
|
+
Connection:
|
142
|
+
- keep-alive
|
143
|
+
Access-Control-Allow-Origin:
|
144
|
+
- "*"
|
145
|
+
body:
|
146
|
+
encoding: ASCII-8BIT
|
147
|
+
string: !binary |-
|
148
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5Ib2xhIGdyYW4gbXVuZG88L2NvZGU+IMKhQnVlbm9zIGTDrWFzISJ9XX0=
|
149
|
+
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
150
|
+
- request:
|
151
|
+
method: post
|
152
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=invalid
|
119
153
|
body:
|
120
154
|
encoding: US-ASCII
|
121
155
|
string: text=Sample+text&source_lang=EN&target_lang=ES
|
@@ -136,19 +170,20 @@ http_interactions:
|
|
136
170
|
Server:
|
137
171
|
- nginx
|
138
172
|
Date:
|
139
|
-
-
|
173
|
+
- Mon, 17 May 2021 14:20:16 GMT
|
140
174
|
Content-Length:
|
141
175
|
- '0'
|
142
176
|
Connection:
|
143
177
|
- keep-alive
|
178
|
+
Access-Control-Allow-Origin:
|
179
|
+
- "*"
|
144
180
|
body:
|
145
181
|
encoding: UTF-8
|
146
182
|
string: ''
|
147
|
-
|
148
|
-
recorded_at: Tue, 08 May 2018 16:31:37 GMT
|
183
|
+
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
149
184
|
- request:
|
150
185
|
method: post
|
151
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
186
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
152
187
|
body:
|
153
188
|
encoding: US-ASCII
|
154
189
|
string: source_lang=EN&target_lang=ES
|
@@ -169,19 +204,20 @@ http_interactions:
|
|
169
204
|
Server:
|
170
205
|
- nginx
|
171
206
|
Date:
|
172
|
-
-
|
207
|
+
- Mon, 17 May 2021 14:20:16 GMT
|
173
208
|
Content-Length:
|
174
209
|
- '45'
|
175
210
|
Connection:
|
176
211
|
- keep-alive
|
212
|
+
Access-Control-Allow-Origin:
|
213
|
+
- "*"
|
177
214
|
body:
|
178
215
|
encoding: UTF-8
|
179
216
|
string: '{"message":"Parameter ''text'' not specified."}'
|
180
|
-
|
181
|
-
recorded_at: Tue, 08 May 2018 16:31:37 GMT
|
217
|
+
recorded_at: Mon, 17 May 2021 14:20:16 GMT
|
182
218
|
- request:
|
183
219
|
method: post
|
184
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
220
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN
|
185
221
|
body:
|
186
222
|
encoding: US-ASCII
|
187
223
|
string: text=Sample+text&source_lang=EN
|
@@ -202,19 +238,20 @@ http_interactions:
|
|
202
238
|
Server:
|
203
239
|
- nginx
|
204
240
|
Date:
|
205
|
-
-
|
241
|
+
- Mon, 17 May 2021 14:20:17 GMT
|
206
242
|
Content-Length:
|
207
243
|
- '52'
|
208
244
|
Connection:
|
209
245
|
- keep-alive
|
246
|
+
Access-Control-Allow-Origin:
|
247
|
+
- "*"
|
210
248
|
body:
|
211
249
|
encoding: UTF-8
|
212
|
-
string: '{"message":"
|
213
|
-
|
214
|
-
recorded_at: Tue, 08 May 2018 16:31:37 GMT
|
250
|
+
string: '{"message":"Value for ''target_lang'' not supported."}'
|
251
|
+
recorded_at: Mon, 17 May 2021 14:20:17 GMT
|
215
252
|
- request:
|
216
253
|
method: post
|
217
|
-
uri: https://api.deepl.com/v2/translate?auth_key=VALID_TOKEN&ignore_tags=code
|
254
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&ignore_tags=code,span&tag_handling=xml
|
218
255
|
body:
|
219
256
|
encoding: US-ASCII
|
220
257
|
string: text=Welcome+and+%3Ccode%3EHello+great+World%3C%2Fcode%3E+Good+Morning%21&source_lang=EN&target_lang=ES
|
@@ -235,11 +272,11 @@ http_interactions:
|
|
235
272
|
Server:
|
236
273
|
- nginx
|
237
274
|
Date:
|
238
|
-
-
|
275
|
+
- Mon, 17 May 2021 14:20:56 GMT
|
239
276
|
Content-Type:
|
240
277
|
- application/json
|
241
278
|
Content-Length:
|
242
|
-
- '
|
279
|
+
- '121'
|
243
280
|
Connection:
|
244
281
|
- keep-alive
|
245
282
|
Access-Control-Allow-Origin:
|
@@ -247,7 +284,42 @@ http_interactions:
|
|
247
284
|
body:
|
248
285
|
encoding: ASCII-8BIT
|
249
286
|
string: !binary |-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
287
|
+
eyJ0cmFuc2xhdGlvbnMiOlt7ImRldGVjdGVkX3NvdXJjZV9sYW5ndWFnZSI6IkVOIiwidGV4dCI6IkJpZW52ZW5pZG8geSA8Y29kZT5IZWxsbyBncmVhdCBXb3JsZDwvY29kZT4gwqFCdWVub3MgZMOtYXMhIn1dfQ==
|
288
|
+
recorded_at: Mon, 17 May 2021 14:20:56 GMT
|
289
|
+
- request:
|
290
|
+
method: post
|
291
|
+
uri: https://api-free.deepl.com/v2/translate?auth_key=VALID_TOKEN&glossary_id=123
|
292
|
+
body:
|
293
|
+
encoding: US-ASCII
|
294
|
+
string: text=%3Cp%3ESample+text%3C%2Fp%3E&source_lang=EN&target_lang=ES
|
295
|
+
headers:
|
296
|
+
Accept-Encoding:
|
297
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
298
|
+
Accept:
|
299
|
+
- "*/*"
|
300
|
+
User-Agent:
|
301
|
+
- Ruby
|
302
|
+
Content-Type:
|
303
|
+
- application/x-www-form-urlencoded
|
304
|
+
response:
|
305
|
+
status:
|
306
|
+
code: 400
|
307
|
+
message: Bad Request
|
308
|
+
headers:
|
309
|
+
Server:
|
310
|
+
- nginx
|
311
|
+
Date:
|
312
|
+
- Tue, 28 Sep 2021 17:20:52 GMT
|
313
|
+
Content-Type:
|
314
|
+
- application/json
|
315
|
+
Content-Length:
|
316
|
+
- '51'
|
317
|
+
Connection:
|
318
|
+
- keep-alive
|
319
|
+
Access-Control-Allow-Origin:
|
320
|
+
- "*"
|
321
|
+
body:
|
322
|
+
encoding: UTF-8
|
323
|
+
string: '{"message":"Value for ''termbaseId'' not supported."}'
|
324
|
+
recorded_at: Tue, 28 Sep 2021 17:20:52 GMT
|
325
|
+
recorded_with: VCR 6.0.0
|
@@ -2,7 +2,7 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api.deepl.com/v2/usage?auth_key=VALID_TOKEN
|
5
|
+
uri: https://api-free.deepl.com/v2/usage?auth_key=VALID_TOKEN
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
@@ -21,14 +21,17 @@ http_interactions:
|
|
21
21
|
Server:
|
22
22
|
- nginx
|
23
23
|
Date:
|
24
|
-
-
|
24
|
+
- Mon, 17 May 2021 14:18:32 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json
|
25
27
|
Content-Length:
|
26
|
-
- '
|
28
|
+
- '48'
|
27
29
|
Connection:
|
28
30
|
- keep-alive
|
31
|
+
Access-Control-Allow-Origin:
|
32
|
+
- "*"
|
29
33
|
body:
|
30
34
|
encoding: UTF-8
|
31
|
-
string: '{"character_count":
|
32
|
-
|
33
|
-
|
34
|
-
recorded_with: VCR 4.0.0
|
35
|
+
string: '{"character_count":353,"character_limit":500000}'
|
36
|
+
recorded_at: Mon, 17 May 2021 14:18:32 GMT
|
37
|
+
recorded_with: VCR 6.0.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Requests::Languages do
|
6
|
+
let(:api) { build_deepl_api }
|
7
|
+
let(:options) { {} }
|
8
|
+
subject { DeepL::Requests::Languages.new(api, options) }
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
context 'When building a request' do
|
12
|
+
it 'should create a request object' do
|
13
|
+
expect(subject).to be_a(described_class)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#request' do
|
19
|
+
around do |example|
|
20
|
+
VCR.use_cassette('languages') { example.call }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'When requesting source languages' do
|
24
|
+
it 'should return an usage object' do
|
25
|
+
languages = subject.request
|
26
|
+
|
27
|
+
expect(languages).to be_an(Array)
|
28
|
+
expect(languages.size).to eq(24)
|
29
|
+
expect(languages.any? { |l| l.code == 'EN' && l.name == 'English' }).to be_truthy
|
30
|
+
expect(languages.any? { |l| l.code == 'ES' && l.name == 'Spanish' }).to be_truthy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'When requesting target languages' do
|
35
|
+
let(:options) { { type: :target } }
|
36
|
+
|
37
|
+
it 'should return an usage object' do
|
38
|
+
languages = subject.request
|
39
|
+
|
40
|
+
expect(languages).to be_an(Array)
|
41
|
+
expect(languages.size).to eq(26)
|
42
|
+
expect(languages.any? { |l| l.code == 'EN' && l.name == 'English' }).to be_falsey
|
43
|
+
expect(languages.any? { |l| l.code == 'ES' && l.name == 'Spanish' }).to be_truthy
|
44
|
+
expect(languages.any? { |l| l.code == 'EN-US' && l.name == 'English (American)' })
|
45
|
+
.to be_truthy
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'When using an invalid type' do
|
50
|
+
let(:options) { { type: :invalid } }
|
51
|
+
|
52
|
+
it 'should return an usage object' do
|
53
|
+
message = "Parameter 'type' is invalid. 'source' and 'target' are valid values."
|
54
|
+
expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -90,6 +90,11 @@ describe DeepL::Requests::Translate do
|
|
90
90
|
expect(request.options[:split_sentences]).to eq('0')
|
91
91
|
end
|
92
92
|
|
93
|
+
it 'should leave `nonewlines` as is' do
|
94
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, split_sentences: 'nonewlines')
|
95
|
+
expect(request.options[:split_sentences]).to eq('nonewlines')
|
96
|
+
end
|
97
|
+
|
93
98
|
it 'should leave `1` as is' do
|
94
99
|
request = DeepL::Requests::Translate.new(api, nil, nil, nil, split_sentences: '1')
|
95
100
|
expect(request.options[:split_sentences]).to eq('1')
|
@@ -117,6 +122,52 @@ describe DeepL::Requests::Translate do
|
|
117
122
|
expect(request.options[:preserve_formatting]).to eq('1')
|
118
123
|
end
|
119
124
|
end
|
125
|
+
|
126
|
+
context 'when using `outline_detection` options' do
|
127
|
+
it 'should convert `true` to `1`' do
|
128
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, outline_detection: true)
|
129
|
+
expect(request.options[:outline_detection]).to eq('1')
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should convert `false` to `0`' do
|
133
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, outline_detection: false)
|
134
|
+
expect(request.options[:outline_detection]).to eq('0')
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should leave `0` as is' do
|
138
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, outline_detection: '0')
|
139
|
+
expect(request.options[:outline_detection]).to eq('0')
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should leave `1` as is' do
|
143
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, outline_detection: '1')
|
144
|
+
expect(request.options[:outline_detection]).to eq('1')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'when using `glossary_id` options' do
|
149
|
+
it 'should work with a nil values' do
|
150
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, glossary_id: nil)
|
151
|
+
expect(request.options[:glossary_id]).to eq(nil)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should work with a string' do
|
155
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, glossary_id: 'sample_id')
|
156
|
+
expect(request.options[:glossary_id]).to eq('sample_id')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'when using `formality` options' do
|
161
|
+
it 'should work with a nil values' do
|
162
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, formality: nil)
|
163
|
+
expect(request.options[:formality]).to eq(nil)
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'should work with a string' do
|
167
|
+
request = DeepL::Requests::Translate.new(api, nil, nil, nil, formality: 'more')
|
168
|
+
expect(request.options[:formality]).to eq('more')
|
169
|
+
end
|
170
|
+
end
|
120
171
|
end
|
121
172
|
|
122
173
|
describe '#request' do
|
@@ -151,6 +202,7 @@ describe DeepL::Requests::Translate do
|
|
151
202
|
|
152
203
|
context 'When performing a valid request with tag handling' do
|
153
204
|
let(:text) { '<p>Sample text</p>' }
|
205
|
+
let(:options) { { tag_handling: 'xml' } }
|
154
206
|
|
155
207
|
it 'should return a text object' do
|
156
208
|
text = subject.request
|
@@ -163,13 +215,13 @@ describe DeepL::Requests::Translate do
|
|
163
215
|
|
164
216
|
context 'When performing a valid request and passing a variable' do
|
165
217
|
let(:text) { 'Welcome and <code>Hello great World</code> Good Morning!' }
|
166
|
-
let(:options) { { ignore_tags: 'code,
|
218
|
+
let(:options) { { tag_handling: 'xml', ignore_tags: 'code,span' } }
|
167
219
|
|
168
220
|
it 'should return a text object' do
|
169
221
|
text = subject.request
|
170
222
|
|
171
223
|
expect(text).to be_a(DeepL::Resources::Text)
|
172
|
-
expect(text.text).to eq('Bienvenido y <code>Hello great World</code> Buenos días!')
|
224
|
+
expect(text.text).to eq('Bienvenido y <code>Hello great World</code> ¡Buenos días!')
|
173
225
|
expect(text.detected_source_language).to eq('EN')
|
174
226
|
end
|
175
227
|
end
|
@@ -200,7 +252,7 @@ describe DeepL::Requests::Translate do
|
|
200
252
|
let(:target_lang) { nil }
|
201
253
|
|
202
254
|
it 'should raise a bad request error' do
|
203
|
-
message = "
|
255
|
+
message = "Value for 'target_lang' not supported."
|
204
256
|
expect { subject.request }.to raise_error(DeepL::Exceptions::BadRequest, message)
|
205
257
|
end
|
206
258
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe DeepL::Resources::Language do
|
6
|
+
subject { described_class.new('EN', 'English', nil, nil, nil) }
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
context 'When building a basic object' do
|
10
|
+
it 'should create a resource' do
|
11
|
+
expect(subject).to be_a(described_class)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should assign the attributes' do
|
15
|
+
expect(subject.code).to eq('EN')
|
16
|
+
expect(subject.name).to eq('English')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not define the supports formality method' do
|
20
|
+
expect { subject.supports_formality? }.to raise_error(DeepL::Exceptions::NotSupported)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when building a target language object' do
|
25
|
+
subject { described_class.new('EN', 'English', true, nil, nil) }
|
26
|
+
|
27
|
+
it 'should create a resource' do
|
28
|
+
expect(subject).to be_a(described_class)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should assign the attributes' do
|
32
|
+
expect(subject.code).to eq('EN')
|
33
|
+
expect(subject.name).to eq('English')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should include the supports formality method' do
|
37
|
+
expect { subject.supports_formality? }.not_to raise_error
|
38
|
+
expect(subject.supports_formality?).to be_truthy
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/resources/text_spec.rb
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DeepL::Resources::Text do
|
6
|
-
subject {
|
6
|
+
subject { described_class.new('Target', 'es', nil, nil) }
|
7
7
|
|
8
8
|
describe '#initialize' do
|
9
9
|
context 'When building a basic object' do
|
10
10
|
it 'should create a resource' do
|
11
|
-
expect(subject).to be_a(
|
11
|
+
expect(subject).to be_a(described_class)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should assign the attributes' do
|
@@ -3,12 +3,12 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DeepL::Resources::Usage do
|
6
|
-
subject {
|
6
|
+
subject { described_class.new(3, 5, nil, nil) }
|
7
7
|
|
8
8
|
describe '#initialize' do
|
9
9
|
context 'When building a basic object' do
|
10
10
|
it 'should create a resource' do
|
11
|
-
expect(subject).to be_a(
|
11
|
+
expect(subject).to be_a(described_class)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should assign the attributes' do
|
@@ -22,7 +22,7 @@ describe DeepL::Resources::Usage do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'When building a quota exceeded object' do
|
25
|
-
subject {
|
25
|
+
subject { described_class.new(5, 5, nil, nil) }
|
26
26
|
|
27
27
|
it 'should exceed the quota' do
|
28
28
|
expect(subject.quota_exceeded?).to be_truthy
|
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.4.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: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: juwelier
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: 'A simple ruby wrapper for the DeepL translation API (v1). For more information,
|
28
42
|
check this: https://www.deepl.com/docs/api-reference.html'
|
29
43
|
email: info@danielherzog.es
|
@@ -48,23 +62,30 @@ files:
|
|
48
62
|
- lib/deepl/exceptions/bad_request.rb
|
49
63
|
- lib/deepl/exceptions/error.rb
|
50
64
|
- lib/deepl/exceptions/limit_exceeded.rb
|
65
|
+
- lib/deepl/exceptions/not_supported.rb
|
51
66
|
- lib/deepl/exceptions/quota_exceeded.rb
|
52
67
|
- lib/deepl/exceptions/request_error.rb
|
53
68
|
- lib/deepl/requests/base.rb
|
69
|
+
- lib/deepl/requests/languages.rb
|
54
70
|
- lib/deepl/requests/translate.rb
|
55
71
|
- lib/deepl/requests/usage.rb
|
56
72
|
- lib/deepl/resources/base.rb
|
73
|
+
- lib/deepl/resources/language.rb
|
57
74
|
- lib/deepl/resources/text.rb
|
58
75
|
- lib/deepl/resources/usage.rb
|
59
76
|
- spec/api/api_spec.rb
|
60
77
|
- spec/api/configuration_spec.rb
|
61
78
|
- spec/api/deepl_spec.rb
|
79
|
+
- spec/fixtures/vcr_cassettes/deepl_languages.yml
|
62
80
|
- spec/fixtures/vcr_cassettes/deepl_translate.yml
|
63
81
|
- spec/fixtures/vcr_cassettes/deepl_usage.yml
|
82
|
+
- spec/fixtures/vcr_cassettes/languages.yml
|
64
83
|
- spec/fixtures/vcr_cassettes/translate_texts.yml
|
65
84
|
- spec/fixtures/vcr_cassettes/usage.yml
|
85
|
+
- spec/requests/languages_spec.rb
|
66
86
|
- spec/requests/translate_spec.rb
|
67
87
|
- spec/requests/usage_spec.rb
|
88
|
+
- spec/resources/language_spec.rb
|
68
89
|
- spec/resources/text_spec.rb
|
69
90
|
- spec/resources/usage_spec.rb
|
70
91
|
- spec/spec_helper.rb
|