Forum: Ruby on Rails REST: transfer data between applications

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-01-16 12:15
Hi all

I'm having trouble finding info on how to tranfser data between 2 rest
appliations. I will try to scetch my problem as simple as possible. I
store data in my first application. In my first application, users need
to login to gain access. The users login with a login form:

# my session controller that handles the authentication
  def create
    logged_in_user = User.find_by_email_and_password(email, password)

    # Create the session and redirect
    unless logged_in_user.blank?
      session[:user] = logged_in_user
      if session[:user].landingspage
        redirect_to(session[:user].landingspage)
      else
        redirect_to(outgoing_invoices_path)
      end
    else
      redirect_to('/login')
      flash[:error] = 'Invalid username/password combination'
    end
  end

Every controller gets checked if the user is still logged in:
before_filter :ensure_login

  def ensure_login
      unless session[:user]
        flash[:error] = "Please login to continue"
        redirect_to("/login")
      end
  end

Once I log in with my browser, I can retrieve all the info in any format
I want (html, xml, json, ...)

Now I have my second application where I want to retrieve data in xml
format from my first application.

No my first obstical is how to pass the login. With every request I will
need to send the login info becouse I don't think the login will be
persistant. I have read info on basic http but I can't seem to integrate
the info in the ensure_login action.
Also, with the login request, I will need to send the request to the
controller/action of what data I need with search parameters. But how do
I sent the login/data request from my second application to my first? I
have found some examples like:

require 'net/http'

Net::HTTP.start('localhost', 3000) do |http|
  response = http.get('/people', 'Accept' => 'text/xml')

  #Do something with the response.

  @code = response.code
  @message = response.message
  @body = response.body
end


In the above example, I try to get xml data from the people object in
xml format. But how do I send my login info and my search parameters?

Any info would be great, becouse I can't seem to find any consistant
info on this.

Thank you in advance
2b2b07fe8688479d2559704d4bf8a264?d=identicon&s=25 Szymon Nowak (szimek)
on 2009-01-16 14:28
(Received via mailing list)
Your login system should provide a way to authenticate using HTTP
basic authentication - most authentication plugins do so i.e.
restful_authentication. If you're not using any plugin, check
http://railscasts.com/episodes/82 to see how to set it up.

Instead of using plain Net::HTTP, you can use ActiveResource (http://
api.rubyonrails.org/classes/ActiveResource/Base.html) or REST Client
(http://rest-client.heroku.com/rdoc/).

On Jan 16, 12:15 pm, Michael Rigart <rails-mailing-l...@andreas-s.net>
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-01-16 16:11
Szymon Nowak wrote:
> Your login system should provide a way to authenticate using HTTP
> basic authentication - most authentication plugins do so i.e.
> restful_authentication. If you're not using any plugin, check
> http://railscasts.com/episodes/82 to see how to set it up.
>
> Instead of using plain Net::HTTP, you can use ActiveResource (http://
> api.rubyonrails.org/classes/ActiveResource/Base.html) or REST Client
> (http://rest-client.heroku.com/rdoc/).
>
> On Jan 16, 12:15�pm, Michael Rigart <rails-mailing-l...@andreas-s.net>

Thanks for the input. I'm usering ActiveResource right now, but I have a
problem when I do a find of my activeresource model.When I do:

Task.find(:all, :params => { :company_id => 78 })

the parameter company_id doesn't seem to get send. When I want to
retrieve the parameter with params[:company_id] I get a blank result
instead of 78 :s
This topic is locked and can not be replied to.