I am using databasedotcom gem. I am able to get data for 1 account only by specifying Client_id, client_secret, username and password in config/database.yml file. but i want to get data according to user login. 1st user login with salesforce he will get data from his salesforce account. same for 2nd 3rd and 4th. Any suggestion will be appreciated.
Example code is below:-
database.yml:-
host: login.salesforce.com client_id: the Consumer Key from Salesforce
client_secret: the Consumer Secret from Salesforce
username: username
password: password+securitytoken
debugging: true
sfdc_controller:-
class Api::V1::SfdcsController < ApplicationController
include Databasedotcom::Rails::Controller
def getSfdcauthentication
username = params[:username]
password = params[:password]
client_id = params[:client_id]
client_secret = params[:client_secret]
client = Databasedotcom::Client.new :client_id => client_id, :client_secret => client_secret
begin
oauth_token = client.authenticate :username => username, :password => password #=> "the-oauth-token"
rescue =>e
oauth_token = false
end
if oauth_token
contact_class = client.materialize("Contact")
@sf_contacts = Contact.all
respond_with(@sf_contacts) do |format|
format.json { render :json => @sf_contacts.as_json }
end
else
render json: {status:200,message:"Authentication failed"}
end
end
end