class Actn::Api::Public
Constants
- CT_JS
- CT_JSON
Public Class Methods
inherited(base)
click to toggle source
Calls superclass method
# File lib/actn/api/public.rb, line 18 def self.inherited base super base.use Goliath::Rack::Params base.use Goliath::Rack::Heartbeat base.use Mw::NoXSS base.use Rack::Session::Cookie, secret: ENV['SECRET'] base.use Rack::Csrf, skip: ['OPTIONS:/.*'], skip_if: proc { |r| ENV['RACK_ENV'] == "test" } base.use Mw::Cors base.use Goliath::Rack::BarrierAroundwareFactory, Mw::Auth, exclude: /^\/connect$/ super end
Public Instance Methods
process(table, path)
click to toggle source
# File lib/actn/api/public.rb, line 35 def process table, path raise NotImplementedError end
response(env)
click to toggle source
# File lib/actn/api/public.rb, line 41 def response env path = env['REQUEST_PATH'] || "/" unless table = path[1..-1].split("/").first raise Goliath::Validation::Error.new(400, "model identifier missing") end begin json = process(table,path) rescue PG::InternalError => e if e.message =~ /does not exist/ raise Goliath::Validation::NotFoundError.new("resource not found") else raise e end end status = json =~ /errors/ ? 406 : 200 [status, CT_JSON, json] end
Private Instance Methods
data()
click to toggle source
# File lib/actn/api/public.rb, line 83 def data params['data'] end
limit()
click to toggle source
# File lib/actn/api/public.rb, line 67 def limit query['limit'] || 50 end
offset()
click to toggle source
# File lib/actn/api/public.rb, line 75 def offset limit * page end
page()
click to toggle source
# File lib/actn/api/public.rb, line 71 def page ((query['page'] || 1).to_i - 1) end
query()
click to toggle source
# File lib/actn/api/public.rb, line 79 def query params['query'] end