deepl-rb 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/VERSION +1 -1
- data/deepl-rb.gemspec +4 -3
- data/lib/deepl/configuration.rb +1 -1
- data/lib/deepl/exceptions/not_supported.rb +11 -0
- data/lib/deepl/requests/languages.rb +3 -1
- data/lib/deepl/resources/language.rb +8 -1
- data/lib/deepl.rb +1 -0
- data/spec/resources/language_spec.rb +23 -1
- metadata +3 -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/README.md
CHANGED
@@ -71,7 +71,10 @@ puts DeepL.languages(type: :target).count
|
|
71
71
|
```
|
72
72
|
|
73
73
|
All languages are also defined on the
|
74
|
-
[official API documentation](https://www.deepl.com/docs-api/translating-text/)
|
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?`.
|
75
78
|
|
76
79
|
### Translate
|
77
80
|
|
@@ -154,6 +157,7 @@ You can capture and process exceptions that may be raised during API calls. Thes
|
|
154
157
|
| `DeepL::Exceptions::LimitExceeded` | You've reached the API's call limit. |
|
155
158
|
| `DeepL::Exceptions::QuotaExceeded` | You've reached the API's character limit. |
|
156
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. |
|
157
161
|
|
158
162
|
An exampling of handling a generic exception:
|
159
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,6 +34,7 @@ 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",
|
data/lib/deepl/configuration.rb
CHANGED
@@ -16,7 +16,9 @@ module DeepL
|
|
16
16
|
def build_languages(request, response)
|
17
17
|
data = JSON.parse(response.body)
|
18
18
|
data.map do |language|
|
19
|
-
Resources::Language.new(language['language'], language['name'],
|
19
|
+
Resources::Language.new(language['language'], language['name'],
|
20
|
+
language['supports_formality'],
|
21
|
+
request, response)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -5,16 +5,23 @@ module DeepL
|
|
5
5
|
class Language < Base
|
6
6
|
attr_reader :code, :name
|
7
7
|
|
8
|
-
def initialize(code, name, *args)
|
8
|
+
def initialize(code, name, supports_formality, *args)
|
9
9
|
super(*args)
|
10
10
|
|
11
11
|
@code = code
|
12
12
|
@name = name
|
13
|
+
@supports_formality = supports_formality
|
13
14
|
end
|
14
15
|
|
15
16
|
def to_s
|
16
17
|
"#{code} - #{name}"
|
17
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
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
data/lib/deepl.rb
CHANGED
@@ -11,6 +11,7 @@ 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'
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe DeepL::Resources::Language do
|
6
|
-
subject { described_class.new('EN', 'English', nil, nil) }
|
6
|
+
subject { described_class.new('EN', 'English', nil, nil, nil) }
|
7
7
|
|
8
8
|
describe '#initialize' do
|
9
9
|
context 'When building a basic object' do
|
@@ -15,6 +15,28 @@ describe DeepL::Resources::Language do
|
|
15
15
|
expect(subject.code).to eq('EN')
|
16
16
|
expect(subject.name).to eq('English')
|
17
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
|
18
40
|
end
|
19
41
|
end
|
20
42
|
end
|
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
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/deepl/exceptions/bad_request.rb
|
63
63
|
- lib/deepl/exceptions/error.rb
|
64
64
|
- lib/deepl/exceptions/limit_exceeded.rb
|
65
|
+
- lib/deepl/exceptions/not_supported.rb
|
65
66
|
- lib/deepl/exceptions/quota_exceeded.rb
|
66
67
|
- lib/deepl/exceptions/request_error.rb
|
67
68
|
- lib/deepl/requests/base.rb
|