zooming-proxy 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/lib/zooming-proxy/middleware.rb +32 -23
- data/lib/zooming-proxy/version.rb +1 -1
- data/zooming-proxy.gemspec +2 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aec5a165d48e311fb815794e281f8598ad51035
|
4
|
+
data.tar.gz: 89cd684060e0cd20a72584981f0ffc1f22935bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e24978b2333fe58ef3dfe5685394d3870b2d87cd05023375190e7feb6921cc0dc41acc0aaf06bc2b38e6c91a419ec630d8ddb37c8f6373a38a84acecf05341a1
|
7
|
+
data.tar.gz: befdb7b2aa145c69033d98c86cd0ad33349f483158f8677fb148121b471cabdb250a4fe7adbd6b4d6aadfb6317a998d8c0d98718f832ffd218dcc36b9aa4f20b
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'json'
|
4
|
+
require 'typhoeus'
|
5
|
+
|
6
|
+
Typhoeus::Config.memoize = true
|
4
7
|
|
5
8
|
module ZoomingProxy
|
6
9
|
# Middleware
|
@@ -59,25 +62,33 @@ module ZoomingProxy
|
|
59
62
|
|
60
63
|
body['_embedded'] ||= {}
|
61
64
|
headers['X-HAL-Zooming'] = depth
|
65
|
+
body = parallel_zooms(body, headers, depth)
|
62
66
|
|
63
|
-
requested_links(body, headers).each { |link| body = zoom_rel(headers, body, depth, link) }
|
64
67
|
zoomed_response(status, headers, body, depth)
|
65
68
|
end
|
66
69
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
70
|
+
def parallel_zooms(body, headers, depth)
|
71
|
+
hydra = Typhoeus::Hydra.new
|
72
|
+
requested_links(body, headers).map do |url, attributes|
|
73
|
+
request = request_rel(url, headers)
|
74
|
+
request.on_complete do |res|
|
75
|
+
body = zoom_rel(attributes[:relation], res, body, attributes[:array], depth)
|
76
|
+
end
|
77
|
+
hydra.queue(request)
|
78
|
+
end
|
79
|
+
hydra.run
|
70
80
|
|
71
|
-
|
72
|
-
|
73
|
-
embedded_body = handle_nested_embeds(res, depth)
|
81
|
+
body
|
82
|
+
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
84
|
+
def zoom_rel(relation, response, body, array, depth)
|
85
|
+
embedded_body = handle_nested_embeds(response, depth)
|
86
|
+
|
87
|
+
if array
|
88
|
+
body['_embedded'][relation] ||= []
|
89
|
+
body['_embedded'][relation] << embedded_body
|
90
|
+
else
|
91
|
+
body['_embedded'][relation] = embedded_body
|
81
92
|
end
|
82
93
|
|
83
94
|
body
|
@@ -88,7 +99,7 @@ module ZoomingProxy
|
|
88
99
|
uri.scheme = scheme
|
89
100
|
uri.host = host
|
90
101
|
|
91
|
-
Typhoeus.
|
102
|
+
Typhoeus::Request.new(uri, headers: headers)
|
92
103
|
end
|
93
104
|
|
94
105
|
def response_to_hash(response)
|
@@ -126,16 +137,14 @@ module ZoomingProxy
|
|
126
137
|
end
|
127
138
|
|
128
139
|
def requested_links(body, headers)
|
129
|
-
|
130
|
-
|
131
|
-
|
140
|
+
body['_links']
|
141
|
+
.to_h
|
142
|
+
.select { |k, _| headers['x-hal-zoom'].split(/\s+/).include?(k) }
|
143
|
+
.each_with_object({}) do |(k, v), urls|
|
144
|
+
array = v.respond_to?(:to_ary)
|
132
145
|
|
133
|
-
|
134
|
-
|
135
|
-
end
|
136
|
-
|
137
|
-
def requested_zooms(headers)
|
138
|
-
headers['x-hal-zoom'].split(/\s+/)
|
146
|
+
[v].flatten.each { |url| urls[url['href']] = { relation: k, array: array } }
|
147
|
+
end
|
139
148
|
end
|
140
149
|
end
|
141
150
|
end
|
data/zooming-proxy.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0")
|
19
19
|
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
20
|
|
21
|
+
spec.add_dependency 'typhoeus', '~> 1.0.2'
|
22
|
+
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
22
24
|
spec.add_development_dependency 'cucumber', '~> 2.4'
|
23
25
|
spec.add_development_dependency 'cucumber-blendle-steps', '~> 0.8'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zooming-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blendle developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.2
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|