api_sim 2.1.0 → 2.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd554e16bbe5055b506c8e28f4814c0ab4e7564
4
- data.tar.gz: 51d4902aa0edb9baa20298de22dd2d74c8cb0019
3
+ metadata.gz: cbfb4f82a254fc887ef63f48e4c3a04733dcae00
4
+ data.tar.gz: b23ca755915f2cfe063cd7c45fae8af53d5c0455
5
5
  SHA512:
6
- metadata.gz: 1a9f751befa266f6f27ad29ea890598a0c643091f5b10b8b06990a139b485253e6308458fba159493c019f24f7e1d2d7dd0a0a3f0ffeb11ddc87e2794f76cff9
7
- data.tar.gz: 874aed368cbf48020122094b886ab0941d988f33131237cc35c443be3088e36fa2a7440f4ece2132cb06e1371a71b5d46297ffb4aa8dd10c2159858cb38cedc3
6
+ metadata.gz: f2867efebd7de8faf3a1f9427f9125d8be5c75e07e51183e218c13d7fd71de933972190e18d565600da81daf31d00f507c52d932f50ffb5eee180d8deb63c6e8
7
+ data.tar.gz: b174edc0615398d14e777e4e23fd53080712adecf11bb98067ab0b10085237c2f1ed93970d9aaa771581811a8be96102b89702e8f50bdfb8764682367e8c13fd
@@ -69,8 +69,13 @@ module ApiSim
69
69
  ''
70
70
  end
71
71
 
72
- get '/requests/:endpoint_name' do
73
- endpoint = self.class.endpoints.select{ |endpoint| endpoint.route == "/#{params[:endpoint_name]}" }.first || halt(404)
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
@@ -1,3 +1,3 @@
1
1
  module ApiSim
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
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.1.0
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-08-29 00:00:00.000000000 Z
11
+ date: 2016-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra