Class: ActionFramework::BaseAPI
- Inherits:
-
Object
- Object
- ActionFramework::BaseAPI
- Defined in:
- lib/actionframework/baseapi.rb
Constant Summary collapse
- @@config =
{}
- @@routes =
{}
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.api(suffix, method) ⇒ Object
17 18 19 20 |
# File 'lib/actionframework/baseapi.rb', line 17 def self.api(suffix,method) array = @@routes[method] || @@routes[method.to_s.upcase] = [] array << suffix.to_s.gsub("_","/") end |
.config(key, value) ⇒ Object
13 14 15 |
# File 'lib/actionframework/baseapi.rb', line 13 def self.config(key,value) @@config[key] = value end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/actionframework/baseapi.rb', line 22 def call env @request = Rack::Request.new(env) @response = Rack::Response.new path = @request.path path.slice!(0) if(@@routes[@request.request_method].nil? || !@@routes[@request.request_method].include?(path)) @response.write "404 Not Found" @response.status = 404 return @response.finish end res = self.send(path.gsub("/","_")) if(@@config[:json]) @response.header["Content-type"] = "application/json" res = res.to_json end @response.write res return @response.finish end |