Class: DeepL::Requests::Base
- Inherits:
-
Object
- Object
- DeepL::Requests::Base
- Defined in:
- lib/deepl/requests/base.rb
Overview
rubocop:disable Metrics/ClassLength
Direct Known Subclasses
Correct, Document::Download, Document::GetStatus, Document::Upload, Glossary::Base, Glossary::Create, LanguageResources, Languages, LanguagesForResource, MultilingualGlossary::Create, MultilingualGlossary::Destroy, MultilingualGlossary::DestroyDictionary, MultilingualGlossary::Entries, MultilingualGlossary::Find, MultilingualGlossary::List, MultilingualGlossary::ReplaceDictionary, MultilingualGlossary::Update, Rephrase, SpokenTerms::Create, SpokenTerms::Destroy, SpokenTerms::DestroyTermList, SpokenTerms::Entries, SpokenTerms::Find, SpokenTerms::List, SpokenTerms::ReplaceTermList, SpokenTerms::Update, StyleProfile::Base, StyleRule::Create, StyleRule::CreateCustomInstruction, StyleRule::Destroy, StyleRule::DestroyCustomInstruction, StyleRule::Find, StyleRule::FindCustomInstruction, StyleRule::List, StyleRule::Update, StyleRule::UpdateConfiguredRules, StyleRule::UpdateCustomInstruction, Translate, TranslationMemory::Base, TranslationMemory::StorageBase, Usage
Defined Under Namespace
Modules: ResponseFormatGuard Classes: BodilessPost
Constant Summary collapse
- MAX_GLOSSARY_IDS =
Maximum number of glossaries that may be provided via the
glossary_idsoption. 5- RETRYABLE_NETWORK_ERRORS =
Transient network failures, which are retried: DNS (SocketError), timeouts (Net::OpenTimeout and Net::ReadTimeout are Timeout::Errors), refused or reset connections, broken pipes and unreachable hosts (SystemCallError), and connections closed early.
[Timeout::Error, SocketError, SystemCallError, EOFError].freeze
- NETWORK_ERRORS =
Network failures without an HTTP response from the API. TLS failures, malformed responses and proxy failures (Net::ProtocolError, raised when a proxy refuses CONNECT, e.g. with 407) are not transient and are raised without retrying.
[*RETRYABLE_NETWORK_ERRORS, Net::HTTPBadResponse, OpenSSL::SSL::SSLError, Net::ProtocolError].freeze
- RESPONSE_FORMAT_ERRORS =
Errors raised while building the result from a received response: the response has an unexpected format.
[JSON::ParserError, NoMethodError, TypeError, KeyError].freeze
- TECHNICAL_HEADERS =
Headers that describe the request the SDK builds; a caller's value is dropped.
%w[content-type content-length transfer-encoding host].freeze
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
- .accepted_options ⇒ Object
-
.accepts_options(*names) ⇒ Object
Declares the options a request class accepts besides
extra_body_parameters. - .inherited(subclass) ⇒ Object
- .validate_options!(options) ⇒ Object
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(api, options = {}, additional_headers = {}) ⇒ Base
constructor
Options set to nil are unset and not sent.
- #request ⇒ Object
Constructor Details
#initialize(api, options = {}, additional_headers = {}) ⇒ Base
Options set to nil are unset and not sent.
79 80 81 82 83 84 85 86 |
# File 'lib/deepl/requests/base.rb', line 79 def initialize(api, = {}, additional_headers = {}) @api = api self.class.() @options = .compact @additional_headers = additional_headers @num_retries = 0 @backoff_timer = Utils::BackoffTimer.new end |
Instance Attribute Details
#api ⇒ Object (readonly)
Returns the value of attribute api.
76 77 78 |
# File 'lib/deepl/requests/base.rb', line 76 def api @api end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
76 77 78 |
# File 'lib/deepl/requests/base.rb', line 76 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
76 77 78 |
# File 'lib/deepl/requests/base.rb', line 76 def response @response end |
Class Method Details
.accepted_options ⇒ Object
61 62 63 |
# File 'lib/deepl/requests/base.rb', line 61 def self. @accepted_options || [] end |
.accepts_options(*names) ⇒ Object
Declares the options a request class accepts besides extra_body_parameters. Any other
option raises ArgumentError before a request is sent.
57 58 59 |
# File 'lib/deepl/requests/base.rb', line 57 def self.(*names) @accepted_options = names.map(&:to_s).freeze end |
.inherited(subclass) ⇒ Object
50 51 52 53 |
# File 'lib/deepl/requests/base.rb', line 50 def self.inherited(subclass) super subclass.prepend(ResponseFormatGuard) end |
.validate_options!(options) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/deepl/requests/base.rb', line 66 def self.() accepted = + ['extra_body_parameters'] unknown = .keys.reject { |name| accepted.include?(name.to_s) } return if unknown.empty? names = unknown.map { |name| "`#{name}`" }.join(', ') raise ArgumentError, "Unknown option#{'s' if unknown.size > 1} #{names}; use " \ '`extra_body_parameters` to send fields the SDK does not model' end |
Instance Method Details
#details ⇒ Object
92 93 94 |
# File 'lib/deepl/requests/base.rb', line 92 def details "HTTP Headers #{loggable_headers}" end |
#request ⇒ Object
88 89 90 |
# File 'lib/deepl/requests/base.rb', line 88 def request raise NotImplementedError end |