开发者

Parsing file or streaming input with feedzirra

开发者 https://www.devze.com 2023-03-08 12:56 出处:网络
开发者_开发问答I\'ve to \"parse\" a Rails \"request.body\" on the fly, something like : feed = Feedzirra::Feed.parse(request.body.read)
开发者_开发问答

I've to "parse" a Rails "request.body" on the fly, something like :

  feed = Feedzirra::Feed.parse(request.body.read)
  feed.entries do |entry|
    entry.title      # => "Ruby Http Client Library Performance"
    entry.url        # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
    entry.author     # => "Paul Dix"
    entry.summary    # => "..."
    entry.content    # => "..."
    entry.published  # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
    entry.categories # => ["...", "..."]
  end

Is it possible? Should be similar to get a streaming input or reading from a file, don't you think so?


... the code was right, as well as the way of parsing, what I missed was the "output" ;-)

Adding "puts", I get the values on the fly ( while I'm getting http POST into "request.body" ):

feed = Feedzirra::Feed.parse(request.body.read)
  feed.entries.each do |entry|
    puts entry.title      # => "Ruby Http Client Library Performance"
    puts entry.url        # => "http://www.pauldix.net/2009/01/ruby-http-client-library-performance.html"
    puts entry.author     # => "Paul Dix"
    puts entry.summary    # => "..."
    puts entry.content    # => "..."
    puts entry.published  # => Thu Jan 29 17:00:19 UTC 2009 # it's a Time object
    puts entry.categories # => ["...", "..."]
  end

Thanks Christopher Manning for suggestions ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号