Class: Thoth::PostApiController
- Inherits:
-
Controller
- Object
- Ramaze::Controller
- Controller
- Thoth::PostApiController
- Defined in:
- lib/thoth/controller/api/post.rb
Instance Method Summary collapse
-
#check_name ⇒ Object
Returns a response indicating whether the specified post name is valid and not already taken.
-
#delete ⇒ Object
Deletes the specified comment.
-
#suggest_name ⇒ Object
Suggests a valid and unique name for the specified post title.
Methods inherited from Controller
Instance Method Details
#check_name ⇒ Object
Returns a response indicating whether the specified post name is valid and not already taken. Returns an HTTP 200 response on success or an HTTP 500 response on error.
Query Parameters
- name
-
post name to check
Sample Response
{"valid":true,"unique":true}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/thoth/controller/api/post.rb', line 46 def check_name error_403 unless auth_key_valid? unless request[:name] && request[:name].length > 0 error_400('Missing required parameter: name') end response['Content-Type'] = 'application/json' name = request[:name].to_s JSON.generate({ :valid => Post.name_valid?(name), :unique => Post.name_unique?(name) }) end |
#delete ⇒ Object
Deletes the specified comment. Returns an HTTP 200 response on success, an HTTP 500 response on error, or an HTTP 404 response if the specified comment does not exist.
Query Parameters (POST only)
- id
-
comment id
- token
-
form token
Sample Response
Success
{"success":true}
Failure
{"error":"The comment could not be deleted due to a database error."}
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/thoth/controller/api/post.rb', line 82 def delete error_403 unless auth_key_valid? && form_token_valid? error_405 unless request.post? error_404 unless request[:id] && @comment = Comment[request[:id]] response['Content-Type'] = 'application/json' if @comment.destroy Ramaze::Cache.action.clear JSON.generate({:success => true}) else respond(JSON.generate({ :error => 'The comment could not be deleted due to a database error.' }, 500)) end end |
#suggest_name ⇒ Object
Suggests a valid and unique name for the specified post title. Returns an HTTP 200 response on success or an HTTP 500 response on error.
Query Parameters
- title
-
post title
Sample Response
{"name":"ninjas-are-awesome"}
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/thoth/controller/api/post.rb', line 110 def suggest_name error_403 unless auth_key_valid? unless request[:title] && request[:title].length > 0 error_400('Missing required parameter: title') end response['Content-Type'] = 'application/json' JSON.generate({"name" => Post.suggest_name(request[:title])}) end |