deepl-rb 3.3.0 → 3.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/CHANGELOG.md +11 -2
- data/README.md +58 -0
- metadata +2 -95
- data/.circleci/config.yml +0 -27
- data/.github/workflows/add_issues_to_kanban.yml +0 -16
- data/.gitlab-ci.yml +0 -172
- data/.rubocop.yml +0 -51
- data/CODE_OF_CONDUCT.md +0 -132
- data/CONTRIBUTING.md +0 -37
- data/Gemfile +0 -24
- data/Rakefile +0 -54
- data/SECURITY.md +0 -58
- data/VERSION +0 -1
- data/deepl-rb.gemspec +0 -133
- data/lib/deepl/api.rb +0 -22
- data/lib/deepl/configuration.rb +0 -59
- data/lib/deepl/constants/base_constant.rb +0 -18
- data/lib/deepl/constants/formality.rb +0 -16
- data/lib/deepl/constants/model_type.rb +0 -14
- data/lib/deepl/constants/split_sentences.rb +0 -14
- data/lib/deepl/constants/tag_handling.rb +0 -13
- data/lib/deepl/constants/tone.rb +0 -20
- data/lib/deepl/constants/writing_style.rb +0 -20
- data/lib/deepl/document_api.rb +0 -121
- data/lib/deepl/exceptions/authorization_failed.rb +0 -14
- data/lib/deepl/exceptions/bad_request.rb +0 -16
- data/lib/deepl/exceptions/document_translation_error.rb +0 -15
- data/lib/deepl/exceptions/error.rb +0 -14
- data/lib/deepl/exceptions/limit_exceeded.rb +0 -18
- data/lib/deepl/exceptions/not_found.rb +0 -16
- data/lib/deepl/exceptions/not_supported.rb +0 -14
- data/lib/deepl/exceptions/quota_exceeded.rb +0 -14
- data/lib/deepl/exceptions/request_entity_too_large.rb +0 -15
- data/lib/deepl/exceptions/request_error.rb +0 -21
- data/lib/deepl/exceptions/server_error.rb +0 -18
- data/lib/deepl/glossary_api.rb +0 -38
- data/lib/deepl/requests/base.rb +0 -196
- data/lib/deepl/requests/document/download.rb +0 -44
- data/lib/deepl/requests/document/get_status.rb +0 -44
- data/lib/deepl/requests/document/upload.rb +0 -74
- data/lib/deepl/requests/glossary/create.rb +0 -59
- data/lib/deepl/requests/glossary/destroy.rb +0 -37
- data/lib/deepl/requests/glossary/entries.rb +0 -37
- data/lib/deepl/requests/glossary/find.rb +0 -38
- data/lib/deepl/requests/glossary/language_pairs.rb +0 -38
- data/lib/deepl/requests/glossary/list.rb +0 -37
- data/lib/deepl/requests/languages.rb +0 -37
- data/lib/deepl/requests/rephrase.rb +0 -55
- data/lib/deepl/requests/translate.rb +0 -82
- data/lib/deepl/requests/usage.rb +0 -33
- data/lib/deepl/resources/base.rb +0 -17
- data/lib/deepl/resources/document_handle.rb +0 -57
- data/lib/deepl/resources/document_translation_status.rb +0 -54
- data/lib/deepl/resources/glossary.rb +0 -28
- data/lib/deepl/resources/language.rb +0 -30
- data/lib/deepl/resources/language_pair.rb +0 -23
- data/lib/deepl/resources/text.rb +0 -24
- data/lib/deepl/resources/usage.rb +0 -27
- data/lib/deepl/utils/backoff_timer.rb +0 -46
- data/lib/deepl/utils/exception_builder.rb +0 -34
- data/lib/deepl.rb +0 -147
- data/lib/http_client_options.rb +0 -22
- data/spec/api/api_spec.rb +0 -20
- data/spec/api/configuration_spec.rb +0 -122
- data/spec/api/deepl_spec.rb +0 -460
- data/spec/constants/constants_spec.rb +0 -158
- data/spec/fixtures/vcr_cassettes/deepl_document.yml +0 -95
- data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +0 -1214
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +0 -1163
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +0 -54
- data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +0 -87
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +0 -358
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +0 -129
- data/spec/fixtures/vcr_cassettes/glossaries.yml +0 -1702
- data/spec/fixtures/vcr_cassettes/languages.yml +0 -229
- data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +0 -401
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +0 -10415
- data/spec/fixtures/vcr_cassettes/usage.yml +0 -171
- data/spec/integration_tests/document_api_spec.rb +0 -177
- data/spec/integration_tests/integration_test_utils.rb +0 -170
- data/spec/requests/glossary/create_spec.rb +0 -65
- data/spec/requests/glossary/destroy_spec.rb +0 -66
- data/spec/requests/glossary/entries_spec.rb +0 -62
- data/spec/requests/glossary/find_spec.rb +0 -68
- data/spec/requests/glossary/language_pairs_spec.rb +0 -40
- data/spec/requests/glossary/list_spec.rb +0 -54
- data/spec/requests/languages_spec.rb +0 -68
- data/spec/requests/rephrase_spec.rb +0 -172
- data/spec/requests/translate_spec.rb +0 -422
- data/spec/requests/usage_spec.rb +0 -43
- data/spec/resources/glossary_spec.rb +0 -38
- data/spec/resources/language_pair_spec.rb +0 -23
- data/spec/resources/language_spec.rb +0 -45
- data/spec/resources/text_spec.rb +0 -23
- data/spec/resources/usage_spec.rb +0 -35
- data/spec/spec_helper.rb +0 -92
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
module Glossary
|
|
9
|
-
class LanguagePairs < Base
|
|
10
|
-
def initialize(api, options = {})
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def request
|
|
15
|
-
build_language_pair_list(*execute_request_with_retries(get_request))
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_s
|
|
19
|
-
"GET #{uri.request_uri}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def build_language_pair_list(request, response)
|
|
25
|
-
data = JSON.parse(response.body)
|
|
26
|
-
data['supported_languages'].map do |language_pair|
|
|
27
|
-
Resources::LanguagePair.new(language_pair['source_lang'], language_pair['target_lang'],
|
|
28
|
-
request, response)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def path
|
|
33
|
-
'glossary-language-pairs'
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
module Glossary
|
|
9
|
-
class List < Base
|
|
10
|
-
def initialize(api, options = {})
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def request
|
|
15
|
-
build_glossary_list(*execute_request_with_retries(get_request))
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_s
|
|
19
|
-
"GET #{uri.request_uri}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def build_glossary_list(request, response)
|
|
25
|
-
data = JSON.parse(response.body)
|
|
26
|
-
data['glossaries'].map do |glossary|
|
|
27
|
-
Resources::Glossary.new(glossary, request, response)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def path
|
|
32
|
-
'glossaries'
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Copyright 2021 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
class Languages < Base
|
|
9
|
-
def initialize(api, options = {})
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def request
|
|
14
|
-
build_languages(*execute_request_with_retries(get_request))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def to_s
|
|
18
|
-
"GET #{uri.request_uri}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
def build_languages(request, response)
|
|
24
|
-
data = JSON.parse(response.body)
|
|
25
|
-
data.map do |language|
|
|
26
|
-
Resources::Language.new(language['language'], language['name'],
|
|
27
|
-
language['supports_formality'],
|
|
28
|
-
request, response)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def path
|
|
33
|
-
'languages'
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Copyright 2025 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
class Rephrase < Base
|
|
9
|
-
attr_reader :text, :target_lang, :writing_style, :tone
|
|
10
|
-
|
|
11
|
-
def initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
|
|
12
|
-
super(api, options)
|
|
13
|
-
@text = text
|
|
14
|
-
@target_lang = target_lang
|
|
15
|
-
@writing_style = writing_style
|
|
16
|
-
@tone = tone
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def request # rubocop:disable Metrics/AbcSize
|
|
20
|
-
text_arrayified = text.is_a?(Array) ? text : [text]
|
|
21
|
-
payload = { text: text_arrayified }
|
|
22
|
-
payload[:target_lang] = target_lang unless target_lang.nil?
|
|
23
|
-
payload[:writing_style] = writing_style unless writing_style.nil?
|
|
24
|
-
payload[:tone] = tone unless tone.nil?
|
|
25
|
-
build_texts(*execute_request_with_retries(post_request(payload)))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def details
|
|
29
|
-
"HTTP Headers: #{headers}\nPayload #{{ text: text, target_lang: target_lang,
|
|
30
|
-
writing_style: writing_style, tone: tone }}"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def to_s
|
|
34
|
-
"POST #{uri.request_uri}"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def build_texts(request, response)
|
|
40
|
-
data = JSON.parse(response.body)
|
|
41
|
-
|
|
42
|
-
texts = data['improvements'].map do |improvement|
|
|
43
|
-
Resources::Text.new(improvement['text'], improvement['detected_source_language'], nil,
|
|
44
|
-
request, response)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
texts.size == 1 ? texts.first : texts
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def path
|
|
51
|
-
'write/rephrase'
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
class Translate < Base
|
|
9
|
-
STRING_TO_BOOLEAN_MAP = { '1' => true, '0' => false }.freeze
|
|
10
|
-
BOOLEAN_TO_STRING_MAP = { true => '1', false => '0' }.freeze
|
|
11
|
-
STRING_TO_BOOLEAN_CONVERSION = ->(value) { STRING_TO_BOOLEAN_MAP[value] }
|
|
12
|
-
BOOLEAN_TO_STRING_CONVERSION = ->(value) { BOOLEAN_TO_STRING_MAP[value] }
|
|
13
|
-
STRING_TO_ARRAY_CONVERSION = lambda { |value|
|
|
14
|
-
if value.nil?
|
|
15
|
-
nil
|
|
16
|
-
else
|
|
17
|
-
(value.is_a?(Array) ? value : value.split(','))
|
|
18
|
-
end
|
|
19
|
-
}.freeze
|
|
20
|
-
OPTIONS_CONVERSIONS = {
|
|
21
|
-
split_sentences: BOOLEAN_TO_STRING_CONVERSION,
|
|
22
|
-
preserve_formatting: STRING_TO_BOOLEAN_CONVERSION,
|
|
23
|
-
outline_detection: STRING_TO_BOOLEAN_CONVERSION,
|
|
24
|
-
splitting_tags: STRING_TO_ARRAY_CONVERSION,
|
|
25
|
-
non_splitting_tags: STRING_TO_ARRAY_CONVERSION,
|
|
26
|
-
ignore_tags: STRING_TO_ARRAY_CONVERSION
|
|
27
|
-
}.freeze
|
|
28
|
-
|
|
29
|
-
attr_reader :text, :source_lang, :target_lang, :ignore_tags, :splitting_tags,
|
|
30
|
-
:non_splitting_tags, :model_type
|
|
31
|
-
|
|
32
|
-
def initialize(api, text, source_lang, target_lang, options = {})
|
|
33
|
-
super(api, options)
|
|
34
|
-
@text = text
|
|
35
|
-
@source_lang = source_lang
|
|
36
|
-
@target_lang = target_lang
|
|
37
|
-
|
|
38
|
-
tweak_parameters!
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def request
|
|
42
|
-
text_arrayified = text.is_a?(Array) ? text : [text]
|
|
43
|
-
payload = { text: text_arrayified, source_lang: source_lang, target_lang: target_lang }
|
|
44
|
-
build_texts(*execute_request_with_retries(post_request(payload)))
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def details
|
|
48
|
-
"HTTP Headers: #{headers}\nPayload #{{ text: text, source_lang: source_lang,
|
|
49
|
-
target_lang: target_lang }}"
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def to_s
|
|
53
|
-
"POST #{uri.request_uri}"
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
private
|
|
57
|
-
|
|
58
|
-
def tweak_parameters!
|
|
59
|
-
OPTIONS_CONVERSIONS.each do |param, converter|
|
|
60
|
-
next unless option?(param) && !converter[option(param)].nil?
|
|
61
|
-
|
|
62
|
-
set_option(param, converter[option(param)])
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def build_texts(request, response)
|
|
67
|
-
data = JSON.parse(response.body)
|
|
68
|
-
|
|
69
|
-
texts = data['translations'].map do |translation|
|
|
70
|
-
Resources::Text.new(translation['text'], translation['detected_source_language'],
|
|
71
|
-
translation['model_type_used'], request, response)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
texts.size == 1 ? texts.first : texts
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def path
|
|
78
|
-
'translate'
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
data/lib/deepl/requests/usage.rb
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Requests
|
|
8
|
-
class Usage < Base
|
|
9
|
-
def initialize(api, options = {})
|
|
10
|
-
super
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def request
|
|
14
|
-
build_usage(*execute_request_with_retries(get_request))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def to_s
|
|
18
|
-
"GET #{uri.request_uri}"
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
private
|
|
22
|
-
|
|
23
|
-
def build_usage(request, response)
|
|
24
|
-
data = JSON.parse(response.body)
|
|
25
|
-
Resources::Usage.new(data['character_count'], data['character_limit'], request, response)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def path
|
|
29
|
-
'usage'
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
data/lib/deepl/resources/base.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class Base
|
|
9
|
-
attr_reader :request, :response
|
|
10
|
-
|
|
11
|
-
def initialize(request, response)
|
|
12
|
-
@request = request
|
|
13
|
-
@response = response
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class DocumentHandle < Base
|
|
9
|
-
attr_reader :document_id, :document_key
|
|
10
|
-
|
|
11
|
-
def initialize(document_id, document_key, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@document_id = document_id
|
|
15
|
-
@document_key = document_key
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_s
|
|
19
|
-
"DocumentHandle: ID: #{document_id} - Key: #{document_key}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
##
|
|
23
|
-
# For this DocumentHandle, waits until the document translation is finished and returns the
|
|
24
|
-
# final status of the document.
|
|
25
|
-
#
|
|
26
|
-
# @return [DeepL::Resources::DocumentTranslationStatus] Final status of the document
|
|
27
|
-
# translation.
|
|
28
|
-
|
|
29
|
-
def wait_until_document_translation_finished
|
|
30
|
-
doc_status = nil
|
|
31
|
-
max_tries = max_doc_status_queries
|
|
32
|
-
num_tries = 0
|
|
33
|
-
loop do
|
|
34
|
-
num_tries += 1
|
|
35
|
-
sleep(calculate_waiting_time(doc_status)) unless doc_status.nil?
|
|
36
|
-
doc_status = DeepL.document.get_status(self)
|
|
37
|
-
break if doc_status.finished? || num_tries > max_tries
|
|
38
|
-
end
|
|
39
|
-
doc_status
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def calculate_waiting_time(_resp)
|
|
45
|
-
# ignore _resp.seconds_remaining for now, while it is unreliable
|
|
46
|
-
5
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def max_doc_status_queries
|
|
50
|
-
configured_value = DeepL.configuration.max_doc_status_queries
|
|
51
|
-
return configured_value unless configured_value.nil?
|
|
52
|
-
|
|
53
|
-
10
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class DocumentTranslationStatus < Base
|
|
9
|
-
attr_reader :document_id, :status, :seconds_remaining, :billed_characters, :error_message
|
|
10
|
-
|
|
11
|
-
def initialize(response, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@document_id = response['document_id']
|
|
15
|
-
@status = response['status']
|
|
16
|
-
@seconds_remaining = response['seconds_remaining']
|
|
17
|
-
@billed_characters = response['billed_characters']
|
|
18
|
-
@error_message = response['error_message']
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def to_s
|
|
22
|
-
"DocumentTranslationStatus: ID: #{document_id} - Status: #{status} " \
|
|
23
|
-
"- Error message: #{error_message}"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
##
|
|
27
|
-
# Checks if the translation finished successfully
|
|
28
|
-
#
|
|
29
|
-
# @return [true] if so
|
|
30
|
-
|
|
31
|
-
def successful?
|
|
32
|
-
status == 'done'
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
##
|
|
36
|
-
# Checks if there was an error during translation
|
|
37
|
-
#
|
|
38
|
-
# @return [true] if so
|
|
39
|
-
|
|
40
|
-
def error?
|
|
41
|
-
status == 'error'
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
##
|
|
45
|
-
# Checks if the translation process terminated. Note that this could be due to an error as
|
|
46
|
-
# well, but means no further waiting is necessary.
|
|
47
|
-
#
|
|
48
|
-
# @return [true] if so
|
|
49
|
-
def finished?
|
|
50
|
-
successful? || error?
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class Glossary < Base
|
|
9
|
-
attr_reader :id, :name, :ready, :source_lang, :target_lang, :creation_time, :entry_count
|
|
10
|
-
|
|
11
|
-
def initialize(glossary, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@id = glossary['glossary_id']
|
|
15
|
-
@name = glossary['name']
|
|
16
|
-
@ready = glossary['ready']
|
|
17
|
-
@source_lang = glossary['source_lang']
|
|
18
|
-
@target_lang = glossary['target_lang']
|
|
19
|
-
@creation_time = glossary['creation_time']
|
|
20
|
-
@entry_count = glossary['entry_count']
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def to_s
|
|
24
|
-
"#{id} - #{name}"
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Copyright 2021 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class Language < Base
|
|
9
|
-
attr_reader :code, :name
|
|
10
|
-
|
|
11
|
-
def initialize(code, name, supports_formality, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@code = code
|
|
15
|
-
@name = name
|
|
16
|
-
@supports_formality = supports_formality
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def to_s
|
|
20
|
-
"#{code} - #{name}"
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def supports_formality?
|
|
24
|
-
return @supports_formality unless @supports_formality.nil?
|
|
25
|
-
|
|
26
|
-
raise Exceptions::NotSupported, 'Support formality is only available on target languages'
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class LanguagePair < Base
|
|
9
|
-
attr_reader :source_lang, :target_lang
|
|
10
|
-
|
|
11
|
-
def initialize(source_lang, target_lang, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@source_lang = source_lang
|
|
15
|
-
@target_lang = target_lang
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_s
|
|
19
|
-
"#{source_lang} - #{target_lang}"
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
data/lib/deepl/resources/text.rb
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class Text < Base
|
|
9
|
-
attr_reader :text, :detected_source_language, :model_type_used
|
|
10
|
-
|
|
11
|
-
def initialize(text, detected_source_language, model_type_used, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@text = text
|
|
15
|
-
@detected_source_language = detected_source_language
|
|
16
|
-
@model_type_used = model_type_used
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def to_s
|
|
20
|
-
text
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Resources
|
|
8
|
-
class Usage < Base
|
|
9
|
-
attr_reader :character_count, :character_limit
|
|
10
|
-
|
|
11
|
-
def initialize(character_count, character_limit, *args)
|
|
12
|
-
super(*args)
|
|
13
|
-
|
|
14
|
-
@character_count = character_count
|
|
15
|
-
@character_limit = character_limit
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def to_s
|
|
19
|
-
"#{character_count} / #{character_limit}"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def quota_exceeded?
|
|
23
|
-
character_count >= character_limit
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# Copyright 2024 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Utils
|
|
8
|
-
class BackoffTimer
|
|
9
|
-
# Implements exponential-backoff strategy.
|
|
10
|
-
# This strategy is based on the GRPC Connection Backoff Protocol:
|
|
11
|
-
# https://github.com/grpc/grpc/blob/master/doc/connection-backoff.md
|
|
12
|
-
|
|
13
|
-
BACKOFF_INITIAL = 1.0
|
|
14
|
-
BACKOFF_MAX = 120.0
|
|
15
|
-
BACKOFF_JITTER = 0.23
|
|
16
|
-
BACKOFF_MULTIPLIER = 1.6
|
|
17
|
-
|
|
18
|
-
attr_reader :num_retries
|
|
19
|
-
|
|
20
|
-
def initialize(min_connection_timeout = 10.0)
|
|
21
|
-
@num_retries = 0
|
|
22
|
-
@backoff = BACKOFF_INITIAL
|
|
23
|
-
@deadline = Time.now.to_f + @backoff
|
|
24
|
-
@min_connection_timeout = min_connection_timeout
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def current_request_timeout
|
|
28
|
-
[time_until_deadline, @min_connection_timeout].max
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def time_until_deadline
|
|
32
|
-
[@deadline - Time.now.to_f, 0.0].max
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def sleep_until_deadline
|
|
36
|
-
sleep(time_until_deadline)
|
|
37
|
-
# Apply multiplier to current backoff time
|
|
38
|
-
@backoff = [@backoff * BACKOFF_MULTIPLIER, BACKOFF_MAX].min
|
|
39
|
-
# Get deadline by applying jitter as a proportion of backoff:
|
|
40
|
-
# if jitter is 0.1, then multiply backoff by random value in [0.9, 1.1]
|
|
41
|
-
@deadline = Time.now.to_f + (@backoff * (1 + (BACKOFF_JITTER * rand(-1.0..1.0))))
|
|
42
|
-
@num_retries += 1
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# Copyright 2022 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
module DeepL
|
|
7
|
-
module Utils
|
|
8
|
-
class ExceptionBuilder
|
|
9
|
-
attr_reader :request, :response
|
|
10
|
-
|
|
11
|
-
def self.error_class_from_response_code(code) # rubocop:disable Metrics/CyclomaticComplexity
|
|
12
|
-
case code
|
|
13
|
-
when 400 then Exceptions::BadRequest
|
|
14
|
-
when 401, 403 then Exceptions::AuthorizationFailed
|
|
15
|
-
when 404 then Exceptions::NotFound
|
|
16
|
-
when 413 then Exceptions::RequestEntityTooLarge
|
|
17
|
-
when 429 then Exceptions::LimitExceeded
|
|
18
|
-
when 456 then Exceptions::QuotaExceeded
|
|
19
|
-
when 500..599 then Exceptions::ServerError
|
|
20
|
-
else Exceptions::RequestError
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def initialize(response)
|
|
25
|
-
@response = response
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def build
|
|
29
|
-
error_class = self.class.error_class_from_response_code(response.code.to_i)
|
|
30
|
-
error_class.new(response)
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|