Class: ActionFramework::BaseAPI
- Inherits:
-
Object
- Object
- ActionFramework::BaseAPI
- Defined in:
- lib/actionframework/baseapi.rb
Class Attribute Summary collapse
-
.config(key, value) ⇒ Object
Returns the value of attribute config.
-
.routes ⇒ Object
Returns the value of attribute routes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ BaseAPI
constructor
A new instance of BaseAPI.
Constructor Details
#initialize ⇒ BaseAPI
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 |
.routes ⇒ Object
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_init ⇒ Object
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 |
.params ⇒ Object
44 45 46 |
# File 'lib/actionframework/baseapi.rb', line 44 def params @request.params end |