api_sim 5.1.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c78fb49e9b8055b9c57b7d929f14e3ccdc550400
4
- data.tar.gz: f366b4b136aa46472c39ec18e2be8e66032e01ac
3
+ metadata.gz: d28ccc19a3eaa578a47a72156ae7506b1c0c629d
4
+ data.tar.gz: 5008b1738a71153aa9933abd54b92da4b54fab8f
5
5
  SHA512:
6
- metadata.gz: 46122772e2556bc430916fa25d89f0cdbbb864ef1d980a6644674da31f7133038ca2b3af48ca393544e0d0077c686e7f811f54cbc0a363ba16827d6bfe639490
7
- data.tar.gz: c42b0887edaed2dad8ffde3f39d6bf661607e89828041f2e6cda7729a927f55ec0374b21a6fe9761f7e01f9934b1bfb1c2c72942555be7db33e0acd592edf49a
6
+ metadata.gz: d0f04ea1e7d633fcde25d0edcd2aefe28664eb954a086b1b0a8cb01c2b22517a1ca40d903459e64cf164ef3c31c19b1b228d2ac21c55f3a0548e8e2938c11f67
7
+ data.tar.gz: 3f830c93e9579f75381dd3ee2961dcf83746b451ae53ecf44ce53d5aa32d153354484e0ee28a618ec33f3a8206329913f17cecc36b0941554a571b215c70db43
@@ -9,9 +9,15 @@ module ApiSim
9
9
  config = self
10
10
  Sinatra.new(BuiltApp) do
11
11
  endpoints config.endpoint_configurations
12
+ ui_root config.ui_root || '/ui'
12
13
  end
13
14
  end
14
15
 
16
+ def ui_root(root = nil)
17
+ @ui_root = root if root
18
+ @ui_root
19
+ end
20
+
15
21
  def configure_endpoint(http_method, route, response_body, response_code=200, headers={}, schema_string='', request_schema: nil)
