Class: TranslationDiff::HTTPProvider

Inherits:
Provider
  • Object
show all
Defined in:
lib/translation_diff/http_provider.rb

Overview

Every HTTP provider inherits this; no logging middleware, ever -- lines must carry no source text or credential.

Constant Summary collapse

RETRY_STATUSES =
[429, 500, 502, 503, 504].freeze
TRANSPORT_FAILURES =

Faraday raises these when nobody answered, as opposed to answering "no".

[Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError].freeze

Instance Method Summary collapse

Instance Method Details

#api_base ⇒ Object

Raises:

  • (NotImplementedError)


12
# File 'lib/translation_diff/http_provider.rb', line 12

def api_base = raise NotImplementedError, "#{self.class} must implement #api_base"

#connection ⇒ Object



30
# File 'lib/translation_diff/http_provider.rb', line 30

def connection = @connection ||= build_connection

#headers ⇒ Object



13
# File 'lib/translation_diff/http_provider.rb', line 13

def headers = {}

#parse_translate_response(_body, _headers, _request) ⇒ Object

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/translation_diff/http_provider.rb', line 21

def parse_translate_response(_body, _headers, _request)
  raise NotImplementedError, "#{self.class} must implement #parse_translate_response"
end

#render_translate_payload(_request) ⇒ Object

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/translation_diff/http_provider.rb', line 17

def render_translate_payload(_request)
  raise NotImplementedError, "#{self.class} must implement #render_translate_payload"
end

#translate(request) ⇒ Object



25
26
27
28
# File 'lib/translation_diff/http_provider.rb', line 25

def translate(request)
  response = post(translate_url, render_translate_payload(request))
  parse_translate_response(response.body, response.headers, request)
end

#translate_url ⇒ Object

Raises:

  • (NotImplementedError)


15
# File 'lib/translation_diff/http_provider.rb', line 15

def translate_url = raise NotImplementedError, "#{self.class} must implement #translate_url"