访问restforce集合以检索ruby脚本中的数据

时间:2018-01-10 17:17:18

标签: ruby restforce

这似乎是一个基本的东西,但有点不确定如何从restforce :: collection

访问数据
require 'restforce'

##set up the connection  part here

accounts = client.query('select Id, EventType, Logdate from EventLogFile where LogDate = Last_n_Days:2')
p accounts

帐户对象返回为restforce :: collection,如下所示:

#<Restforce::Collection:0x00000002197218 @client=#<Restforce::Data::Client @options={:api_version=>"41.0", :username=>"sfdc.dev", :password=>"somepass!", :security_token=>nil, :client_id=>"3MVG9A2kN3Bn1XgTalsb2qZ0e7r9tzLavy7o_V7AAQG7jKctPLq.qDq", :client_secret=>"87623", :host=>"login.salesforce.com", :oauth_token=>"DIZcbAJBBdKtF67Vm3pBI1vasRBp41PQpDCz2yfghnqwXYpyvcecLvpUx", :refresh_token=>nil, :instance_url=>"https://myorg.my.salesforce.com", :cache=>nil, :authentication_retries=>3, :compress=>nil, :mashify=>nil, :timeout=>nil, :adapter=>:net_http, :proxy_uri=>nil, :authentication_callback=>nil, :ssl=>{}, :request_headers=>nil, :logger=>#<Logger:0x00000002158158 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x000000021580e0 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00000002158068 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00000002158798>>>, :log_level=>:debug}>, @raw_page={"totalSize"=>2, "done"=>true, "records"=>[{"attributes"=>{"type"=>"Account", "url"=>"/services/data/v41.0/sobjects/Account/001i000002EF7iDAAT"}, "Id"=>"001i000002EF7iDAAT", "Name"=>"Sterlidge Pty Ltd", "AccountNumber"=>nil}, {"attributes"=>{"type"=>"Account", "url"=>"/services/data/v41.0/sobjects/Account/001i000002EF7iEAAT"}, "Id"=>"001i000002EF7iEAAT", "Name"=>"Sherwood Gem Pty Ltd", "AccountNumber"=>nil}]}>

如何检索:oauth_token之类的值?做某事 accounts[:oauth_token],抛出异常

undefined method `[]' for #<Restforce::Collection:0x000000010ead70> (NoMethodError)

1 个答案:

答案 0 :(得分:0)

根据API,您可以oauth_token获取client,如此:

client.options[:oauth_token]