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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d57ed2b6dd27e29957eba23cc6c1db7151976fb6
4
- data.tar.gz: 1b1a33b4adf338b09a3b4fc550a0ef709fe099d9
3
+ metadata.gz: 2342a194cd72165b95cc033f50da33195b97e1a6
4
+ data.tar.gz: f60394a0258a4dafb00d355f477f1c3fff30525e
5
5
  SHA512:
6
- metadata.gz: 692792ab410f0828fff347c1196bb028b476361fe3337df0303909ae96dc1d6baa0c0755a9e1d416080d53d0cbb12db1eafcd03c5203f79b5c16c813c3090aae
7
- data.tar.gz: 667d4b0044c70eb6577763b2feb51b87bf6cf5f13e3ab5bd224bf5cf82f9925ee4e972474aea1bbe7efe93c187f2eb2b8e6aa1595a4f35265ee90935f62e4d2a
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('.', path, "#{verb}.json")
8
- halt 404 if !File.exists?(path)
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 '/*' do
15
- serve_file request.path_info, 'get'
16
- end
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
@@ -1,3 +1,3 @@
1
1
  module Apiif
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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: