api_sim 1.1.0 → 1.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: 3b15c7a6cedd1f3b8c3544986dce19a917911ea9
4
- data.tar.gz: daaac2cab53393e6ade881e389108d1ff3e15540
3
+ metadata.gz: 68730144a320ff78fd1a860b3b2f2f1adc36b662
4
+ data.tar.gz: 2e5cf3747afbb3995bf96d60a3662ff294239c11
5
5
  SHA512:
6
- metadata.gz: 3177ab13b83c0dd6a952a42d8cd9c863e87ac1f235e5c03fbf79788e9c2b1905824e2bf133b5b89e7220e9640a2bada03e8c767cfa4c899d48a73418eb0fd684
7
- data.tar.gz: f0310976ccd8c1a41e7754034d77083caff7b3b139a441a7516c03a4f1c32abb430fff2e59d1a36acdd7dd9901e7e6755aacf2baa2d2096d7154d99f741f4351
6
+ metadata.gz: 24e685f735efbf7fb56c9d1b81375ba464ee8e5ba0eca75b92f918c6af1fc4453a4d8599e1f6796dd0631c05568096b47bb52ece8f9df0794484c4130b16f92a
7
+ data.tar.gz: 08c7bb5aca6d50e4ae6fed9b806225cfa81f52ae495c13faff02d89efed2cd5a82b74480dd10b560deb23e00c562f7bd96728570993b5d2b649bc3726640aa4e
data/.pairs ADDED
@@ -0,0 +1,6 @@
1
+ pairs:
2
+ mk: Mark Kollasch; mkollasch
3
+ md: Mark Douglass; mdouglass
4
+ email:
5
+ prefix: pair
6
+ domain: pivotal.io
@@ -49,7 +49,7 @@ module ApiSim
49
49
  end
50
50
 
51
51
  delete '/ui/response/:method/*' do
52
- all_matching_matchers = matchers(faux_request(http_method, route, request.body))
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)
@@ -0,0 +1,12 @@
1
+ module ViewHelpers
2
+
3
+ def self.endpoint_match (endpoint)
4
+ if endpoint.match_on_body? then
5
+ "/#{endpoint.matcher.source}/"
6
+ else
7
+ ''
8
+ end
9
+ end
10
+
11
+ end
12
+
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ApiSim
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -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
- <tr>
15
- <td><%= endpoint.http_method %> <%= endpoint.route %> <%= custom_matcher?(endpoint) %></td>
16
- <td><%= endpoint.match_on_body? ? "/#{endpoint.matcher.source}/" : '' %></td>
17
- <td>
18
- <% if endpoint.readonly? %>
19
- Cannot edit dynamic endpoints
20
- <% else %>
21
- <%= link_to_response_edit endpoint %>
22
- <% end %>
23
- </td>
24
- <td>
25
- <%= link_to_read_requests endpoint %>
26
- </td>
27
- <td>
28
- <form action="/ui/response/<%= endpoint.http_method %><%= endpoint.route %>" method="post">
29
- <input type="hidden" value="delete" name="_method">
30
- <button class='btn-link' type="submit">Reset</button>
31
- </form>
32
- </td>
33
- </tr>
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.1.0
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.0
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