lib/soulmate/server.rb in soulmate-0.0.1 vs lib/soulmate/server.rb in soulmate-0.0.2
- old
+ new
@@ -9,31 +9,34 @@
before do
content_type 'application/json', :charset => 'utf-8'
end
get '/' do
- '{ "soulmate": 0.1.0, "status": "ok" }'
+ JSON.pretty_generate({ :soulmate => Soulmate::Version::STRING, :status => "ok" })
end
get '/search' do
+ raise Sinatra::NotFound unless (params[:term] and params[:types] and params[:types].is_a?(Array))
+
limit = (params[:limit] || 5).to_i
types = params[:types].map { |t| normalize(t) }
term = params[:term]
results = {}
types.each do |type|
- matcher = Soulmate::Matcher.new(type)
+ matcher = Matcher.new(type)
results[type] = matcher.matches_for_term(term, :limit => limit)
end
JSON.pretty_generate({
:term => params[:term],
:results => results
})
end
not_found do
- '{ "error": "not found" }'
+ content_type 'application/json', :charset => 'utf-8'
+ JSON.pretty_generate({ :error => "not found" })
end
end
end