api_sim 5.1.0 → 8.0.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 +5 -5
- data/.travis.yml +1 -1
- data/README.md +50 -0
- data/api_sim.gemspec +4 -4
- data/examples/basic/Gemfile.lock +15 -15
- data/examples/basic/config.ru +1 -1
- data/examples/cors/Gemfile.lock +21 -18
- data/examples/with-fixtures/Gemfile.lock +19 -17
- data/examples/with-fixtures/config.ru +1 -23
- data/examples/with-fixtures/data/users/1/{GET.json → GET.json.erb} +0 -0
- data/lib/api_sim/app_builder.rb +22 -2
- data/lib/api_sim/built_app.rb +13 -40
- data/lib/api_sim/recorded_request.rb +3 -3
- data/lib/api_sim/ui_app.rb +50 -0
- data/lib/api_sim/version.rb +1 -1
- data/lib/api_sim/view_helpers.rb +7 -7
- data/lib/api_sim/views/index.html.erb +2 -2
- data/lib/api_sim/views/requests/index.html.erb +1 -1
- data/lib/api_sim/views/responses/form.html.erb +2 -2
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 327685bacf8a6f9deecaa212e828fb2357c733f56ff84b34e55d883014c54d01
|
4
|
+
data.tar.gz: bf1feab48cb25aadbbca0f5a6602c1ed47c4781b40833033857f1c0a40dfac62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd5e1c789269cd0bd2e87e5a9616987f4ff726406e43f9070e668120e2fc548de0dd5d5434c77273bb55cb850b7e357976b27cdc12f2c51c00277af698782b5
|
7
|
+
data.tar.gz: 887ab0200e2597021038c29f2f518b0f8c3d48f68160c54cecd738325ee59fd137ab758f6b05d3ed3f4d52fff241f656fdd3c22cad21f31ca5fbc51633b004a0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -54,12 +54,62 @@ After which the simulators should be running on port 9292.
|
|
54
54
|
|
55
55
|
## API
|
56
56
|
|
57
|
+
API Sim has an HTTP API that allows you, the developer, to manage responses and verify
|
58
|
+
requests.
|
59
|
+
|
60
|
+
### The "Request/Response" API
|
61
|
+
|
62
|
+
|
63
|
+
#### Modify the response from an endpoint
|
64
|
+
|
65
|
+
The star in the path should match the request path that you want to update.
|
66
|
+
The "method" in the PUT request should match the HTTP method for the request.
|
67
|
+
```HTTP
|
68
|
+
HTTP/1.1 PUT /response/*
|
69
|
+
{
|
70
|
+
"method": "post",
|
71
|
+
"status": 999,
|
72
|
+
"body": "{\"id\": 99}",
|
73
|
+
"headers": {"NEW-HEADER": "output"}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
#### Read requests made to an endpoint
|
80
|
+
|
81
|
+
The star in the path should match the path that you want to retrieve requests for.
|
82
|
+
```HTTP
|
83
|
+
GET /requests/:method/*
|
84
|
+
```
|
85
|
+
|
86
|
+
```HTTP
|
87
|
+
HTTP/1.1 200 OK
|
88
|
+
|
89
|
+
[
|
90
|
+
{}
|
91
|
+
]
|
92
|
+
```
|
93
|
+
|
94
|
+
### 498
|
95
|
+
|
57
96
|
The API that these simulators generate can get pretty smart. To help you, the user,
|
58
97
|
distinguish between failures and "smarts", we've made up an HTTP status code: 498.
|
59
98
|
This code means "we received a request that did not match an expected schema". If you
|
60
99
|
provide the simulators with a request schema for an endpoint, all requests must match
|
61
100
|
that schema. If they do not, they'll receive our fictional status code.
|
62
101
|
|
102
|
+
## UI
|
103
|
+
|
104
|
+
The simulator application has a UI for manipulating and monitoring requests and responses.
|
105
|
+
You can view this UI by visiting `/ui` at the URL of the simulator.
|
106
|
+
|
107
|
+
Additionally, you can configure the endpoint for viewing the UI by adding to your config.ru.
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
ui_root '/path/to/ui'
|
111
|
+
```
|
112
|
+
|
63
113
|
## Development
|
64
114
|
|
65
115
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/api_sim.gemspec
CHANGED
@@ -19,12 +19,12 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "sinatra", '~>
|
23
|
-
spec.add_dependency "nokogiri", '~> 1.6
|
22
|
+
spec.add_dependency "sinatra", '~> 2.0'
|
23
|
+
spec.add_dependency "nokogiri", '~> 1.6'
|
24
24
|
spec.add_dependency "json-schema", '>= 2.5'
|
25
25
|
spec.add_dependency "mustermann", '~> 1.0.0.beta2'
|
26
|
-
spec.add_development_dependency "bundler", "~> 1
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
-
spec.add_development_dependency "capybara", "~> 2.7
|
29
|
+
spec.add_development_dependency "capybara", "~> 2.7"
|
30
30
|
end
|
data/examples/basic/Gemfile.lock
CHANGED
@@ -1,32 +1,32 @@
|
|
1
1
|
PATH
|
2
2
|
remote: ../..
|
3
3
|
specs:
|
4
|
-
api_sim (
|
4
|
+
api_sim (7.0.0)
|
5
5
|
json-schema (>= 2.5)
|
6
6
|
mustermann (~> 1.0.0.beta2)
|
7
|
-
nokogiri (~> 1.6
|
8
|
-
sinatra (~> 1.
|
7
|
+
nokogiri (~> 1.6)
|
8
|
+
sinatra (~> 1.4)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
addressable (2.
|
14
|
-
public_suffix (
|
15
|
-
json-schema (2.8.
|
13
|
+
addressable (2.7.0)
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
|
+
json-schema (2.8.1)
|
16
16
|
addressable (>= 2.4)
|
17
|
-
mini_portile2 (2.
|
18
|
-
mustermann (1.0.
|
19
|
-
nokogiri (1.
|
20
|
-
mini_portile2 (~> 2.
|
21
|
-
public_suffix (
|
22
|
-
rack (1.6.
|
23
|
-
rack-protection (1.5.
|
17
|
+
mini_portile2 (2.4.0)
|
18
|
+
mustermann (1.0.3)
|
19
|
+
nokogiri (1.10.7)
|
20
|
+
mini_portile2 (~> 2.4.0)
|
21
|
+
public_suffix (4.0.1)
|
22
|
+
rack (1.6.11)
|
23
|
+
rack-protection (1.5.5)
|
24
24
|
rack
|
25
25
|
sinatra (1.4.8)
|
26
26
|
rack (~> 1.5)
|
27
27
|
rack-protection (~> 1.4)
|
28
28
|
tilt (>= 1.3, < 3)
|
29
|
-
tilt (2.0.
|
29
|
+
tilt (2.0.10)
|
30
30
|
|
31
31
|
PLATFORMS
|
32
32
|
ruby
|
@@ -35,4 +35,4 @@ DEPENDENCIES
|
|
35
35
|
api_sim!
|
36
36
|
|
37
37
|
BUNDLED WITH
|
38
|
-
1.
|
38
|
+
1.17.2
|
data/examples/basic/config.ru
CHANGED
@@ -3,7 +3,7 @@ require 'api_sim'
|
|
3
3
|
ENDPOINT_JSON_SCHEMA = {type: "object", properties: {a: {type: "integer"}}}.to_json
|
4
4
|
|
5
5
|
app = ApiSim.build_app do
|
6
|
-
configure_endpoint 'GET', '/endpoint?queryParam=foo', 'Hi!',
|
6
|
+
configure_endpoint 'GET', '/endpoint?queryParam=foo', 'Hi!', 201, {'X-CUSTOM-HEADER' => 'easy as abc'}, ENDPOINT_JSON_SCHEMA
|
7
7
|
configure_endpoint 'GET', '/endpoint', 'Hi!', 200, {'X-CUSTOM-HEADER' => 'easy as abc'}, ENDPOINT_JSON_SCHEMA
|
8
8
|
configure_endpoint 'GET', '/begin/:middle/end', 'You found an any-value path', 200, {'CONTENT-TYPE' => 'application/json'}
|
9
9
|
|
data/examples/cors/Gemfile.lock
CHANGED
@@ -1,31 +1,34 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../..
|
3
3
|
specs:
|
4
|
-
api_sim (
|
4
|
+
api_sim (7.0.0)
|
5
5
|
json-schema (>= 2.5)
|
6
|
-
|
7
|
-
|
6
|
+
mustermann (~> 1.0.0.beta2)
|
7
|
+
nokogiri (~> 1.6)
|
8
|
+
sinatra (~> 1.4)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
addressable (2.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rack
|
22
|
-
rack-
|
13
|
+
addressable (2.7.0)
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
|
+
json-schema (2.8.1)
|
16
|
+
addressable (>= 2.4)
|
17
|
+
mini_portile2 (2.4.0)
|
18
|
+
mustermann (1.0.3)
|
19
|
+
nokogiri (1.10.7)
|
20
|
+
mini_portile2 (~> 2.4.0)
|
21
|
+
public_suffix (4.0.1)
|
22
|
+
rack (1.6.11)
|
23
|
+
rack-cors (1.0.6)
|
24
|
+
rack (>= 1.6.0)
|
25
|
+
rack-protection (1.5.5)
|
23
26
|
rack
|
24
|
-
sinatra (1.4.
|
27
|
+
sinatra (1.4.8)
|
25
28
|
rack (~> 1.5)
|
26
29
|
rack-protection (~> 1.4)
|
27
30
|
tilt (>= 1.3, < 3)
|
28
|
-
tilt (2.0.
|
31
|
+
tilt (2.0.10)
|
29
32
|
|
30
33
|
PLATFORMS
|
31
34
|
ruby
|
@@ -35,4 +38,4 @@ DEPENDENCIES
|
|
35
38
|
rack-cors
|
36
39
|
|
37
40
|
BUNDLED WITH
|
38
|
-
1.
|
41
|
+
1.17.2
|
@@ -1,30 +1,32 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../..
|
3
3
|
specs:
|
4
|
-
api_sim (
|
4
|
+
api_sim (7.0.0)
|
5
5
|
json-schema (>= 2.5)
|
6
|
-
|
7
|
-
|
6
|
+
mustermann (~> 1.0.0.beta2)
|
7
|
+
nokogiri (~> 1.6)
|
8
|
+
sinatra (~> 1.4)
|
8
9
|
|
9
10
|
GEM
|
10
11
|
remote: https://rubygems.org/
|
11
12
|
specs:
|
12
|
-
addressable (2.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rack
|
13
|
+
addressable (2.7.0)
|
14
|
+
public_suffix (>= 2.0.2, < 5.0)
|
15
|
+
json-schema (2.8.1)
|
16
|
+
addressable (>= 2.4)
|
17
|
+
mini_portile2 (2.4.0)
|
18
|
+
mustermann (1.0.3)
|
19
|
+
nokogiri (1.10.7)
|
20
|
+
mini_portile2 (~> 2.4.0)
|
21
|
+
public_suffix (4.0.1)
|
22
|
+
rack (1.6.11)
|
23
|
+
rack-protection (1.5.5)
|
22
24
|
rack
|
23
|
-
sinatra (1.4.
|
25
|
+
sinatra (1.4.8)
|
24
26
|
rack (~> 1.5)
|
25
27
|
rack-protection (~> 1.4)
|
26
28
|
tilt (>= 1.3, < 3)
|
27
|
-
tilt (2.0.
|
29
|
+
tilt (2.0.10)
|
28
30
|
|
29
31
|
PLATFORMS
|
30
32
|
ruby
|
@@ -33,4 +35,4 @@ DEPENDENCIES
|
|
33
35
|
api_sim!
|
34
36
|
|
35
37
|
BUNDLED WITH
|
36
|
-
1.
|
38
|
+
1.17.2
|
@@ -1,30 +1,8 @@
|
|
1
1
|
require 'api_sim'
|
2
2
|
require 'find'
|
3
3
|
|
4
|
-
DATA_DIR = File.expand_path('./data', __dir__)
|
5
|
-
endpoints = []
|
6
|
-
Find.find(DATA_DIR) do |path|
|
7
|
-
next if Dir.exist?(path) # Skip directories
|
8
|
-
http_method = File.basename(path, '.json') # our files are their HTTP method with the mime-type as the extension
|
9
|
-
route = File.dirname(path).gsub(DATA_DIR, '') # the endpoint URL is everything else
|
10
|
-
response = JSON.parse(File.read(path))
|
11
|
-
status = response['status']
|
12
|
-
headers = response['headers']
|
13
|
-
body = response['body'].to_json
|
14
|
-
schema = response['schema'].to_json
|
15
|
-
puts "Configuring endpoint #{http_method} #{route}"
|
16
|
-
endpoints << [
|
17
|
-
http_method,
|
18
|
-
route,
|
19
|
-
body,
|
20
|
-
status,
|
21
|
-
headers,
|
22
|
-
schema
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
4
|
app = ApiSim.build_app do
|
27
|
-
|
5
|
+
configure_fixture_directory './data'
|
28
6
|
end
|
29
7
|
|
30
8
|
run app
|
File without changes
|
data/lib/api_sim/app_builder.rb
CHANGED
@@ -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(
|
@@ -48,14 +54,28 @@ module ApiSim
|
|
48
54
|
headers: response[1],
|
49
55
|
response_body: response[2],
|
50
56
|
default: true,
|
51
|
-
body_matches: matcher
|
57
|
+
body_matches: matcher,
|
52
58
|
)
|
53
59
|
)
|
54
60
|
end
|
55
61
|
end
|
56
62
|
|
63
|
+
def configure_fixture_directory(dir)
|
64
|
+
dir = dir.chomp('/')
|
65
|
+
Dir[File.join(dir, "**/*.json.erb")].each do |path|
|
66
|
+
endpoint_match = path.match(%r{#{dir}([/\w+\_\-]+)/(GET|POST|PATCH|OPTIONS|HEAD|PUT|DELETE).json})
|
67
|
+
config = JSON.parse(File.read(path))
|
68
|
+
configure_endpoint endpoint_match[2],
|
69
|
+
endpoint_match[1],
|
70
|
+
config['body'].to_json,
|
71
|
+
config['status'],
|
72
|
+
config['headers'],
|
73
|
+
config['schema'].to_json
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
57
77
|
def endpoint_configurations
|
58
78
|
@endpoint_configurations ||= []
|
59
79
|
end
|
60
80
|
end
|
61
|
-
end
|
81
|
+
end
|
data/lib/api_sim/built_app.rb
CHANGED
@@ -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
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
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
|
@@ -141,7 +109,8 @@ module ApiSim
|
|
141
109
|
|
142
110
|
@response_body = case request.env['CONTENT_TYPE']
|
143
111
|
when %r{application/json} then
|
144
|
-
|
112
|
+
body = request.body.read
|
113
|
+
body.empty? ? {} : JSON.parse(body)
|
145
114
|
when %r{text/xml} then
|
146
115
|
Nokogiri::XML(request.body.read)
|
147
116
|
when %r{application/x-www-form-urlencoded} then
|
@@ -165,6 +134,10 @@ module ApiSim
|
|
165
134
|
end
|
166
135
|
end
|
167
136
|
|
137
|
+
def route
|
138
|
+
"/#{params[:splat].first}"
|
139
|
+
end
|
140
|
+
|
168
141
|
def blank?(item)
|
169
142
|
item.nil? || item.empty?
|
170
143
|
end
|
@@ -23,10 +23,10 @@ module ApiSim
|
|
23
23
|
private
|
24
24
|
def parse_headers_from(request_env)
|
25
25
|
request_env.select do |k, v|
|
26
|
-
k =~ /^HTTP_/
|
26
|
+
k =~ /^HTTP_/ || k =~ /CONTENT_TYPE/
|
27
27
|
end.each_with_object({}) do |(k, v), h|
|
28
|
-
h[k.split('_')
|
29
|
-
end
|
28
|
+
h[k.gsub(/HTTP\_/, '').split('_').join('-').downcase] = v
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
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
|
data/lib/api_sim/version.rb
CHANGED
data/lib/api_sim/view_helpers.rb
CHANGED
@@ -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="/
|
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="/
|
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="
|
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="
|
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:
|
4
|
+
version: 8.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:
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6
|
33
|
+
version: '1.6'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6
|
40
|
+
version: '1.6'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: json-schema
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1
|
75
|
+
version: '2.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1
|
82
|
+
version: '2.1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.7
|
117
|
+
version: '2.7'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.7
|
124
|
+
version: '2.7'
|
125
125
|
description: A DSL on top of sinatra for building application simulators
|
126
126
|
email:
|
127
127
|
- dugancathal@gmail.com
|
@@ -150,7 +150,7 @@ files:
|
|
150
150
|
- examples/with-fixtures/Gemfile
|
151
151
|
- examples/with-fixtures/Gemfile.lock
|
152
152
|
- examples/with-fixtures/config.ru
|
153
|
-
- examples/with-fixtures/data/users/1/GET.json
|
153
|
+
- examples/with-fixtures/data/users/1/GET.json.erb
|
154
154
|
- lib/api_sim.rb
|
155
155
|
- lib/api_sim/app_builder.rb
|
156
156
|
- lib/api_sim/built_app.rb
|
@@ -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
|
@@ -188,8 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
189
|
- !ruby/object:Gem::Version
|
189
190
|
version: '0'
|
190
191
|
requirements: []
|
191
|
-
|
192
|
-
rubygems_version: 2.4.5
|
192
|
+
rubygems_version: 3.1.2
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: A DSL on top of sinatra for building application simulators
|