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