我已经设法使这几乎工作,但我认为我得到了一些严重的困惑。所有示例似乎都涵盖了根据其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"]
答案 0 :(得分:0)
事实证明:首先会按照我的意愿返回一家公司,但是我没有找到合乎逻辑的方法,因为我不想要第一个条目,我想要任何符合我的参数的条目..
#Work out company id from company name
company = Basecamp::Company.find(:first, :params => {:name => opts[:company] })
people = Basecamp::Person.find(:all, :params => {:company_id => company.id })
people.each do | person |
puts person.email_address
end