How to pass parameter to with_api_auth(access_id, secret_key) in rails

101 Views Asked by At

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

There are 1 best solutions below

2
Kamal Pandey On

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