Module: DeepL
- Extended by:
- DeepL
- Included in:
- DeepL
- Defined in:
- lib/deepl.rb,
lib/version.rb,
lib/deepl/api.rb,
lib/deepl/document_api.rb,
lib/deepl/glossary_api.rb,
lib/deepl/configuration.rb,
lib/deepl/requests/base.rb,
lib/http_client_options.rb,
lib/deepl/constants/tone.rb,
lib/deepl/requests/usage.rb,
lib/deepl/resources/base.rb,
lib/deepl/resources/text.rb,
lib/deepl/style_rule_api.rb,
lib/deepl/resources/usage.rb,
lib/deepl/exceptions/error.rb,
lib/deepl/requests/rephrase.rb,
lib/deepl/requests/languages.rb,
lib/deepl/requests/translate.rb,
lib/deepl/resources/glossary.rb,
lib/deepl/resources/language.rb,
lib/deepl/constants/formality.rb,
lib/deepl/utils/backoff_timer.rb,
lib/deepl/constants/model_type.rb,
lib/deepl/exceptions/not_found.rb,
lib/deepl/resources/style_rule.rb,
lib/deepl/constants/tag_handling.rb,
lib/deepl/exceptions/bad_request.rb,
lib/deepl/requests/glossary/find.rb,
lib/deepl/requests/glossary/list.rb,
lib/deepl/constants/base_constant.rb,
lib/deepl/constants/writing_style.rb,
lib/deepl/exceptions/server_error.rb,
lib/deepl/resources/language_pair.rb,
lib/deepl/utils/exception_builder.rb,
lib/deepl/exceptions/not_supported.rb,
lib/deepl/exceptions/request_error.rb,
lib/deepl/requests/document/upload.rb,
lib/deepl/requests/glossary/create.rb,
lib/deepl/requests/style_rule/list.rb,
lib/deepl/constants/split_sentences.rb,
lib/deepl/exceptions/limit_exceeded.rb,
lib/deepl/exceptions/quota_exceeded.rb,
lib/deepl/requests/glossary/destroy.rb,
lib/deepl/requests/glossary/entries.rb,
lib/deepl/resources/document_handle.rb,
lib/deepl/requests/document/download.rb,
lib/deepl/requests/document/get_status.rb,
lib/deepl/exceptions/authorization_failed.rb,
lib/deepl/requests/glossary/language_pairs.rb,
lib/deepl/exceptions/request_entity_too_large.rb,
lib/deepl/exceptions/document_translation_error.rb,
lib/deepl/resources/document_translation_status.rb
Overview
Copyright 2024 DeepL SE (www.deepl.com) Use of this source code is governed by an MIT license that can be found in the LICENSE file. frozen_string_literal: true
Defined Under Namespace
Modules: Constants, Exceptions, Requests, Resources, Utils
Classes: API, Configuration, DocumentApi, GlossaryApi, HTTPClientOptions, StyleRuleApi
Constant Summary
collapse
- VERSION =
'3.6.1'
Instance Method Summary
collapse
-
#api ⇒ Object
-
#configuration ⇒ Object
-
#configure {|configuration| ... } ⇒ Object
-
#document(options = {}) ⇒ Object
-
#glossaries(options = {}) ⇒ Object
-
#http_client ⇒ Object
-
#languages(options = {}) ⇒ Object
-
#rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#style_rules(options = {}) ⇒ Object
-
#translate(text, source_lang, target_lang, options = {}) ⇒ Object
-
#usage(options = {}) ⇒ Object
-
#with_session(client_options = HTTPClientOptions.new()) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
Instance Method Details
#api ⇒ Object
83
84
85
|
# File 'lib/deepl.rb', line 83
def api
@api ||= API.new(configuration)
end
|
#configuration ⇒ Object
150
151
152
|
# File 'lib/deepl.rb', line 150
def configuration
@configuration ||= Configuration.new
end
|
154
155
156
157
|
# File 'lib/deepl.rb', line 154
def configure
yield configuration if block_given?
configuration.validate!
end
|
#document(options = {}) ⇒ Object
96
97
98
99
|
# File 'lib/deepl.rb', line 96
def document(options = {})
configure if @configuration.nil?
DocumentApi.new(api, options)
end
|
#glossaries(options = {}) ⇒ Object
101
102
103
104
|
# File 'lib/deepl.rb', line 101
def glossaries(options = {})
configure if @configuration.nil?
GlossaryApi.new(api, options)
end
|
#http_client ⇒ Object
121
122
123
|
# File 'lib/deepl.rb', line 121
def http_client
@http_client
end
|
#languages(options = {}) ⇒ Object
#rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) ⇒ Object
rubocop:disable Metrics/ParameterLists
111
112
113
114
|
# File 'lib/deepl.rb', line 111
def rephrase(text, target_lang = nil, writing_style = nil, tone = nil, options = {}) configure if @configuration.nil?
Requests::Rephrase.new(api, text, target_lang, writing_style, tone, options).request
end
|
#style_rules(options = {}) ⇒ Object
106
107
108
109
|
# File 'lib/deepl.rb', line 106
def style_rules(options = {})
configure if @configuration.nil?
StyleRuleApi.new(api, options)
end
|
#translate(text, source_lang, target_lang, options = {}) ⇒ Object
91
92
93
94
|
# File 'lib/deepl.rb', line 91
def translate(text, source_lang, target_lang, options = {})
configure if @configuration.nil?
Requests::Translate.new(api, text, source_lang, target_lang, options).request
end
|
#usage(options = {}) ⇒ Object
116
117
118
119
|
# File 'lib/deepl.rb', line 116
def usage(options = {})
configure if @configuration.nil?
Requests::Usage.new(api, options).request
end
|
#with_session(client_options = HTTPClientOptions.new()) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/deepl.rb', line 125
def with_session(client_options = HTTPClientOptions.new()) raise ArgumentError 'This method requires a block to be passed in which contains the actual API calls, see README for example usage.' unless block_given?
has_proxy = client_options.proxy.key?('proxy_addr') and client_options.proxy.key?('proxy_port')
begin
uri = URI(configuration.host)
http = Net::HTTP.new(uri.host, uri.port, has_proxy ? client_options.proxy['proxy_addr'] : nil,
has_proxy ? client_options.proxy['proxy_port'] : nil)
http.use_ssl = client_options.enable_ssl_verification
http.ca_file = client_options.cert_path if client_options.cert_path
http.open_timeout = client_options.open_timeout unless client_options.open_timeout.nil?
http.read_timeout = client_options.read_timeout unless client_options.read_timeout.nil?
http.write_timeout = client_options.write_timeout unless client_options.write_timeout.nil?
http.ssl_timeout = client_options.ssl_timeout unless client_options.ssl_timeout.nil?
http.start
@http_client = http
api.update_http_client(http)
yield
ensure
http.finish
end
end
|