Class: Thoth::PostApiController

### Home Classes Methods

### In Files

- lib/thoth/controller/api/post.rb

### Parent

Ramaze::Controller

### Methods

- #check_name
- #delete
- #suggest_name

### Files

- robots.txt

### Class/Module Index

Quicksearch

- Thoth
- Thoth::AdminController
- Thoth::ArchiveController
- Thoth::Comment
- Thoth::CommentApiController
- Thoth::CommentController
- Thoth::Config
- Thoth::Error
- Thoth::Importer
- Thoth::MainController
- Thoth::Media
- Thoth::MediaController
- Thoth::MinifyController
- Thoth::Page
- Thoth::PageApiController
- Thoth::PageController
- Thoth::Pager
- Thoth::Plugin
- Thoth::Plugin::Delicious
- Thoth::Plugin::Flickr
- Thoth::Plugin::Tags
- Thoth::Plugin::Twitter
- Thoth::Post
- Thoth::PostApiController
- Thoth::PostController
- Thoth::SchemaError
- Thoth::SearchController
- Thoth::Tag
- Thoth::TagApiController
- Thoth::TagController
- Thoth::TagsPostsMap
- Ramaze
- Ramaze::Dispatcher
- Ramaze::Dispatcher::File
- Ramaze::Helper
- Ramaze::Helper::Admin
- Ramaze::Helper::Cookie
- Ramaze::Helper::Error
- Ramaze::Helper::Pagination
- Ramaze::Helper::Sanitize
- Ramaze::Helper::Wiki
- Ramaze::Helper::Ysearch
- Ramaze::Helper::Ysearch::SearchError
- AddMediaSize
- CreateSchema
- PantsImporter
- PoseidonImporter

No matching classes.

# Thoth::PostApiController

### Public Instance Methods

check_name() click to toggle source

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}

    # File lib/thoth/controller/api/post.rb, line 51
    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() click to toggle source

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 an unknown database error."}

    # File lib/thoth/controller/api/post.rb, line 87
    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
        action_cache.clear
        JSON.generate({:success => true})
      else
        respond(JSON.generate({
          :error => 'The comment could not be deleted due to an unknown ' <<
              'database error.'
        }, 500))
      end
    end

suggest_name() click to toggle source

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"}

    # File lib/thoth/controller/api/post.rb, line 116
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.