I'm trying to update code for importing trello cards to asana, and I had to update to the latest asana gem https://github.com/Asana/ruby-asana.
Now I'm getting this error when I'm trying to access a collection item by index.
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>'
What is the correct syntax for accessing a Asana::Resources::Collection by index?
client = Asana::Client.new do |c|
c.authentication :access_token, PERSONAL_ACCESS_TOKEN
end
workspaces = client.workspaces.find_all
workspace = workspaces[0]
As you mentioned in the README.md the library will return a Asana::Resources::Collection for API responses containing multiple elements and/or multiple pages.
Among other things the collection is an Enumerable and will expose the Enumerable API.
There are several ways to iterate through the elements of the collection or to grab specific elements of the collection:
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>
There are also several examples including one using the personal access token to iterate over the workspaces available