16
22
  endpoint_configurations.push(
17
23
  Matchers::StaticRequestMatcher.new(
@@ -58,4 +64,4 @@ module ApiSim
58
64
  @endpoint_configurations ||= []
59
65
  end
60
66
  end
61
- end
67
+ end
@@ -2,59 +2,27 @@ require 'sinatra/base'
2
2
  require 'nokogiri'
3
3
  require 'json'
4
4
  require 'tilt/erb'
5
- require 'api_sim/view_helpers'
6
5
  require 'json-schema'
7
6
  require 'mustermann'
7
+ require 'api_sim/view_helpers'
8
+ require 'api_sim/ui_app'
8
9
 
9
10
  module ApiSim
10
11
  class BuiltApp < Sinatra::Base
11
12
  API_REQUEST_MATCHER = Mustermann.new('/requests/:method{+path}')
12
13
  use Rack::MethodOverride
13
14
 
14
- helpers do
15
- include ViewHelpers
16
- end
17
-
18
15
  def self.endpoints(endpoints = nil)
19
16
  @endpoints = endpoints if endpoints
20
17
  return @endpoints
21
18
  end
22
19
 
23
- get '/' do
24
- erb :'index.html', layout: :'layout.html'
25
- end
26
-
27
- get '/ui/response/:method/*' do
28
- @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
29
- erb :'responses/form.html', layout: :'layout.html'
30
- end
31
-
32
- get '/ui/requests/:method/*' do
33
- @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
34
-
35
- erb :'requests/index.html', layout: :'layout.html'
36
- end
37
-
38
- post '/ui/response/:method/*' do
39
- @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
40
- unless params['schema'].empty?
41
- @errors = JSON::Validator.fully_validate(JSON.parse(params['schema']), params['body'])
42
- if @errors.any?
43
- return erb :'responses/form.html', layout: :'layout.html'
44
- end
20
+ def self.ui_root(root = nil)
21
+ if root
22
+ @ui_root = root
23
+ self.register UiApp.with_root(root)
45
24
  end
46
- new_config = create_matcher_override(mimicked_request)
47
-
48
- self.class.endpoints.unshift(new_config)
49
- redirect to '/'
50
- end
51
-
52
- delete '/ui/response/:method/*' do
53
- all_matching_matchers = matchers(mimicked_request)
54
- all_matching_matchers.each &:reset!
55
- non_default_matchers = all_matching_matchers.reject(&:default)
56
- self.class.endpoints.delete_if { |endpoint| non_default_matchers.include?(endpoint) }
57
- redirect to '/'
25
+ @ui_root
58
26
  end
59
27
 
60
28
  put '/response/*' do
@@ -165,6 +133,10 @@ module ApiSim
165
133
  end
166
134
  end
167
135
 
136
+ def route
137
+ "/#{params[:splat].first}"
138
+ end
139
+
168
140
  def blank?(item)
169
141
  item.nil? || item.empty?
170
142
  end
@@ -0,0 +1,50 @@
1
+ require 'sinatra/base'
2
+ require 'api_sim/view_helpers'
3
+
4
+ module ApiSim
5
+ module UiApp
6
+ def self.with_root(root)
7
+ Module.new do
8
+ def self.registered(app)
9
+ app.helpers ViewHelpers
10
+ app.get "#{app.ui_root}" do
11
+ erb :'index.html', layout: :'layout.html'
12
+ end
13
+
14
+ app.get "#{app.ui_root}/response/:method/*" do
15
+ @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
16
+ erb :'responses/form.html', layout: :'layout.html'
17
+ end
18
+
19
+ app.get "#{app.ui_root}/requests/:method/*" do
20
+ @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
21
+
22
+ erb :'requests/index.html', layout: :'layout.html'
23
+ end
24
+
25
+ app.post "#{app.ui_root}/response/:method/*" do
26
+ @config = matcher(faux_request(method: http_method, path: route, body: faux_body, query: request.query_string))
27
+ unless params['schema'].empty?
28
+ @errors = JSON::Validator.fully_validate(JSON.parse(params['schema']), params['body'])
29
+ if @errors.any?
30
+ return erb :'responses/form.html', layout: :'layout.html'
31
+ end
32
+ end
33
+ new_config = create_matcher_override(mimicked_request)
34
+
35
+ self.class.endpoints.unshift(new_config)
36
+ redirect to app.ui_root
37
+ end
38
+
39
+ app.delete "#{app.ui_root}/response/:method/*" do
40
+ all_matching_matchers = matchers(mimicked_request)
41
+ all_matching_matchers.each &:reset!
42
+ non_default_matchers = all_matching_matchers.reject(&:default)
43
+ self.class.endpoints.delete_if {|endpoint| non_default_matchers.include?(endpoint)}
44
+ redirect to app.ui_root
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiSim
2
- VERSION = "5.1.0"
2
+ VERSION = "6.0.0"
3
3
  end
@@ -16,14 +16,10 @@ module ApiSim
16
16
  @config
17
17
  end
18
18
 
19
- def route
20
- "/#{params[:splat].first}"
21
- end
22
-
23
19
  def link_to_response_edit(endpoint)
24
20
  match = endpoint.match_on_body? ? endpoint.matcher.source : ''
25
21
  <<-HTML
26
- <a href="/ui/response/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
22
+ <a href="#{ui_root}/response/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
27
23
  #{endpoint.route}
28
24
  </a>
29
25
  HTML
@@ -36,7 +32,7 @@ module ApiSim
36
32
  def link_to_read_requests(endpoint)
37
33
  match = endpoint.match_on_body? ? endpoint.matcher.source : ''
38
34
  <<-HTML
39
- <a href="/ui/requests/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
35
+ <a href="#{ui_root}/requests/#{endpoint.http_method}#{endpoint.route}?match=#{match}">
40
36
  #{endpoint.requests.count}
41
37
  </a>
42
38
  HTML
@@ -49,5 +45,9 @@ module ApiSim
49
45
  ''
50
46
  end
51
47
  end
48
+
49
+ def ui_root
50
+ self.class.ui_root
51
+ end
52
52
  end
53
- end
53
+ end
@@ -25,7 +25,7 @@
25
25
  <%= link_to_read_requests endpoint %>
26
26
  </td>
27
27
  <td>
28
- <form action="/ui/response/<%= endpoint.http_method %><%= endpoint.route %>" method="post">
28
+ <form action="<%= ui_root %>/response/<%= endpoint.http_method %><%= endpoint.route %>" method="post">
29
29
  <input type="hidden" value="delete" name="_method">
30
30
  <input type="hidden" value="<%= endpoint_match endpoint %>" name="match">
31
31
  <button class='btn-link' type="submit">Reset</button>
@@ -34,4 +34,4 @@
34
34
  </tr>
35
35
  <% end %>
36
36
  </tbody>
37
- </table>
37
+ </table>
@@ -2,7 +2,7 @@
2
2
  <h1>Simulators</h1>
3
3
  <h2>Response for <%= config.http_method %> <%= config.route %></h2>
4
4
  </div>
5
- <form action="/ui/response/<%= config.http_method %><%= config.route %>" method="post">
5
+ <form action="<%= ui_root %>/response/<%= config.http_method %><%= config.route %>" method="post">
6
6
  <div class="row">
7
7
  <% if @errors %>
8
8
  <div class="alert alert-danger">
@@ -51,4 +51,4 @@
51
51
  <button class='btn btn-primary' type="submit">Save</button>
52
52
  </div>
53
53
  </div>
54
- </form>
54
+ </form>
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: 5.1.0
4
+ version: 6.0.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: 2017-04-19 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -163,6 +163,7 @@ files:
163
163
  - lib/api_sim/public/app.js
164
164
  - lib/api_sim/public/favicon.ico
165
165
  - lib/api_sim/recorded_request.rb
166
+ - lib/api_sim/ui_app.rb
166
167
  - lib/api_sim/version.rb
167
168
  - lib/api_sim/view_helpers.rb
168
169
  - lib/api_sim/views/index.html.erb
@@ -189,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  version: '0'
190
191
  requirements: []
191
192
  rubyforge_project:
192
- rubygems_version: 2.4.5
193
+ rubygems_version: 2.6.12
193
194
  signing_key:
194
195
  specification_version: 4
195
196
  summary: A DSL on top of sinatra for building application simulators