Sha256: adac45517e75f190eb9ce3e8876c57010959ff4c0501b8c0cb67591dc6671216
Contents?: true
Size: 795 Bytes
Versions: 2
Compression:
Stored size: 795 Bytes
Contents
require 'sinatra/base' require 'soulmate' module Soulmate class Server < Sinatra::Base include Helpers before do content_type 'application/json', :charset => 'utf-8' end get '/' do '{ "soulmate": 0.1.0, "status": "ok" }' end get '/search' do 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) 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" }' end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
soulmate-0.0.1 | lib/soulmate/server.rb |
soulmate-0.0.0 | lib/soulmate/server.rb |