api_valve 0.3.1 → 0.4.0
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/README.md +6 -1
- data/lib/api_valve/forwarder.rb +19 -17
- data/lib/api_valve/proxy.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1446c98734c8db7a8a802108b6f76e76792efe515bb17a9c84d5679a14645f
|
4
|
+
data.tar.gz: 43c13f7b3186fe752639e46bfacf73943fa5bd1b624ebc49e70d14c40cf0b132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2a55f91363b04866c0db5589ee6536965ad1c28e8dbe2584e83bd3ac306116de2f78ec85ccf96ac342c75490f5fbe01c111012ba1c2b826a3bae9543c45873
|
7
|
+
data.tar.gz: 84b94d9afd865a79aacf15f1cf2fbf0cb019a5c9406299b8c56701b97902443e3b40d10cdaa761d33fb4e6f1f12fbd1d02de38ddfef15da0b464f7a0280c51a0
|
data/README.md
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
# ApiValve
|
2
2
|
|
3
|
+
[](https://badge.fury.io/rb/fidor_api)
|
4
|
+
[](https://travis-ci.org/mkon/api_valve)
|
5
|
+
|
3
6
|
Extensible rack application that serves as lightweight API reverse proxy.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
7
|
-
Just add the gem
|
10
|
+
Just add the gem to your `Gemfile`
|
8
11
|
|
9
12
|
```ruby
|
10
13
|
gem 'api_valve'
|
11
14
|
```
|
12
15
|
|
16
|
+
## Usage
|
17
|
+
|
13
18
|
See the [examples](https://github.com/mkon/api_valve/tree/master/examples) section on how to
|
14
19
|
create & configure your own proxy using this gem.
|
data/lib/api_valve/forwarder.rb
CHANGED
@@ -24,22 +24,29 @@ module ApiValve
|
|
24
24
|
# Instanciates the Request and Response classes and wraps them arround the original
|
25
25
|
# request and response.
|
26
26
|
def call(original_request, local_options = {})
|
27
|
-
request =
|
27
|
+
request = build_request(original_request, request_options.deep_merge(local_options))
|
28
28
|
request.check_permissions!
|
29
|
-
|
30
|
-
|
31
|
-
run_request(request),
|
32
|
-
response_options.merge(
|
33
|
-
target_prefix: @target_prefix,
|
34
|
-
local_prefix: original_request.env['SCRIPT_NAME']
|
35
|
-
)
|
36
|
-
).rack_response
|
29
|
+
response = build_response(original_request, run_request(request), response_options)
|
30
|
+
response.rack_response
|
37
31
|
end
|
38
32
|
|
39
33
|
private
|
40
34
|
|
41
|
-
def
|
42
|
-
|
35
|
+
def build_request(original_request, options)
|
36
|
+
klass = options[:klass] || Request
|
37
|
+
klass.new(original_request, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_response(original_request, original_response, options)
|
41
|
+
klass = options[:klass] || Response
|
42
|
+
klass.new(
|
43
|
+
original_request,
|
44
|
+
original_response,
|
45
|
+
options.merge(
|
46
|
+
target_prefix: @target_prefix,
|
47
|
+
local_prefix: original_request.env['SCRIPT_NAME']
|
48
|
+
)
|
49
|
+
)
|
43
50
|
end
|
44
51
|
|
45
52
|
def request_options
|
@@ -47,14 +54,9 @@ module ApiValve
|
|
47
54
|
(@options[:request] || {}).merge(@options.slice(:permission_handler))
|
48
55
|
end
|
49
56
|
|
50
|
-
def response_klass
|
51
|
-
response_options[:klass] || Response
|
52
|
-
end
|
53
|
-
|
54
57
|
def response_options
|
55
58
|
# integrate permission handler options as it is instantiated in the response
|
56
|
-
(@options[:response] || {})
|
57
|
-
.merge(@options.slice(:permission_handler) || {})
|
59
|
+
(@options[:response] || {}).merge(@options.slice(:permission_handler) || {})
|
58
60
|
end
|
59
61
|
|
60
62
|
def run_request(request)
|
data/lib/api_valve/proxy.rb
CHANGED
@@ -12,6 +12,12 @@ module ApiValve
|
|
12
12
|
define_callbacks :call
|
13
13
|
|
14
14
|
class << self
|
15
|
+
def build(config, &block)
|
16
|
+
from_hash(config).tap do |proxy|
|
17
|
+
proxy.instance_eval(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
15
21
|
def from_config(file_name = nil)
|
16
22
|
file_name ||= name.underscore
|
17
23
|
path = find_config(file_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_valve
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|