Class: ActionFramework::BaseAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/actionframework/baseapi.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseAPI

Returns a new instance of BaseAPI.



4
5
6
# File 'lib/actionframework/baseapi.rb', line 4

def initialize
		api_init
end

Class Attribute Details

.config(key, value) ⇒ Object

Returns the value of attribute config.



9
10
11
# File 'lib/actionframework/baseapi.rb', line 9

def config
  @config
end

.routesObject

Returns the value of attribute routes.



9
10
11
# File 'lib/actionframework/baseapi.rb', line 9

def routes
  @routes
end

Class Method Details

.api(suffix, method) ⇒ Object



20
21
22
23
24
25
# File 'lib/actionframework/baseapi.rb', line 20

def api suffix,method
	if(@config[:json] == true)
		prefix = "/json/"
	end
	@routes[method] = prefix+(suffix.to_s.gsub("_","/"))
end

.api_initObject



15
16
17
18
# File 'lib/actionframework/baseapi.rb', line 15

def api_init
	@routes = {}
	@config = {}
end

.call(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/actionframework/baseapi.rb', line 27

def call env
	@request = Rack::Request.new env
	@response = Rack::Response.new

	if(@routes[@request.method].nil?)
		@response.write "404 Not Found"
		return @response.finish
	end
	methodname = @routes[method].split("/")
	response = self.send(methodname[methodname.length-1])
	if(@config[:json] == true)
		response = response.to_json
	end
	@response.write response
	@response.finish
end

.paramsObject



44
45
46
# File 'lib/actionframework/baseapi.rb', line 44

def params
	@request.params
end