我需要使用这个Sinatra应用程序并让它在rails中运行。我知道我可以将它放在lib文件夹中并设置路由。但是如何设置接受参数的路径?
kClientId = ""
kClientSecret = ""
kClientCallbackURL = ""
set :port, 1234 # The port to bind to.
post '/swap' do
# This call takes a single POST parameter, "code", which
# it combines with your client ID, secret and callback
# URL to get an OAuth token from the Spotify Auth Service,
# which it will pass back to the caller in a JSON payload.
auth_code = params[:code]
uri = URI.parse("https://ws.spotify.com")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new("/oauth/token")
request.form_data = {
"grant_type" => "authorization_code",
"client_id" => kClientId,
"client_secret" => kClientSecret,
"redirect_uri" => kClientCallbackURL,
"code" => auth_code
}
response = http.request(request)
status response.code.to_i
return response.body
end
答案 0 :(得分:0)
Mount Sinatra app inside a rails app and sharing layout
基本上你可以安装你的应用程序,你的Sinatra应用程序中的所有路径都将以你安装它的路径为前缀。 Params将照常通过。