apiif 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apiif.rb +13 -8
- data/lib/apiif/options.rb +20 -0
- data/lib/apiif/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2342a194cd72165b95cc033f50da33195b97e1a6
|
4
|
+
data.tar.gz: f60394a0258a4dafb00d355f477f1c3fff30525e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8716ce495242f386f5fa33fd77470d2f1ac31b6a13c4e9b25a1dd2f05ce320aa449b5228186536812b422342772f04ba5466152a04fcbd2c9b3422169ae6e1b
|
7
|
+
data.tar.gz: 272f95038c6c1150cb8f761b9b2160da53c718e22f11484db0363c10a48df65c92ec1f3ea80a122c1b37a1756d8c618706a80d7cb839d929d5ce5b8590bc3c9d
|
data/lib/apiif.rb
CHANGED
@@ -1,21 +1,26 @@
|
|
1
1
|
require 'apiif/version'
|
2
|
+
require 'apiif/options'
|
2
3
|
|
3
4
|
require 'sinatra'
|
4
5
|
|
5
6
|
class Apiif::Server < Sinatra::Base
|
7
|
+
set :port, Apiif::OPTIONS[:port]
|
8
|
+
|
6
9
|
def serve_file(path, verb)
|
7
|
-
path = File.join(
|
8
|
-
|
10
|
+
path = File.join(Apiif::OPTIONS[:root], path, "#{verb}.json")
|
11
|
+
|
12
|
+
if !File.exists?(path)
|
13
|
+
halt 405 if Dir.exists?(File.dirname(path))
|
14
|
+
halt 404
|
15
|
+
end
|
9
16
|
|
10
17
|
content_type :json
|
11
18
|
File.read(path)
|
12
19
|
end
|
13
20
|
|
14
|
-
get '
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
post '/*' do
|
19
|
-
serve_file request.path_info, 'post'
|
21
|
+
['get', 'put', 'post', 'delete'].each do |verb|
|
22
|
+
self.send verb, '/*' do
|
23
|
+
serve_file request.path_info, verb
|
24
|
+
end
|
20
25
|
end
|
21
26
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
Apiif::OPTIONS = {
|
4
|
+
:port => 8080,
|
5
|
+
:root => Dir.pwd
|
6
|
+
}
|
7
|
+
|
8
|
+
parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = 'Usage: apiif [options]'
|
10
|
+
|
11
|
+
opts.on '--port [PORT]', Integer, 'HTTP Server port (default: 8080)' do |port|
|
12
|
+
Apiif::OPTIONS[:port] = port
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on '--root [PATH]', 'Directory root (default: current directory)' do |path|
|
16
|
+
Apiif::OPTIONS[:root] = path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
parser.parse!
|
data/lib/apiif/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apiif
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Tao
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- bin/apiif
|
35
35
|
- lib/apiif.rb
|
36
|
+
- lib/apiif/options.rb
|
36
37
|
- lib/apiif/version.rb
|
37
38
|
homepage: https://github.com/dtao/apiif
|
38
39
|
licenses:
|