deepl-rb 3.6.0 → 3.7.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/.circleci/config.yml +27 -0
- data/.github/workflows/add_issues_to_kanban.yml +16 -0
- data/.gitlab-ci.yml +177 -0
- data/.rubocop.yml +51 -0
- data/CHANGELOG.md +40 -3
- data/CODE_OF_CONDUCT.md +132 -0
- data/CONTRIBUTING.md +37 -0
- data/Gemfile +24 -0
- data/README.md +153 -22
- data/Rakefile +58 -0
- data/SECURITY.md +58 -0
- data/VERSION +1 -0
- data/deepl-rb.gemspec +167 -0
- data/lib/deepl/api.rb +22 -0
- data/lib/deepl/configuration.rb +59 -0
- data/lib/deepl/constants/base_constant.rb +18 -0
- data/lib/deepl/constants/formality.rb +16 -0
- data/lib/deepl/constants/model_type.rb +14 -0
- data/lib/deepl/constants/split_sentences.rb +14 -0
- data/lib/deepl/constants/tag_handling.rb +13 -0
- data/lib/deepl/constants/tone.rb +20 -0
- data/lib/deepl/constants/writing_style.rb +20 -0
- data/lib/deepl/document_api.rb +121 -0
- data/lib/deepl/exceptions/authorization_failed.rb +14 -0
- data/lib/deepl/exceptions/bad_request.rb +16 -0
- data/lib/deepl/exceptions/document_translation_error.rb +15 -0
- data/lib/deepl/exceptions/error.rb +14 -0
- data/lib/deepl/exceptions/limit_exceeded.rb +18 -0
- data/lib/deepl/exceptions/not_found.rb +16 -0
- data/lib/deepl/exceptions/not_supported.rb +14 -0
- data/lib/deepl/exceptions/quota_exceeded.rb +14 -0
- data/lib/deepl/exceptions/request_entity_too_large.rb +15 -0
- data/lib/deepl/exceptions/request_error.rb +21 -0
- data/lib/deepl/exceptions/server_error.rb +18 -0
- data/lib/deepl/glossary_api.rb +38 -0
- data/lib/deepl/requests/base.rb +212 -0
- data/lib/deepl/requests/document/download.rb +44 -0
- data/lib/deepl/requests/document/get_status.rb +44 -0
- data/lib/deepl/requests/document/upload.rb +75 -0
- data/lib/deepl/requests/glossary/create.rb +59 -0
- data/lib/deepl/requests/glossary/destroy.rb +37 -0
- data/lib/deepl/requests/glossary/entries.rb +37 -0
- data/lib/deepl/requests/glossary/find.rb +38 -0
- data/lib/deepl/requests/glossary/language_pairs.rb +38 -0
- data/lib/deepl/requests/glossary/list.rb +37 -0
- data/lib/deepl/requests/languages.rb +37 -0
- data/lib/deepl/requests/rephrase.rb +55 -0
- data/lib/deepl/requests/style_rule/create.rb +46 -0
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +45 -0
- data/lib/deepl/requests/style_rule/destroy.rb +39 -0
- data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +40 -0
- data/lib/deepl/requests/style_rule/find.rb +40 -0
- data/lib/deepl/requests/style_rule/find_custom_instruction.rb +41 -0
- data/lib/deepl/requests/style_rule/list.rb +59 -0
- data/lib/deepl/requests/style_rule/update.rb +42 -0
- data/lib/deepl/requests/style_rule/update_configured_rules.rb +41 -0
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +47 -0
- data/lib/deepl/requests/translate.rb +106 -0
- data/lib/deepl/requests/translation_memory/list.rb +58 -0
- data/lib/deepl/requests/usage.rb +33 -0
- data/lib/deepl/resources/base.rb +17 -0
- data/lib/deepl/resources/document_handle.rb +57 -0
- data/lib/deepl/resources/document_translation_status.rb +54 -0
- data/lib/deepl/resources/glossary.rb +28 -0
- data/lib/deepl/resources/language.rb +30 -0
- data/lib/deepl/resources/language_pair.rb +23 -0
- data/lib/deepl/resources/style_rule.rb +86 -0
- data/lib/deepl/resources/text.rb +24 -0
- data/lib/deepl/resources/translation_memory.rb +25 -0
- data/lib/deepl/resources/usage.rb +27 -0
- data/lib/deepl/style_rule_api.rb +61 -0
- data/lib/deepl/translation_memory_api.rb +17 -0
- data/lib/deepl/utils/backoff_timer.rb +46 -0
- data/lib/deepl/utils/exception_builder.rb +34 -0
- data/lib/deepl.rb +175 -0
- data/lib/http_client_options.rb +22 -0
- data/lib/version.rb +8 -0
- data/spec/api/api_spec.rb +20 -0
- data/spec/api/configuration_spec.rb +122 -0
- data/spec/api/deepl_spec.rb +460 -0
- data/spec/constants/constants_spec.rb +158 -0
- data/spec/fixtures/vcr_cassettes/deepl_document.yml +95 -0
- data/spec/fixtures/vcr_cassettes/deepl_document_download.yml +1214 -0
- data/spec/fixtures/vcr_cassettes/deepl_glossaries.yml +1163 -0
- data/spec/fixtures/vcr_cassettes/deepl_languages.yml +54 -0
- data/spec/fixtures/vcr_cassettes/deepl_rephrase.yml +87 -0
- data/spec/fixtures/vcr_cassettes/deepl_translate.yml +358 -0
- data/spec/fixtures/vcr_cassettes/deepl_usage.yml +129 -0
- data/spec/fixtures/vcr_cassettes/glossaries.yml +1702 -0
- data/spec/fixtures/vcr_cassettes/languages.yml +229 -0
- data/spec/fixtures/vcr_cassettes/rephrase_texts.yml +401 -0
- data/spec/fixtures/vcr_cassettes/style_rules.yml +92 -0
- data/spec/fixtures/vcr_cassettes/style_rules_crud.yml +926 -0
- data/spec/fixtures/vcr_cassettes/translate_texts.yml +10630 -0
- data/spec/fixtures/vcr_cassettes/translation_memories.yml +74 -0
- data/spec/fixtures/vcr_cassettes/usage.yml +171 -0
- data/spec/integration_tests/document_api_spec.rb +178 -0
- data/spec/integration_tests/integration_test_utils.rb +170 -0
- data/spec/integration_tests/style_rule_api_spec.rb +135 -0
- data/spec/integration_tests/translation_memory_api_spec.rb +70 -0
- data/spec/requests/extra_body_parameters_types_spec.rb +82 -0
- data/spec/requests/glossary/create_spec.rb +65 -0
- data/spec/requests/glossary/destroy_spec.rb +66 -0
- data/spec/requests/glossary/entries_spec.rb +62 -0
- data/spec/requests/glossary/find_spec.rb +68 -0
- data/spec/requests/glossary/language_pairs_spec.rb +40 -0
- data/spec/requests/glossary/list_spec.rb +54 -0
- data/spec/requests/languages_spec.rb +68 -0
- data/spec/requests/rephrase_spec.rb +172 -0
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +54 -0
- data/spec/requests/style_rule/create_spec.rb +45 -0
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +54 -0
- data/spec/requests/style_rule/destroy_spec.rb +54 -0
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +56 -0
- data/spec/requests/style_rule/find_spec.rb +56 -0
- data/spec/requests/style_rule/list_spec.rb +58 -0
- data/spec/requests/style_rule/update_configured_rules_spec.rb +52 -0
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +58 -0
- data/spec/requests/style_rule/update_spec.rb +48 -0
- data/spec/requests/translate_spec.rb +492 -0
- data/spec/requests/translation_memory/list_spec.rb +61 -0
- data/spec/requests/usage_spec.rb +43 -0
- data/spec/resources/glossary_spec.rb +38 -0
- data/spec/resources/language_pair_spec.rb +23 -0
- data/spec/resources/language_spec.rb +45 -0
- data/spec/resources/text_spec.rb +23 -0
- data/spec/resources/translation_memory_spec.rb +35 -0
- data/spec/resources/usage_spec.rb +35 -0
- data/spec/spec_helper.rb +92 -0
- metadata +130 -3
|
@@ -0,0 +1,44 @@
|
|
|
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 Requests
|
|
8
|
+
module Document
|
|
9
|
+
class GetStatus < Base
|
|
10
|
+
attr_reader :document_id, :document_key
|
|
11
|
+
|
|
12
|
+
def initialize(api, document_id, document_key, options = {}, additional_headers = {})
|
|
13
|
+
super(api, options, additional_headers)
|
|
14
|
+
@document_id = document_id
|
|
15
|
+
@document_key = document_key
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def request
|
|
19
|
+
payload = { document_key: document_key }
|
|
20
|
+
build_doc_translation_status(*execute_request_with_retries(post_request(payload)))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def details
|
|
24
|
+
"HTTP Headers: #{headers}\nPayload #{{ document_key: document_key }}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_s
|
|
28
|
+
"POST #{uri.request_uri}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def build_doc_translation_status(request, response)
|
|
34
|
+
document_translation_status = JSON.parse(response.body)
|
|
35
|
+
Resources::DocumentTranslationStatus.new(document_translation_status, request, response)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def path
|
|
39
|
+
"document/#{document_id}"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,75 @@
|
|
|
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 Requests
|
|
8
|
+
module Document
|
|
9
|
+
class Upload < Base
|
|
10
|
+
attr_reader :input_file_path, :source_lang, :target_lang, :filename
|
|
11
|
+
|
|
12
|
+
SUPPORTED_OPTIONS = %w[formality glossary_id output_format].freeze
|
|
13
|
+
|
|
14
|
+
def initialize(api, input_file_path, source_lang, target_lang, filename = nil, # rubocop:disable Metrics/ParameterLists
|
|
15
|
+
options = {}, additional_headers = {})
|
|
16
|
+
super(api, options, additional_headers)
|
|
17
|
+
@input_file_path = input_file_path
|
|
18
|
+
@source_lang = source_lang
|
|
19
|
+
@target_lang = target_lang
|
|
20
|
+
@filename = filename
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def request
|
|
24
|
+
File.open(input_file_path, 'rb') do |input_file|
|
|
25
|
+
form_data = build_base_form_data(input_file)
|
|
26
|
+
apply_extra_body_parameters_to_form(form_data)
|
|
27
|
+
build_doc_handle(*execute_request_with_retries(post_request_with_file(form_data),
|
|
28
|
+
[input_file]))
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def details
|
|
33
|
+
"HTTP Headers: #{headers}\nPayload #{[
|
|
34
|
+
['file', "File at #{input_file_path} opened in binary mode"],
|
|
35
|
+
['source_lang', source_lang], ['target_lang', target_lang], ['filename', filename]
|
|
36
|
+
]}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_s
|
|
40
|
+
"POST #{uri.request_uri}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def build_base_form_data(input_file)
|
|
46
|
+
form_data = [
|
|
47
|
+
['file', input_file], ['source_lang', source_lang],
|
|
48
|
+
['target_lang', target_lang]
|
|
49
|
+
]
|
|
50
|
+
filename_param = filename || File.basename(input_file_path)
|
|
51
|
+
form_data.push(['filename', filename_param]) unless filename_param.nil?
|
|
52
|
+
add_supported_options_to_form(form_data)
|
|
53
|
+
form_data
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def add_supported_options_to_form(form_data)
|
|
57
|
+
SUPPORTED_OPTIONS.each do |option_name|
|
|
58
|
+
option_value = option(option_name)
|
|
59
|
+
form_data.push([option_name, option_value]) unless option_value.nil?
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def build_doc_handle(request, response)
|
|
64
|
+
parsed_response = JSON.parse(response.body)
|
|
65
|
+
Resources::DocumentHandle.new(parsed_response['document_id'],
|
|
66
|
+
parsed_response['document_key'], request, response)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def path
|
|
70
|
+
'document'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
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 Create < Base
|
|
10
|
+
attr_reader :name, :source_lang, :target_lang, :entries, :entries_format
|
|
11
|
+
|
|
12
|
+
def initialize(api, name, source_lang, target_lang, entries, options = {})
|
|
13
|
+
super(api, options)
|
|
14
|
+
@name = name
|
|
15
|
+
@source_lang = source_lang
|
|
16
|
+
@target_lang = target_lang
|
|
17
|
+
@entries = entries
|
|
18
|
+
@entries_format = delete_option(:entries_format) || 'tsv'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def request
|
|
22
|
+
payload = {
|
|
23
|
+
name: name, source_lang: source_lang, target_lang: target_lang, entries: entries_to_tsv,
|
|
24
|
+
entries_format: entries_format
|
|
25
|
+
}
|
|
26
|
+
build_glossary(*execute_request_with_retries(post_request(payload)))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def details
|
|
30
|
+
"HTTP Headers: #{headers}\nPayload #{{
|
|
31
|
+
name: name, source_lang: source_lang, target_lang: target_lang, entries: entries_to_tsv,
|
|
32
|
+
entries_format: entries_format
|
|
33
|
+
}}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def to_s
|
|
37
|
+
"POST #{uri.request_uri}"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
private
|
|
41
|
+
|
|
42
|
+
def entries_to_tsv
|
|
43
|
+
return entries if entries.is_a?(String)
|
|
44
|
+
|
|
45
|
+
entries.reduce('') { |tsv, entry| "#{tsv}#{entry.first}\t#{entry.last}\n" }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def build_glossary(request, response)
|
|
49
|
+
glossary = JSON.parse(response.body)
|
|
50
|
+
Resources::Glossary.new(glossary, request, response)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def path
|
|
54
|
+
'glossaries'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Destroy < Base
|
|
10
|
+
attr_reader :id
|
|
11
|
+
|
|
12
|
+
def initialize(api, id, options = {})
|
|
13
|
+
super(api, options)
|
|
14
|
+
@id = id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def request
|
|
18
|
+
build_response(*execute_request_with_retries(delete_request))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
"DELETE #{uri.request_uri}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build_response(_, _)
|
|
28
|
+
id
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def path
|
|
32
|
+
"glossaries/#{id}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
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 Entries < Base
|
|
10
|
+
attr_reader :id
|
|
11
|
+
|
|
12
|
+
def initialize(api, id, options = {})
|
|
13
|
+
super(api, options)
|
|
14
|
+
@id = id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def request
|
|
18
|
+
build_entries(*execute_request_with_retries(get_request))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
"GET #{uri.request_uri}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build_entries(_, response)
|
|
28
|
+
response.body.split("\n").map { |entry| entry.split("\t") }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def path
|
|
32
|
+
"glossaries/#{id}/entries"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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 Find < Base
|
|
10
|
+
attr_reader :id
|
|
11
|
+
|
|
12
|
+
def initialize(api, id, options = {})
|
|
13
|
+
super(api, options)
|
|
14
|
+
@id = id
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def request
|
|
18
|
+
build_glossary(*execute_request_with_retries(get_request))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def to_s
|
|
22
|
+
"GET #{uri.request_uri}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def build_glossary(request, response)
|
|
28
|
+
glossary = JSON.parse(response.body)
|
|
29
|
+
Resources::Glossary.new(glossary, request, response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def path
|
|
33
|
+
"glossaries/#{id}"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Copyright 2026 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
|
+
module StyleRule
|
|
9
|
+
class Create < Base
|
|
10
|
+
def initialize(api, name, language, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@name = name
|
|
13
|
+
@language = language
|
|
14
|
+
@configured_rules = delete_option(:configured_rules)
|
|
15
|
+
@custom_instructions = delete_option(:custom_instructions)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def request
|
|
19
|
+
payload = { name: @name, language: @language }
|
|
20
|
+
payload[:configured_rules] = @configured_rules if @configured_rules
|
|
21
|
+
payload[:custom_instructions] = @custom_instructions if @custom_instructions
|
|
22
|
+
build_style_rule(*execute_request_with_retries(post_request(payload)))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def to_s
|
|
26
|
+
"POST #{uri.request_uri}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def build_style_rule(request, response)
|
|
32
|
+
data = JSON.parse(response.body)
|
|
33
|
+
DeepL::Resources::StyleRule.new(data, request, response)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def uri
|
|
37
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def path
|
|
41
|
+
'style_rules'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright 2026 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
|
+
module StyleRule
|
|
9
|
+
class CreateCustomInstruction < Base
|
|
10
|
+
def initialize(api, style_id, label, prompt, source_language = nil, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
@label = label
|
|
14
|
+
@prompt = prompt
|
|
15
|
+
@source_language = source_language
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def request
|
|
19
|
+
payload = { label: @label, prompt: @prompt }
|
|
20
|
+
payload[:source_language] = @source_language if @source_language
|
|
21
|
+
build_custom_instruction(*execute_request_with_retries(post_request(payload)))
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s
|
|
25
|
+
"POST #{uri.request_uri}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def build_custom_instruction(_request, response)
|
|
31
|
+
data = JSON.parse(response.body)
|
|
32
|
+
DeepL::Resources::CustomInstruction.new(data)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def uri
|
|
36
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def path
|
|
40
|
+
"style_rules/#{@style_id}/custom_instructions"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Copyright 2026 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
|
+
module StyleRule
|
|
9
|
+
class Destroy < Base
|
|
10
|
+
def initialize(api, style_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def request
|
|
16
|
+
build_response(*execute_request_with_retries(delete_request))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"DELETE #{uri.request_uri}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def build_response(_, _)
|
|
26
|
+
@style_id
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def uri
|
|
30
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def path
|
|
34
|
+
"style_rules/#{@style_id}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright 2026 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
|
+
module StyleRule
|
|
9
|
+
class DestroyCustomInstruction < Base
|
|
10
|
+
def initialize(api, style_id, instruction_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
@instruction_id = instruction_id
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def request
|
|
17
|
+
build_response(*execute_request_with_retries(delete_request))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_s
|
|
21
|
+
"DELETE #{uri.request_uri}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def build_response(_, _)
|
|
27
|
+
@instruction_id
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uri
|
|
31
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def path
|
|
35
|
+
"style_rules/#{@style_id}/custom_instructions/#{@instruction_id}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Copyright 2026 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
|
+
module StyleRule
|
|
9
|
+
class Find < Base
|
|
10
|
+
def initialize(api, style_id, options = {})
|
|
11
|
+
super(api, options)
|
|
12
|
+
@style_id = style_id
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def request
|
|
16
|
+
build_style_rule(*execute_request_with_retries(get_request))
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"GET #{uri.request_uri}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def build_style_rule(request, response)
|
|
26
|
+
data = JSON.parse(response.body)
|
|
27
|
+
DeepL::Resources::StyleRule.new(data, request, response)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def uri
|
|
31
|
+
@uri ||= URI("#{host}/v3/#{path}")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def path
|
|
35
|
+
"style_rules/#{@style_id}"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|