api_proxy 0.1.1 → 0.1.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/Gemfile.lock +3 -3
- data/api_proxy.gemspec +1 -1
- data/lib/api_proxy/config.rb +12 -1
- data/lib/api_proxy/middleware.rb +7 -1
- data/lib/api_proxy/request_options_builder.rb +7 -1
- data/lib/api_proxy/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 850e6c12b86a5c88c752864553bb26b391498f148d21640c6134db2df615e369
|
4
|
+
data.tar.gz: a2913cb8b94b47f6deea174faa8b96a802c1bff42dd5c6771a878df198ce82a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6888a33aa5ca0ccfa834995e8f4f408da2c930da243abc53c757c4660a144fa0e038c9c334634ddbcd14768f012f82d0134fdf8d8b919928a1cd87350fc0d73
|
7
|
+
data.tar.gz: 69b9061cdb5939387c348b71c8986813b752c684e46a2b83481f8f20b4a322f2c1e734dc701be44bf01086c98d0ba5ce3500834910bee4acb916500b1d17f0c1
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api_proxy (0.1.
|
4
|
+
api_proxy (0.1.2)
|
5
5
|
api_signature (~> 0.1.2)
|
6
|
-
httparty (
|
6
|
+
httparty (>= 0.15)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
@@ -57,7 +57,7 @@ GEM
|
|
57
57
|
guard-compat (~> 1.1)
|
58
58
|
rspec (>= 2.99.0, < 4.0)
|
59
59
|
hashdiff (0.3.7)
|
60
|
-
httparty (0.
|
60
|
+
httparty (0.16.2)
|
61
61
|
multi_xml (>= 0.5.2)
|
62
62
|
i18n (1.0.1)
|
63
63
|
concurrent-ruby (~> 1.0)
|
data/api_proxy.gemspec
CHANGED
data/lib/api_proxy/config.rb
CHANGED
@@ -2,7 +2,15 @@
|
|
2
2
|
|
3
3
|
module ApiProxy
|
4
4
|
class Config
|
5
|
-
attr_accessor :api_key,
|
5
|
+
attr_accessor :api_key,
|
6
|
+
:api_secret,
|
7
|
+
:url_scheme,
|
8
|
+
:api_host,
|
9
|
+
:api_port,
|
10
|
+
:api_prefix,
|
11
|
+
:request_starts_with,
|
12
|
+
:request_allowed,
|
13
|
+
:custom_headers
|
6
14
|
|
7
15
|
def initialize
|
8
16
|
load_defaults
|
@@ -18,6 +26,9 @@ module ApiProxy
|
|
18
26
|
|
19
27
|
@api_prefix = '/api/v1/'
|
20
28
|
@request_starts_with = '/_ts'
|
29
|
+
|
30
|
+
@request_allowed = ->(_env) { true }
|
31
|
+
@custom_headers = ->(_env) { {} }
|
21
32
|
end
|
22
33
|
end
|
23
34
|
end
|
data/lib/api_proxy/middleware.rb
CHANGED
@@ -8,7 +8,7 @@ module ApiProxy
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
return @app.call(env) unless
|
11
|
+
return @app.call(env) unless allow_request?(env)
|
12
12
|
|
13
13
|
builder = RequestOptionsBuilder.new(env, @config)
|
14
14
|
request = ApiProxy::Request.new(builder)
|
@@ -17,5 +17,11 @@ module ApiProxy
|
|
17
17
|
|
18
18
|
Rack::Response.new(response.to_s, response.code, request.headers)
|
19
19
|
end
|
20
|
+
|
21
|
+
def allow_request?(env)
|
22
|
+
return false unless env['REQUEST_PATH'].start_with?(@config.request_starts_with)
|
23
|
+
|
24
|
+
@config.request_allowed.call(env)
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
@@ -20,7 +20,7 @@ module ApiProxy
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def options
|
23
|
-
{ headers:
|
23
|
+
{ headers: headers, format: :json }
|
24
24
|
end
|
25
25
|
|
26
26
|
def url
|
@@ -33,6 +33,12 @@ module ApiProxy
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
def headers
|
37
|
+
custom_headers = config.custom_headers.call(env)
|
38
|
+
|
39
|
+
signature_builder.headers.merge(custom_headers)
|
40
|
+
end
|
41
|
+
|
36
42
|
def signature_builder
|
37
43
|
@signature_builder ||= ApiSignature::Builder.new(request_params)
|
38
44
|
end
|
data/lib/api_proxy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Malinovskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,16 +166,16 @@ dependencies:
|
|
166
166
|
name: httparty
|
167
167
|
requirement: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
|
-
- - "
|
169
|
+
- - ">="
|
170
170
|
- !ruby/object:Gem::Version
|
171
|
-
version: 0.15
|
171
|
+
version: '0.15'
|
172
172
|
type: :runtime
|
173
173
|
prerelease: false
|
174
174
|
version_requirements: !ruby/object:Gem::Requirement
|
175
175
|
requirements:
|
176
|
-
- - "
|
176
|
+
- - ">="
|
177
177
|
- !ruby/object:Gem::Version
|
178
|
-
version: 0.15
|
178
|
+
version: '0.15'
|
179
179
|
description:
|
180
180
|
email:
|
181
181
|
- igor.malinovskiy@netfixllc.org
|