Question

I've been unable to work with an object within code triggered from a Resque worker. This is a sinatra/datamapper app. The Feed class is a DataMapper model. Here's the Subscriber code

class Subscriber
  @queue = :subscriptions_queue

  def self.perform(feed_id)
    feed = Feed.get(feed_id)
    feed.subscribe()
  end
end

Working well, up until the subscribe() method executes

class Feed
  def subscribe    
    feed = Feedzirra::Feed.fetch_and_parse(url)
    raise feed.description
  end
end

Which results in an error:

** [23:09:44 2012-08-02] 32028: (Job{subscriptions_queue} | Subscriber | [2]) failed: #<NoMethodError: undefined method `description' for #<Hash:0x007fa6f4b97e48>>

Why would that be a hash? I can call inspect on the feed object:

class Feed
  def subscribe    
    feed = Feedzirra::Feed.fetch_and_parse(url)
    raise feed.inspect
  end
end

which dumps the feed as one would expect:

** [23:01:31 2012-08-02] 32010: (Job{subscriptions_queue} | Subscriber | [2]) failed: #<RuntimeError: {#<Addressable::URI:0x3fefd45f2fb8 URI:http://feeds.feedburner.com/scoutapp>=>#<Feedzirra::Parser::RSSFeedBurner:0x007fdfaa024f18 @title="Scout ~ The Blog", @url="http://blog.scoutapp.com/", @description="Scout ~ The Blog", @hubs=["http://pubsubhubbub.appspot.com/"], @entries=

See any areas to look at?

Was it helpful?

Solution

It's actually an hash with a pair of Addressable::URI => Feedzirra::Parser::RSSFeedBurner

if you don't know how to get that URI object just do feed[feed.keys[0]].description or feed.values[0]

Also checking the github repo it seems you should have a entries method. This happens if you are fetching from the root url. So you might be able to do feeds.entries.first if you only want to get the first.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top