garb icon indicating copy to clipboard operation
garb copied to clipboard

Requesting list of segments raises TypeError exception

Open jwtd opened this issue 12 years ago • 1 comments

Using: Ruby 1.9.3 garb 0.9.1

Running sample code from: https://github.com/vigetlabs/garb/wiki/Segments which is...

Garb::Management::Segment.all.each {|segment| puts "#{segment.id}:#{segment.name} => #{segment.definition}"}

Raises a TypeError exception...

/Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb.rb:67:in `[]': can't convert String into Integer (TypeError)
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb.rb:67:in `block in parse_link'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb.rb:67:in `each'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb.rb:67:in `detect'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb.rb:67:in `parse_link'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb/management/segment.rb:15:in `new_from_entry'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb/management/segment.rb:9:in `block in all'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb/management/segment.rb:9:in `map'
from /Users/jd/.rvm/gems/[email protected]/gems/garb-0.9.1/lib/garb/management/segment.rb:9:in `all'

jwtd avatar Mar 09 '12 17:03 jwtd

This monkey patch got me past the issues...

module Garb
  def parse_link(entry, rel)
    if entry['link'].is_a?(Array)
      entry['link'].detect {|link| link["rel"] == rel}['href']
    else
      entry['link']['href']
    end
  end
end

jwtd avatar Mar 09 '12 17:03 jwtd