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: d28ccc19a3eaa578a47a72156ae7506b1c0c629d
4
- data.tar.gz: 5008b1738a71153aa9933abd54b92da4b54fab8f
3
+ metadata.gz: 7905137c0443a89caa2b2d4469b61176c070e36c
4
+ data.tar.gz: 84e725443b70b8b5f318615a2872392a7d6a33a2
5
5
  SHA512:
6
- metadata.gz: d0f04ea1e7d633fcde25d0edcd2aefe28664eb954a086b1b0a8cb01c2b22517a1ca40d903459e64cf164ef3c31c19b1b228d2ac21c55f3a0548e8e2938c11f67
7
- data.tar.gz: 3f830c93e9579f75381dd3ee2961dcf83746b451ae53ecf44ce53d5aa32d153354484e0ee28a618ec33f3a8206329913f17cecc36b0941554a571b215c70db43
6
+ metadata.gz: d4aad308c51ffc159df5e0474d2e8cf462ee49e5b13612a8464934820d2577561f401455603db5639205416810ce28c7e9cef068b4ad7c0ab22fcb6e38bc11a2
7
+ data.tar.gz: 6925d1f89a28eb0b391ad7d722ba20af55bdf834ded8ccf80bf20cb6f6a4327fe7975cff51220a3c1ff4c6908fa7482e4ae6a9ddb2cc64a14d04f92ec98dd641
@@ -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!', 200, {'X-CUSTOM-HEADER' => 'easy as abc'}, ENDPOINT_JSON_SCHEMA
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
- endpoints.each {|endpoint| configure_endpoint(*endpoint) }
5
+ configure_fixture_directory './data'
28
6
  end
29
7
 
30
8
  run app
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ApiSim
2
- VERSION = "6.0.0"
2
+ VERSION = "6.1.1"
3
3
  end
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.0.0
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-06-16 00:00:00.000000000 Z
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.12
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