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

Accessing the restforce collection to retrive data in a ruby script

这似乎是一件基本的事情,但不确定如何从 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

帐户对象 return 像这样 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)

基于 API 你可以从 client 得到 oauth_token 像这样:

client.options[:oauth_token]