Class: MainController

Inherits:
Nephos::Controller show all
Defined in:
app/main.rb

Constant Summary collapse

AUTH_IMG_EXT =
%w(.jpg .jpeg .png .gif)

Instance Attribute Summary

Attributes inherited from Nephos::Controller

#callpath, #env, #infos, #params

Instance Method Summary collapse

Methods inherited from Nephos::Controller

#initialize

Constructor Details

This class inherits a constructor from Nephos::Controller

Instance Method Details

#add_urlObject



13
14
15
16
17
18
19
20
21
# File 'app/main.rb', line 13

def add_url
  url = arguments["url"]
  if url
    Dataset << url
    return {plain: "#{url} added"}
  else
    return {plain: "url argument required"}
  end
end

#debugObject



51
52
53
# File 'app/main.rb', line 51

def debug
  binding.pry
end

#helloObject



33
34
35
# File 'app/main.rb', line 33

def hello
  {html: "<html><body><h1>hello world</h1><p>lol</p></body></html>"}
end

#imageObject



38
39
40
41
42
43
44
45
46
47
48
# File 'app/main.rb', line 38

def image
  dir = File.expand_path('controllers/')
  file = File.expand_path(params["image"], dir)
  if not file[0..(dir.size-1)] == dir or not AUTH_IMG_EXT.include?(File.extname(file))
    return {status: 500, content: "invalid path #{params['image']}"}
  elsif not File.exists? file
    return {status: 404, content: "invalid path #{params['image']}"}
  else
    return {type: 'image/jpeg', content: File.read(file)}
  end
end

#rm_urlObject



23
24
25
26
27
28
29
30
31
# File 'app/main.rb', line 23

def rm_url
  url = arguments[:url]
  if url
    Dataset.rm url
    return {plain: "#{url} removed"}
  else
    return {plain: "url argument required"}
  end
end

#rootObject



3
4
5
6
7
8
9
10
11
# File 'app/main.rb', line 3

def root
  {
    json: {
      list: $dataset,
      add: '/add',
      rm: '/rm',
    }
  }
end