Class: CommunityZero::SearchEndpoint
- Defined in:
- lib/community_zero/endpoints/search_endpoint.rb
Overview
The endpoint for searching for cookbooks.
Constant Summary
Constants inherited from Endpoint
Instance Attribute Summary
Attributes inherited from Endpoint
Instance Method Summary collapse
-
#get(request) ⇒ Object
GET /search?q=QUERY.
Methods inherited from Endpoint
#call, #initialize, #store, #url_for, #version_url_for
Constructor Details
This class inherits a constructor from CommunityZero::Endpoint
Instance Method Details
#get(request) ⇒ Object
GET /search?q=QUERY
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/community_zero/endpoints/search_endpoint.rb', line 24 def get(request) q = request.query_params['q'].to_s start = Integer(request.query_params['start'] || 0) items = Integer(request.query_params['items'] || 10) cookbooks = store.search(q)[start...items] || [] respond({ 'items' => cookbooks.collect { |cookbook| { 'cookbook_name' => cookbook.name, 'cookbook_description' => cookbook.description, 'cookbook' => url_for(cookbook), 'cookbook_maintainer' => cookbook.maintainer } }, 'total' => cookbooks.size, 'start' => start, }) end |