deepl-rb 2.5.0 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/VERSION +1 -1
- data/deepl-rb.gemspec +5 -3
- data/lib/deepl/configuration.rb +1 -1
- data/lib/deepl/exceptions/request_entity_too_large.rb +12 -0
- data/lib/deepl/requests/base.rb +1 -8
- data/lib/deepl/requests/translate.rb +4 -2
- data/lib/deepl/utils/exception_builder.rb +29 -0
- data/lib/deepl.rb +4 -0
- data/spec/api/configuration_spec.rb +1 -1
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +417 -341
- data/spec/requests/translate_spec.rb +83 -2
- data/spec/spec_helper.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39127e54045e9c2632e8708554251443acfdbfbb1cdbf8806ef98f2e0ee81fb4
|
4
|
+
data.tar.gz: b5e7b26cf284e1ad6334397a56259ff120a0fa08f7352cb99eccfa68a652eadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74efcad943159db5c628bdd11ed699a996ab7f2360406fc0c010d48ac7c32488a5ec75d728904e57bf469af17a2fe276bd05b3e3293160b8d00436a8cb6da268
|
7
|
+
data.tar.gz: 8373bb2749eb249c1f5dfed6e2551e795ef8baf8cceb4983994e37ff3f0c8d1eac09b56b2e74a061a2ae6f836a380af728aea7b09dd5a15f8d4a575bb89c3b98
|
data/README.md
CHANGED
@@ -128,6 +128,7 @@ The following parameters will be automatically converted:
|
|
128
128
|
| `preserve_formatting` | Converts `false` to `'0'` and `true` to `'1'`
|
129
129
|
| `split_sentences` | Converts `false` to `'0'` and `true` to `'1'`
|
130
130
|
| `outline_detection` | Converts `false` to `'0'` and `true` to `'1'`
|
131
|
+
| `splitting_tags` | Converts arrays to strings joining by commas
|
131
132
|
| `non_splitting_tags` | Converts arrays to strings joining by commas
|
132
133
|
| `ignore_tags` | Converts arrays to strings joining by commas
|
133
134
|
| `formality` | No conversion applied
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.2
|
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.
|
5
|
+
# stub: deepl-rb 2.5.2 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "deepl-rb".freeze
|
9
|
-
s.version = "2.5.
|
9
|
+
s.version = "2.5.2"
|
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 = "2022-
|
14
|
+
s.date = "2022-09-25"
|
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 = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/deepl/exceptions/not_found.rb",
|
38
38
|
"lib/deepl/exceptions/not_supported.rb",
|
39
39
|
"lib/deepl/exceptions/quota_exceeded.rb",
|
40
|
+
"lib/deepl/exceptions/request_entity_too_large.rb",
|
40
41
|
"lib/deepl/exceptions/request_error.rb",
|
41
42
|
"lib/deepl/glossary_api.rb",
|
42
43
|
"lib/deepl/requests/base.rb",
|
@@ -55,6 +56,7 @@ Gem::Specification.new do |s|
|
|
55
56
|
"lib/deepl/resources/language_pair.rb",
|
56
57
|
"lib/deepl/resources/text.rb",
|
57
58
|
"lib/deepl/resources/usage.rb",
|
59
|
+
"lib/deepl/utils/exception_builder.rb",
|
58
60
|
"spec/api/api_spec.rb",
|
59
61
|
"spec/api/configuration_spec.rb",
|
60
62
|
"spec/api/deepl_spec.rb",
|
data/lib/deepl/configuration.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Exceptions
|
5
|
+
class RequestEntityTooLarge < RequestError
|
6
|
+
def message
|
7
|
+
'The request size has reached the supported limit. ' \
|
8
|
+
"Make sure that you're sending more than 50 sentences when translating"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/deepl/requests/base.rb
CHANGED
@@ -72,14 +72,7 @@ module DeepL
|
|
72
72
|
def validate_response!(request, response)
|
73
73
|
return if response.is_a?(Net::HTTPSuccess)
|
74
74
|
|
75
|
-
|
76
|
-
when '400' then raise Exceptions::BadRequest.new(request, response)
|
77
|
-
when '401', '403' then raise Exceptions::AuthorizationFailed.new(request, response)
|
78
|
-
when '404' then raise Exceptions::NotFound.new(request, response)
|
79
|
-
when '429' then raise Exceptions::LimitExceeded.new(request, response)
|
80
|
-
when '456' then raise Exceptions::QuotaExceeded.new(request, response)
|
81
|
-
else raise Exceptions::RequestError.new(request, response)
|
82
|
-
end
|
75
|
+
raise Utils::ExceptionBuilder.new(request, response).build
|
83
76
|
end
|
84
77
|
|
85
78
|
def path
|
@@ -4,16 +4,18 @@ module DeepL
|
|
4
4
|
module Requests
|
5
5
|
class Translate < Base
|
6
6
|
BOOLEAN_CONVERSION = { true => '1', false => '0' }.freeze
|
7
|
-
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',
|
7
|
+
ARRAY_CONVERSION = ->(value) { value.is_a?(Array) ? value.join(',') : value }.freeze
|
8
8
|
OPTIONS_CONVERSIONS = {
|
9
9
|
split_sentences: BOOLEAN_CONVERSION,
|
10
10
|
preserve_formatting: BOOLEAN_CONVERSION,
|
11
11
|
outline_detection: BOOLEAN_CONVERSION,
|
12
|
+
splitting_tags: ARRAY_CONVERSION,
|
12
13
|
non_splitting_tags: ARRAY_CONVERSION,
|
13
14
|
ignore_tags: ARRAY_CONVERSION
|
14
15
|
}.freeze
|
15
16
|
|
16
|
-
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :
|
17
|
+
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
|
18
|
+
:non_splitting_tags
|
17
19
|
|
18
20
|
def initialize(api, text, source_lang, target_lang, options = {})
|
19
21
|
super(api, options)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DeepL
|
4
|
+
module Utils
|
5
|
+
class ExceptionBuilder
|
6
|
+
attr_reader :request, :response
|
7
|
+
|
8
|
+
ERROR_CODE_CLASS_MAP = {
|
9
|
+
'400' => Exceptions::BadRequest,
|
10
|
+
'401' => Exceptions::AuthorizationFailed,
|
11
|
+
'403' => Exceptions::AuthorizationFailed,
|
12
|
+
'404' => Exceptions::NotFound,
|
13
|
+
'413' => Exceptions::RequestEntityTooLarge,
|
14
|
+
'429' => Exceptions::LimitExceeded,
|
15
|
+
'456' => Exceptions::QuotaExceeded
|
16
|
+
}.freeze
|
17
|
+
|
18
|
+
def initialize(request, response)
|
19
|
+
@request = request
|
20
|
+
@response = response
|
21
|
+
end
|
22
|
+
|
23
|
+
def build
|
24
|
+
error_class = ERROR_CODE_CLASS_MAP[response.code.to_s] || Exceptions::RequestError
|
25
|
+
error_class.new(request, response)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/deepl.rb
CHANGED
@@ -13,6 +13,7 @@ require 'deepl/exceptions/limit_exceeded'
|
|
13
13
|
require 'deepl/exceptions/quota_exceeded'
|
14
14
|
require 'deepl/exceptions/not_found'
|
15
15
|
require 'deepl/exceptions/not_supported'
|
16
|
+
require 'deepl/exceptions/request_entity_too_large'
|
16
17
|
|
17
18
|
# -- Requests
|
18
19
|
require 'deepl/requests/base'
|
@@ -34,6 +35,9 @@ require 'deepl/resources/language_pair'
|
|
34
35
|
require 'deepl/resources/text'
|
35
36
|
require 'deepl/resources/usage'
|
36
37
|
|
38
|
+
# -- Utils
|
39
|
+
require 'deepl/utils/exception_builder'
|
40
|
+
|
37
41
|
# -- Other wrappers
|
38
42
|
require 'deepl/api'
|
39
43
|
require 'deepl/configuration'
|
@@ -9,7 +9,7 @@ describe DeepL::Configuration do
|
|
9
9
|
describe '#initialize' do
|
10
10
|
context 'When using default configuration attributes' do
|
11
11
|
it 'should use default attributes' do
|
12
|
-
expect(subject.auth_key).to eq(ENV
|
12
|
+
expect(subject.auth_key).to eq(ENV.fetch('DEEPL_AUTH_KEY', nil))
|
13
13
|
expect(subject.host).to eq('https://api.deepl.com')
|
14
14
|
expect(subject.version).to eq('v2')
|
15
15
|
end
|