我已经设法让它几乎可以工作,但我认为我遇到了一些严重的困惑。所有示例似乎都涵盖了根据 id 查找单个记录。
我以为我可以传递一个参数来过滤单个属性
https://xxxx.basecamphq.com/companies.xml?name=xxxx
Basecamp::Company.find(:all, :params => { :name => xxx })
require 'rubygems'
require 'English'
require 'trollop'
require 'basecamp'
require 'ap'
opts = Trollop::options do
version "1.0"
banner <<-EOS
#{File.basename($0)}
Description: Dump the users from a company stored in basecampe via the api.
Usage:
#{File.basename($0)} [options]
where [options] are:
EOS
opt :company , "Company to export" , :default => "XXXX"
opt :token_file, "File to read token from " , :default => "~/.basecamp/token"
end
basecamp_token = IO.read(File.expand_path(opts[:token_file])).chomp
Basecamp.establish_connection!('xxxx.basecamphq.com', basecamp_token , 'X' , true)
#Work out company id from company name
company = Basecamp::Company.find(:all).select { |c| c.attributes["name"] == opts[:company] }
company_id = company[0].instance_variable_get("@attributes")["id"]
people = Basecamp::Person.find(:all, :params => {:company_id => company_id })
#ap people
#todo work out how to iterate over all people
puts people[0].instance_variable_get("@attributes")["email_address"]