1

I created one class to call api on other rails server.

Client (RemoteAssessment.rb):

class RemoteAssessment < ActiveResource::Base

self.site = "http://localhost:5000/api/v1"

headers["Content-Type"] = "application/json"

with_api_auth(access_id, secret_key)

end

Calling code (onefile.rb):

RemoteAssessment.find('4')

I want to pass "access_id" and "secret_key" from my caller (onefile.rb). I tried multiple ways but it is not working.

I am new to ruby on rails, so it may be a basic question.

Please help me to figure out passing parameter from caller.

Thanks, Sachin

1 Answers1

0

One way to do it is

Client (RemoteAssessment.rb):

class RemoteAssessment < ActiveResource::Base

  def self.with_api_auth(access_id, secret_key)

  end
end

and in

remoteAssessment = RemoteAssessment.find('4')

remoteAssessment.with_api_auth(ENV['access_id'], ENV['secret_key']

and other you can create service class and pass access_id and secret_key

Kamal Pandey
  • 1,508
  • 1
  • 8
  • 12
  • Thanks Bhupati. I tried your solution but it is not working. As api is calling before in your solution and after that it is calling the with_api_auth. Also these parameter will be different for each login, we can not take it from ENV variables. – Sachin Saxena Jun 04 '19 at 10:53
  • could you show some more code from where you are calling this or may be github link so that it will be easier to debug – Kamal Pandey Jun 04 '19 at 11:03