Class: I18n::Backend::Jargon::EtagHttpClient
- Inherits:
-
Object
- Object
- I18n::Backend::Jargon::EtagHttpClient
- Defined in:
- lib/i18n/backend/jargon/etag_http_client.rb
Instance Method Summary collapse
- #download(path) ⇒ Object
-
#initialize(options) ⇒ EtagHttpClient
constructor
A new instance of EtagHttpClient.
Constructor Details
#initialize(options) ⇒ EtagHttpClient
Returns a new instance of EtagHttpClient.
7 8 9 10 |
# File 'lib/i18n/backend/jargon/etag_http_client.rb', line 7 def initialize() @options = @etags = {} end |
Instance Method Details
#download(path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/i18n/backend/jargon/etag_http_client.rb', line 12 def download(path) @client ||= Faraday.new(@options[:host]) response = @client.get(path) do |request| request.headers["If-None-Match"] = @etags[path] if @etags[path] request.headers["Accept"] = 'application/json' request.[:timeout] = @options[:http_read_timeout] request.[:open_timeout] = @options[:http_open_timeout] end @etags[path] = response['ETag'] case response.status when 200 then yield response.body when 304 else raise "Failed request: #{response.inspect}" end end |