api_sim 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pairs +6 -0
- data/lib/api_sim/built_app.rb +6 -1
- data/lib/api_sim/helpers/view_helpers.rb +12 -0
- data/lib/api_sim/matchers/base_matcher.rb +2 -1
- data/lib/api_sim/matchers/static_request_matcher.rb +0 -9
- data/lib/api_sim/recorded_request.rb +3 -2
- data/lib/api_sim/version.rb +1 -1
- data/lib/api_sim/views/index.html.erb +22 -20
- data/lib/api_sim/views/requests/index.html.erb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68730144a320ff78fd1a860b3b2f2f1adc36b662
|
4
|
+
data.tar.gz: 2e5cf3747afbb3995bf96d60a3662ff294239c11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24e685f735efbf7fb56c9d1b81375ba464ee8e5ba0eca75b92f918c6af1fc4453a4d8599e1f6796dd0631c05568096b47bb52ece8f9df0794484c4130b16f92a
|
7
|
+
data.tar.gz: 08c7bb5aca6d50e4ae6fed9b806225cfa81f52ae495c13faff02d89efed2cd5a82b74480dd10b560deb23e00c562f7bd96728570993b5d2b649bc3726640aa4e
|
data/.pairs
ADDED
data/lib/api_sim/built_app.rb
CHANGED
@@ -49,7 +49,7 @@ module ApiSim
|
|
49
49
|
end
|
50
50
|
|
51
51
|
delete '/ui/response/:method/*' do
|
52
|
-
all_matching_matchers = matchers(
|
52
|
+
all_matching_matchers = matchers(mimicked_request)
|
53
53
|
all_matching_matchers.each &:reset!
|
54
54
|
non_default_matchers = all_matching_matchers.reject(&:default)
|
55
55
|
self.class.endpoints.delete_if { |endpoint| non_default_matchers.include?(endpoint) }
|
@@ -69,6 +69,11 @@ 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)
|
74
|
+
endpoint.requests.to_json
|
75
|
+
end
|
76
|
+
|
72
77
|
%i(get post put patch delete).each do |http_method|
|
73
78
|
public_send(http_method, '/*') do
|
74
79
|
endpoint = matcher(request)
|
@@ -19,6 +19,7 @@ module ApiSim
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def reset!
|
22
|
+
@requests = []
|
22
23
|
@overridden = false
|
23
24
|
end
|
24
25
|
|
@@ -36,7 +37,7 @@ module ApiSim
|
|
36
37
|
|
37
38
|
def record_request(request)
|
38
39
|
request.body.rewind
|
39
|
-
requests.push(RecordedRequest.new(body: request.body.read, request_env: request.env))
|
40
|
+
requests.push(RecordedRequest.new(body: request.body.read, request_env: request.env, request_path: request.path))
|
40
41
|
end
|
41
42
|
|
42
43
|
def to_s
|
@@ -33,10 +33,6 @@ module ApiSim
|
|
33
33
|
!!@overridden
|
34
34
|
end
|
35
35
|
|
36
|
-
def reset!
|
37
|
-
@overridden = false
|
38
|
-
end
|
39
|
-
|
40
36
|
def requests
|
41
37
|
@requests ||= []
|
42
38
|
end
|
@@ -47,11 +43,6 @@ module ApiSim
|
|
47
43
|
DOC
|
48
44
|
end
|
49
45
|
|
50
|
-
def record_request(request)
|
51
|
-
request.body.rewind
|
52
|
-
requests.push(RecordedRequest.new(body: request.body.read, request_env: request.env))
|
53
|
-
end
|
54
|
-
|
55
46
|
def matches_dynamic_path?(request)
|
56
47
|
route_tokens = route.split('/')
|
57
48
|
request_tokens = request.path.split('/')
|
@@ -1,11 +1,12 @@
|
|
1
1
|
module ApiSim
|
2
2
|
class RecordedRequest
|
3
|
-
attr_reader :time, :headers, :body
|
3
|
+
attr_reader :time, :headers, :body, :path
|
4
4
|
|
5
|
-
def initialize(time: Time.now, body:, request_env:)
|
5
|
+
def initialize(time: Time.now, body:, request_env:, request_path:)
|
6
6
|
@time = time
|
7
7
|
@body = body
|
8
8
|
@headers = parse_headers_from(request_env)
|
9
|
+
@path = request_path
|
9
10
|
end
|
10
11
|
|
11
12
|
private
|
data/lib/api_sim/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<% require_relative '../helpers/view_helpers' %>
|
1
2
|
<h2>Simulators</h2>
|
2
3
|
<table>
|
3
4
|
<thead>
|
@@ -11,26 +12,27 @@
|
|
11
12
|
</thead>
|
12
13
|
<tbody>
|
13
14
|
<% endpoints.each do |endpoint| %>
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
</
|
32
|
-
</
|
33
|
-
</
|
15
|
+
<tr>
|
16
|
+
<td><%= endpoint.http_method %> <%= endpoint.route %> <%= custom_matcher?(endpoint) %></td>
|
17
|
+
<td><%= ViewHelpers.endpoint_match endpoint %></td>
|
18
|
+
<td>
|
19
|
+
<% if endpoint.readonly? %>
|
20
|
+
Cannot edit dynamic endpoints
|
21
|
+
<% else %>
|
22
|
+
<%= link_to_response_edit endpoint %>
|
23
|
+
<% end %>
|
24
|
+
</td>
|
25
|
+
<td>
|
26
|
+
<%= link_to_read_requests endpoint %>
|
27
|
+
</td>
|
28
|
+
<td>
|
29
|
+
<form action="/ui/response/<%= endpoint.http_method %><%= endpoint.route %>" method="post">
|
30
|
+
<input type="hidden" value="delete" name="_method">
|
31
|
+
<input type="hidden" value="<%= ViewHelpers.endpoint_match endpoint %>" name="match">
|
32
|
+
<button class='btn-link' type="submit">Reset</button>
|
33
|
+
</form>
|
34
|
+
</td>
|
35
|
+
</tr>
|
34
36
|
<% end %>
|
35
37
|
</tbody>
|
36
38
|
</table>
|
@@ -7,6 +7,7 @@
|
|
7
7
|
<tr>
|
8
8
|
<th>Time</th>
|
9
9
|
<th>Body</th>
|
10
|
+
<th>Route</th>
|
10
11
|
<th>Headers</th>
|
11
12
|
</tr>
|
12
13
|
</thead>
|
@@ -15,6 +16,7 @@
|
|
15
16
|
<tr>
|
16
17
|
<th class="header-column"><p><%= request.time %></p></th>
|
17
18
|
<td><p><%= h request.body %></p></td>
|
19
|
+
<td><p><%= h request.path %></p></td>
|
18
20
|
<td>
|
19
21
|
<ul>
|
20
22
|
<% request.headers.each do |header, value| %>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_sim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Taylor
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
|
+
- ".pairs"
|
119
120
|
- ".rspec"
|
120
121
|
- ".travis.yml"
|
121
122
|
- Gemfile
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- lib/api_sim.rb
|
130
131
|
- lib/api_sim/app_builder.rb
|
131
132
|
- lib/api_sim/built_app.rb
|
133
|
+
- lib/api_sim/helpers/view_helpers.rb
|
132
134
|
- lib/api_sim/matchers.rb
|
133
135
|
- lib/api_sim/matchers/base_matcher.rb
|
134
136
|
- lib/api_sim/matchers/dynamic_request_matcher.rb
|
@@ -164,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
166
|
version: '0'
|
165
167
|
requirements: []
|
166
168
|
rubyforge_project:
|
167
|
-
rubygems_version: 2.5.
|
169
|
+
rubygems_version: 2.5.1
|
168
170
|
signing_key:
|
169
171
|
specification_version: 4
|
170
172
|
summary: A DSL on top of sinatra for building application simulators
|