Class: Thoth::TagApiController

Inherits:
Controller
  • Object
show all
Defined in:
lib/thoth/controller/api/tag.rb

Instance Method Summary collapse

Methods inherited from Controller

action_missing

Instance Method Details

#suggestObject

Returns a JSON array of existing tag names and usage counts for tags that begin with the specified query string.

Query Parameters

q

query string

limit

(optional) maximum number of tags to return

Sample Response

[["foo",15],["foobar",11],["foosball",2]]


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/thoth/controller/api/tag.rb', line 45

def suggest
  error_403 unless auth_key_valid?

  unless request[:q]
    error_400('Missing required parameter: q')
  end

  query = request[:q].lstrip
  limit = request[:limit] ? request[:limit].to_i : 1000

  response['Content-Type'] = 'application/json'
  JSON.generate(Tag.suggest(query, limit))
end