api_valve 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e02e6ea22e34fe53e6b776abc3844b1581ea0ca12eade5f6ee5f857a6bb779d
4
- data.tar.gz: 846954dd57564d157906ca5956a9ec43fa9ad9ecc750aac4dcddcb536c7ad9d1
3
+ metadata.gz: ca1446c98734c8db7a8a802108b6f76e76792efe515bb17a9c84d5679a14645f
4
+ data.tar.gz: 43c13f7b3186fe752639e46bfacf73943fa5bd1b624ebc49e70d14c40cf0b132
5
5
  SHA512:
6
- metadata.gz: ff191c95817ae0d9e335131afe42a5163224c69400e055596ff419f9d93404c0e82da26fe296ddc1d2fe4adb49d79bd8541e0108a16a0e87a13a9d710ee84cc5
7
- data.tar.gz: c8436b6a7402b1fab1831a38f2b1662d6eddcfefe46b44a5e487b0c8d382174eaea88fea153eda252a1c89655d3f8ade2be0b92a906359b573588a12b44649fc
6
+ metadata.gz: bc2a55f91363b04866c0db5589ee6536965ad1c28e8dbe2584e83bd3ac306116de2f78ec85ccf96ac342c75490f5fbe01c111012ba1c2b826a3bae9543c45873
7
+ data.tar.gz: 84b94d9afd865a79aacf15f1cf2fbf0cb019a5c9406299b8c56701b97902443e3b40d10cdaa761d33fb4e6f1f12fbd1d02de38ddfef15da0b464f7a0280c51a0
data/README.md CHANGED
@@ -1,14 +1,19 @@
1
1
  # ApiValve
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/fidor_api.svg)](https://badge.fury.io/rb/fidor_api)
4
+ [![Build Status](https://travis-ci.org/mkon/api_valve.svg?branch=master)](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.
@@ -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 = request_klass.new(original_request, request_options.deep_merge(local_options))
27
+ request = build_request(original_request, request_options.deep_merge(local_options))
28
28
  request.check_permissions!
29
- response_klass.new(
30
- original_request,
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 request_klass
42
- request_options[:klass] || Request
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)
@@ -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.3.1
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-09-19 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport