2015-10-20 69 views
0

我正在嘗試更新用於將trello卡導入到體位的代碼,並且我不得不更新到最新的體式寶石https://github.com/Asana/ruby-asana如何通過索引訪問正式集合中的物品

現在,當我嘗試按索引訪問收集項目時,出現此錯誤。

exportTrelloToAsana.rb:63:in `block in <main>': undefined method `[]' for #<Asana::Resources::Collection:0x007fbba1d0d810> (NoMethodError) 
    from exportTrelloToAsana.rb:56:in `each' 
    from exportTrelloToAsana.rb:56:in `<main>' 

什麼是通過索引訪問嘉尚::資源::收集正確的語法?

client = Asana::Client.new do |c| 
    c.authentication :access_token, PERSONAL_ACCESS_TOKEN 
end 

workspaces = client.workspaces.find_all 
workspace = workspaces[0] 

回答

0

當您在README.md提到的庫將返回Asana::Resources::Collection包含多個元素和/或多個頁面的API響應。

其中的集合是Enumerable,並將公開Enumerable API。

有幾種方法通過集合中的元素進行迭代或搶收集的具體內容:

workspaces = client.workspaces.find_all 
workspaces.take(1) 
#<Asana::Workspace id: 1234, name: "Moon Landing"> 

workspaces.first  
#<Asana::Workspace id: 1234, name: "Moon Landing"> 

workspaces.each 
#<Enumerator:0x000001032df790> 

也有幾個examples使用個人訪問令牌包括一個iterate over the workspaces available