class Grass::API
Constants
- FILE_ACTIONS
- FILE_PARAMS
- JSON_HEAD
Public Instance Methods
delete(env)
click to toggle source
# File lib/grass/endpoints/api.rb, line 42 def delete(env) file = get_file deleted = !file.destroy.persisted? error! file unless deleted [200,JSON_HEAD,deleted] end
get(env)
click to toggle source
# File lib/grass/endpoints/api.rb, line 23 def get(env) [200,JSON_HEAD,get_file.to_json] end
post(env)
click to toggle source
# File lib/grass/endpoints/api.rb, line 27 def post(env) file = Source.create(get_file_params.update(key: env['REQUEST_PATH'])) error! file unless file.persisted? get_file_actions.each{|action| file.public_send(action) } [200,JSON_HEAD,file.to_json] end
put(env)
click to toggle source
# File lib/grass/endpoints/api.rb, line 34 def put(env) file = get_file updated = file.update(get_file_params) error! file unless updated get_file_actions.each{|action| file.public_send(action) } [200,JSON_HEAD,file.to_json] end
response(env)
click to toggle source
# File lib/grass/endpoints/api.rb, line 19 def response(env) self.public_send env['REQUEST_METHOD'].downcase, env end
Private Instance Methods
error!(file)
click to toggle source
# File lib/grass/endpoints/api.rb, line 64 def error! file raise Goliath::Validation::NotAcceptable.new(file.errors.full_messages.to_json) end
get_file()
click to toggle source
# File lib/grass/endpoints/api.rb, line 51 def get_file raise Goliath::Validation::NotFoundError unless file = Source[env['REQUEST_PATH']].first file end
get_file_actions()
click to toggle source
# File lib/grass/endpoints/api.rb, line 56 def get_file_actions FILE_ACTIONS.select{ |action| params.delete(action) }.map{|action| "#{action}!" } end
get_file_params()
click to toggle source
# File lib/grass/endpoints/api.rb, line 60 def get_file_params params.select{ |key,value| FILE_PARAMS.include?(key) } end