samsymons / RedditKit.rb

[Deprecated] A Ruby wrapper for the reddit API
https://redditkit.com/
MIT License
152 stars 26 forks source link

Client.comments() returns array with nil objects? #33

Open andreimarks opened 9 years ago

andreimarks commented 9 years ago

When iterating through comments to get all the replies in a tree, I often run into a problem where a nil object is returned as part of the initial comments array, and I'm fairly certain the top level list of comments isn't complete. It happens more frequently on links with > 200 comments.

Example code, in case I'm just missing something basic:

def iterate_through_replies( comment )
  replies = comment.replies
  if !replies.empty?
    replies.each do |r|
      iterate_through_replies( r )
    end
  end
end

link = RedditKit.link( some_full_name )
comments = RedditKit.comments( link.id )
comments.each do |c|
  iterate_through_replies( c ) 
end

At some point this error gets returned: in 'iterate_through_replies': undefined method 'replies' for nil:NilClass (NoMethodError)

Is a comment getting parsed weirdly? Maybe this is related to this PRAW issue?