samsymons / RedditKit.rb

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

Lots of undefined errors when trying to access attributes. #6

Closed sergiotapia closed 10 years ago

sergiotapia commented 10 years ago

I'm fetching the comments for a user:

  comments.each do |comment|
    if comment.subreddit == 'Foobar'
      post = Post.new(
          author: comment.author,
          body: comment.body_html,
          permalink: comment.name,
          post_date: comment.created
      )
      post.save!
    end
  end

And I'm getting undefined method for 'name' errors. And not only for name, also for ups and downs.

Using the RubyMine debugger I can see these properties values, yet I can't access them in code or in the Watches window. Is this a known bug?

sergiotapia commented 10 years ago

I can access them all using the comment.attributes[:name] notation. Odd, I wish there were some consistancy here.

samsymons commented 10 years ago

The voting properties use the RedditKit::Votable module. Although the actual attributes returned by reddit are named ups and downs, those are hidden in favor of the dedicated accessor methods in RedditKit::Votable.

As for the error with name, that's a similar situation; the full_name instance method gives you back the full name, even those the actual attribute from reddit is simply name.

The rationale behind it is that RedditKit should be a nice wrapper on top of reddit's API, hiding ugly or unclear attribute names behind simple accessors, while still providing access to the raw API data if needed.

I'll update the documentation tonight to better point this out; it's unclear from just reading the README, sorry about that!

Hopefully that helps!