i18n-backend-http 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/i18n/backend/http/etag_http_client.rb +34 -4
- data/lib/i18n/backend/http/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8ea78a7b0a0e7dfdccc20ca06d46666f58af4db
|
4
|
+
data.tar.gz: c799bc4abac23b88bc5528fb6d583c7d54e0c5ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e5fa2fbeea4b8fc93edaa301cee223f62cc281124f1ff20adc1338a9371da95461034f5519627a54ba8e99af09241b7e8c06e6f7f8f4405a5788dec70b2d6e1
|
7
|
+
data.tar.gz: 7584730604387ed2f9fce284cce34edf7f389b1940d13c5085166546cb678221244eb3f27f2e44d554856f45c9a616c9557faea705e58ea98ca6d8da13e02395
|
@@ -4,26 +4,56 @@ module I18n
|
|
4
4
|
module Backend
|
5
5
|
class Http
|
6
6
|
class I18n::Backend::Http::EtagHttpClient
|
7
|
+
STATS_NAMESPACE = 'i18n-backend-http.etag_client'.freeze
|
8
|
+
|
7
9
|
def initialize(options)
|
8
10
|
@options = options
|
9
11
|
end
|
10
12
|
|
11
13
|
def download(path, etag:)
|
12
14
|
@client ||= Faraday.new(@options[:host])
|
15
|
+
start = Time.now
|
16
|
+
|
13
17
|
response = @client.get(path) do |request|
|
14
18
|
request.headers.merge!(@options[:headers]) if @options[:headers]
|
15
19
|
request.headers["If-None-Match"] = etag if etag
|
16
|
-
request.options[:timeout]
|
17
|
-
request.options[:open_timeout]
|
20
|
+
request.options[:timeout] = @options[:http_read_timeout]
|
21
|
+
request.options[:open_timeout] = @options[:http_open_timeout]
|
18
22
|
end
|
19
23
|
|
24
|
+
tags = {status_code: response.status, path: path}
|
25
|
+
|
26
|
+
record :timing, time: (Time.now - start).to_f * 1000, tags: tags
|
27
|
+
|
20
28
|
case response.status
|
21
|
-
when 200
|
22
|
-
|
29
|
+
when 200
|
30
|
+
record :success, tags: tags
|
31
|
+
[response.body, response['ETag']]
|
32
|
+
when 304
|
33
|
+
record :success, tags: tags
|
34
|
+
nil
|
23
35
|
else
|
36
|
+
record :failure, tags: tags
|
24
37
|
raise "Failed request: #{response.inspect}"
|
25
38
|
end
|
26
39
|
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def record(event, options = {})
|
44
|
+
return unless client = @options[:statsd_client]
|
45
|
+
|
46
|
+
case event
|
47
|
+
when :success
|
48
|
+
client.increment("#{STATS_NAMESPACE}.success", tags: options[:tags])
|
49
|
+
when :failure
|
50
|
+
client.increment("#{STATS_NAMESPACE}.failure", tags: options[:tags])
|
51
|
+
when :timing
|
52
|
+
client.histogram("#{STATS_NAMESPACE}.request_time", options[:time], tags: options[:tags])
|
53
|
+
else
|
54
|
+
raise "Unknown statsd event type to record"
|
55
|
+
end
|
56
|
+
end
|
27
57
|
end
|
28
58
|
end
|
29
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-backend-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|