api_sim 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/api_sim/built_app.rb +31 -2
- data/lib/api_sim/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbfb4f82a254fc887ef63f48e4c3a04733dcae00
|
4
|
+
data.tar.gz: b23ca755915f2cfe063cd7c45fae8af53d5c0455
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2867efebd7de8faf3a1f9427f9125d8be5c75e07e51183e218c13d7fd71de933972190e18d565600da81daf31d00f507c52d932f50ffb5eee180d8deb63c6e8
|
7
|
+
data.tar.gz: b174edc0615398d14e777e4e23fd53080712adecf11bb98067ab0b10085237c2f1ed93970d9aaa771581811a8be96102b89702e8f50bdfb8764682367e8c13fd
|
data/lib/api_sim/built_app.rb
CHANGED
@@ -69,8 +69,13 @@ module ApiSim
|
|
69
69
|
''
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
|
73
|
+
get '/requests/*' do
|
74
|
+
endpoint_name = parse_endpoint_from_request(request) || halt(404)
|
75
|
+
http_method = params.fetch('method', 'GET')
|
76
|
+
endpoint = find_matching_endpoint(endpoint_name, http_method)
|
77
|
+
|
78
|
+
halt(404) unless endpoint
|
74
79
|
endpoint.requests.to_json
|
75
80
|
end
|
76
81
|
|
@@ -84,6 +89,25 @@ module ApiSim
|
|
84
89
|
|
85
90
|
private
|
86
91
|
|
92
|
+
def find_matching_endpoint(endpoint_name, http_method)
|
93
|
+
matching_endpoints = active_endpoints.select do |endpoint|
|
94
|
+
endpoint.route == "/#{endpoint_name}"
|
95
|
+
end
|
96
|
+
|
97
|
+
case matching_endpoints.size
|
98
|
+
when 0
|
99
|
+
nil
|
100
|
+
when 1
|
101
|
+
matching_endpoints.first
|
102
|
+
else
|
103
|
+
matching_endpoints.find { |endpoint| endpoint.http_method =~ /#{http_method}/i }
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def active_endpoints
|
108
|
+
self.class.endpoints.reject(&:overridden?)
|
109
|
+
end
|
110
|
+
|
87
111
|
def create_matcher_override(request)
|
88
112
|
old_matcher = matcher(request)
|
89
113
|
config = matcher_overrides(old_matcher.response(request))
|
@@ -146,5 +170,10 @@ module ApiSim
|
|
146
170
|
|
147
171
|
@response_body.empty? ? {} : @response_body
|
148
172
|
end
|
173
|
+
|
174
|
+
def parse_endpoint_from_request(request)
|
175
|
+
path_matcher = request.path.match(/\/requests\/([\w\/_-]*)/)
|
176
|
+
path_matcher.size == 2 ? path_matcher[1] : nil
|
177
|
+
end
|
149
178
|
end
|
150
179
|
end
|
data/lib/api_sim/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_sim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Taylor
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|