api_sim 6.0.0 → 6.1.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7905137c0443a89caa2b2d4469b61176c070e36c
|
4
|
+
data.tar.gz: 84e725443b70b8b5f318615a2872392a7d6a33a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4aad308c51ffc159df5e0474d2e8cf462ee49e5b13612a8464934820d2577561f401455603db5639205416810ce28c7e9cef068b4ad7c0ab22fcb6e38bc11a2
|
7
|
+
data.tar.gz: 6925d1f89a28eb0b391ad7d722ba20af55bdf834ded8ccf80bf20cb6f6a4327fe7975cff51220a3c1ff4c6908fa7482e4ae6a9ddb2cc64a14d04f92ec98dd641
|
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
|
|
@@ -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
@@ -54,12 +54,26 @@ module ApiSim
|
|
54
54
|
headers: response[1],
|
55
55
|
response_body: response[2],
|
56
56
|
default: true,
|
57
|
-
body_matches: matcher
|
57
|
+
body_matches: matcher,
|
58
58
|
)
|
59
59
|
)
|
60
60
|
end
|
61
61
|
end
|
62
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
|
+
|
63
77
|
def endpoint_configurations
|
64
78
|
@endpoint_configurations ||= []
|
65
79
|
end
|
data/lib/api_sim/version.rb
CHANGED
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: 6.
|
4
|
+
version: 6.1.1
|
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-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -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
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
192
|
rubyforge_project:
|
193
|
-
rubygems_version: 2.6.
|
193
|
+
rubygems_version: 2.6.11
|
194
194
|
signing_key:
|
195
195
|
specification_version: 4
|
196
196
|
summary: A DSL on top of sinatra for building application simulators
|