attune 1.0.8 → 1.0.9
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/attune/default.rb +2 -2
- data/lib/attune/gzip.rb +62 -0
- data/lib/attune/json_logger.rb +0 -1
- data/lib/attune/version.rb +1 -1
- metadata +3 -4
- data/lib/attune/gzip_request.rb +0 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33e278960925d8b1aeb5e7575b66a575299e6323
|
4
|
+
data.tar.gz: 614890038d5ff2ab7ad3d21517c08fa6bea7df01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1be52d8cb15c9822985205f2824997e2de1c5e60e00e192d54deaa7243568205f894acc8880f6f9598d9b57b2746f70bf158023518b79d2d11a136e0f33083fc
|
7
|
+
data.tar.gz: 6b60a69e5a43cd521fafe45a5dda7cedcd55fb468ea891a54f37a63bd9ec3dc3de0f34813a4a6f1eccea6e2fcf0830be8cfeea97dad09d7a4e95786e4d6a7e65
|
data/lib/attune/default.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'attune/param_flattener'
|
2
2
|
require "attune/call_dropping"
|
3
3
|
require "attune/json_logger"
|
4
|
-
require "attune/
|
4
|
+
require "attune/gzip"
|
5
5
|
require "attune/net_http_persistent"
|
6
6
|
|
7
7
|
module Attune
|
@@ -30,7 +30,7 @@ module Attune
|
|
30
30
|
builder.use Attune::JsonLogger
|
31
31
|
|
32
32
|
# Gzip requests, Faraday handles responses automatically
|
33
|
-
builder.use Attune::
|
33
|
+
builder.use Attune::Gzip
|
34
34
|
|
35
35
|
# Raise exceptions for HTTP 4xx/5xx
|
36
36
|
builder.response :raise_error
|
data/lib/attune/gzip.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Attune
|
2
|
+
# Some code taken from a yet to be released version of faraday-middleware
|
3
|
+
class Gzip < Faraday::Middleware
|
4
|
+
dependency 'zlib'
|
5
|
+
|
6
|
+
CONTENT_TYPE = 'Content-Type'.freeze
|
7
|
+
CONTENT_ENCODING = 'Content-Encoding'.freeze
|
8
|
+
MIME_TYPE = 'application/json'.freeze
|
9
|
+
ENCODING_TYPE = 'gzip'.freeze
|
10
|
+
ACCEPT_ENCODING = 'Accept-Encoding'.freeze
|
11
|
+
CONTENT_LENGTH = 'Content-Length'.freeze
|
12
|
+
SUPPORTED_ENCODINGS = 'gzip,deflate'.freeze
|
13
|
+
RUBY_ENCODING = '1.9'.respond_to?(:force_encoding)
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
if has_body?(env) && is_json?(env)
|
17
|
+
wio = StringIO.new("w")
|
18
|
+
w_gz = Zlib::GzipWriter.new(wio)
|
19
|
+
w_gz.write env[:body]
|
20
|
+
w_gz.close
|
21
|
+
env[:body] = wio.string
|
22
|
+
env[:request_headers][CONTENT_ENCODING] = ENCODING_TYPE
|
23
|
+
end
|
24
|
+
env[:request_headers][ACCEPT_ENCODING] ||= SUPPORTED_ENCODINGS
|
25
|
+
@app.call(env).on_complete do |env|
|
26
|
+
case env[:response_headers][CONTENT_ENCODING]
|
27
|
+
when 'gzip'
|
28
|
+
reset_body(env, &method(:uncompress_gzip))
|
29
|
+
when 'deflate'
|
30
|
+
reset_body(env, &method(:inflate))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def is_json?(env)
|
35
|
+
env[:request_headers][CONTENT_TYPE] == MIME_TYPE
|
36
|
+
end
|
37
|
+
def has_body?(env)
|
38
|
+
body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset_body(env)
|
42
|
+
env[:body] = yield(env[:body])
|
43
|
+
env[:response_headers].delete(CONTENT_ENCODING)
|
44
|
+
env[:response_headers][CONTENT_LENGTH] = env[:body].length
|
45
|
+
end
|
46
|
+
|
47
|
+
def uncompress_gzip(body)
|
48
|
+
io = StringIO.new(body)
|
49
|
+
gzip_reader = if RUBY_ENCODING
|
50
|
+
Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT')
|
51
|
+
else
|
52
|
+
Zlib::GzipReader.new(io)
|
53
|
+
end
|
54
|
+
gzip_reader.read
|
55
|
+
end
|
56
|
+
def inflate(body)
|
57
|
+
Zlib::Inflate.inflate(body)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
data/lib/attune/json_logger.rb
CHANGED
data/lib/attune/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attune
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Hawthorn
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -147,7 +147,7 @@ files:
|
|
147
147
|
- lib/attune/client.rb
|
148
148
|
- lib/attune/configurable.rb
|
149
149
|
- lib/attune/default.rb
|
150
|
-
- lib/attune/
|
150
|
+
- lib/attune/gzip.rb
|
151
151
|
- lib/attune/json_logger.rb
|
152
152
|
- lib/attune/mocks.rb
|
153
153
|
- lib/attune/models/anonymous_result.rb
|
@@ -201,4 +201,3 @@ test_files:
|
|
201
201
|
- spec/attune_spec.rb
|
202
202
|
- spec/remote_spec.rb
|
203
203
|
- spec/spec_helper.rb
|
204
|
-
has_rdoc:
|
data/lib/attune/gzip_request.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module Attune
|
2
|
-
class GzipRequest < Faraday::Middleware
|
3
|
-
CONTENT_TYPE = 'Content-Type'.freeze
|
4
|
-
CONTENT_ENCODING = 'Content-Encoding'.freeze
|
5
|
-
MIME_TYPE = 'application/json'.freeze
|
6
|
-
ENCODING_TYPE = 'gzip'.freeze
|
7
|
-
|
8
|
-
def call(env)
|
9
|
-
if has_body?(env) && is_json?(env)
|
10
|
-
wio = StringIO.new("w")
|
11
|
-
w_gz = Zlib::GzipWriter.new(wio)
|
12
|
-
w_gz.write env[:body]
|
13
|
-
w_gz.close
|
14
|
-
env[:body] = wio.string
|
15
|
-
env[:request_headers][CONTENT_ENCODING] = ENCODING_TYPE
|
16
|
-
end
|
17
|
-
@app.call env
|
18
|
-
end
|
19
|
-
def is_json?(env)
|
20
|
-
env[:request_headers][CONTENT_TYPE] == MIME_TYPE
|
21
|
-
end
|
22
|
-
def has_body?(env)
|
23
|
-
body = env[:body] and !(body.respond_to?(:to_str) and body.empty?)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|