0

I need to take this Sinatra app and have it run in rails. I get I can place this in the lib folder and set up the routes. But how do I set up the route to accept the parameter?

    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
Dondada
  • 421
  • 9
  • 25
  • This is an exact duplicate (including identical code) of http://stackoverflow.com/questions/22445318/turning-a-sinatra-app-into-a-rails-controller – matt Mar 17 '14 at 16:09

1 Answers1

0

Mount Sinatra app inside a rails app and sharing layout

Basically you can mount your app and all the routes in your Sinatra App will be prefixed by the route under which you mounted it. Params will be passed as usual.

Community
  • 1
  • 1