Class: Grass::API
- Inherits:
-
Goliath::API
- Object
- Goliath::API
- Grass::API
- Defined in:
- lib/grass/endpoints/api.rb
Constant Summary collapse
- JSON_HEAD =
{"Content-Type" => "application/json"}
- FILE_PARAMS =
%w(raw binary)
- FILE_ACTIONS =
%w(hide show commit)
Instance Method Summary collapse
- #delete(env) ⇒ Object
- #get(env) ⇒ Object
- #post(env) ⇒ Object
- #put(env) ⇒ Object
- #response(env) ⇒ Object
Instance Method Details
#delete(env) ⇒ Object
42 43 44 45 46 47 |
# 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) ⇒ Object
23 24 25 |
# File 'lib/grass/endpoints/api.rb', line 23 def get(env) [200,JSON_HEAD,get_file.to_json] end |
#post(env) ⇒ Object
27 28 29 30 31 32 |
# 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) ⇒ Object
34 35 36 37 38 39 40 |
# 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) ⇒ Object
19 20 21 |
# File 'lib/grass/endpoints/api.rb', line 19 def response(env) self.public_send env['REQUEST_METHOD'].downcase, env end |