-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest.rb
executable file
·57 lines (42 loc) · 1.12 KB
/
rest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env ruby
require 'sinatra/base'
require 'json'
require_relative 'myconfig.rb'
class Rest < Sinatra::Base
#Enable external access on any ip configured.
set :bind, '0.0.0.0'
#load config files
config = MyConfig.new
path = config.attrs[:path]
#use Rack::Auth::Basic do |username, password|
# username == config.attrs[:username] and password == config.attrs[:password]
#end
def reverse(name)
#code
name.reverse
end
get '/complete' do
'Hello World ' + Dir.exists?('tmp/rest/').to_s
end
get '/complete/names' do
name_array = []
Dir.foreach(path) do |item| #if File.directory? '/home/deeje/complete'
#skip . files
next if item =~ /^\./
#set full path for convienence
full_path = "#{path}/#{item}"
#set the type of file/dir
File.directory?(full_path) ? (type = 'dir') : (type = 'file')
#set ctime
ctime = File.stat(full_path).ctime
#Build the array for each item
name_array << {
'name' => item,
'full_path' => full_path,
'type' => type,
'ctime' => ctime
}
end
name_array.to_json
end
end