Module: DeepL
- Extended by:
- DeepL
- Included in:
- DeepL
- Defined in:
- lib/deepl.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/requests/usage.rb,
lib/deepl/resources/base.rb,
lib/deepl/resources/text.rb,
lib/deepl/resources/usage.rb,
lib/deepl/exceptions/error.rb,
lib/deepl/requests/languages.rb,
lib/deepl/requests/translate.rb,
lib/deepl/resources/glossary.rb,
lib/deepl/resources/language.rb,
lib/deepl/utils/backoff_timer.rb,
lib/deepl/exceptions/not_found.rb,
lib/deepl/exceptions/bad_request.rb,
lib/deepl/requests/glossary/find.rb,
lib/deepl/requests/glossary/list.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/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: Exceptions, Requests, Resources, Utils
Classes: API, Configuration, DocumentApi, GlossaryApi, HTTPClientOptions
Instance Method Summary
collapse
Instance Method Details
#api ⇒ Object
67
68
69
|
# File 'lib/deepl.rb', line 67
def api
@api ||= API.new(configuration)
end
|
#configuration ⇒ Object
124
125
126
|
# File 'lib/deepl.rb', line 124
def configuration
@configuration ||= Configuration.new
end
|
128
129
130
131
|
# File 'lib/deepl.rb', line 128
def configure
yield configuration if block_given?
configuration.validate!
end
|
#document(options = {}) ⇒ Object
80
81
82
83
|
# File 'lib/deepl.rb', line 80
def document(options = {})
configure if @configuration.nil?
DocumentApi.new(api, options)
end
|
#glossaries(options = {}) ⇒ Object
85
86
87
88
|
# File 'lib/deepl.rb', line 85
def glossaries(options = {})
configure if @configuration.nil?
GlossaryApi.new(api, options)
end
|
#http_client ⇒ Object
95
96
97
|
# File 'lib/deepl.rb', line 95
def http_client
@http_client
end
|
#languages(options = {}) ⇒ Object
#translate(text, source_lang, target_lang, options = {}) ⇒ Object
75
76
77
78
|
# File 'lib/deepl.rb', line 75
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
90
91
92
93
|
# File 'lib/deepl.rb', line 90
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/deepl.rb', line 99
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
|