samsymons / RedditKit.rb

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

Can I use this gem to fetch a users latest comment? #5

Closed sergiotapia closed 10 years ago

sergiotapia commented 10 years ago

My use case is quite simple, I just need to fetch the latest comments given a user.

For example:

user = RedditKit.user 'foobar'
user.comments.each do |comment|
  puts #{comment.body} - #{comment.post_date}
end

Is this possible at the moment, I couldn't seem to find anything related to Comments in the source code.

BukhariH commented 10 years ago

There's something like this exactly in the examples! So, we have your back!

You can achieve exactly what you're looking for by:

comments = RedditKit.user_content 'PresidentObama', :category => :comments

comments.each do |comment|
  puts "The comment '#{comment.text}' was posted at #{comment.posted_at}."
end

That is what you were looking for?

sergiotapia commented 10 years ago

I don't know how I missed that, let's chalk it up to 3am coding. :)

I had already written a Nokogiri based parsing solution but I assume this will be much quicker. Is this library only parsing JSON comments? That would be significantly quicker than my HTML scraping solution.

samsymons commented 10 years ago

Yeah, RedditKit uses reddit's JSON API for comments and parses them using multi_json, so it's pretty speedy.

sergiotapia commented 10 years ago

Thank you, I'll change my ruby code to use this lib and submit a pull request to show this example on the README.md file.