Class: Reddit::Comment
- Includes:
- JsonListing
- Defined in:
- lib/ruby_reddit_api/comment.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_html ⇒ Object
readonly
Returns the value of attribute body_html.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#created_utc ⇒ Object
readonly
Returns the value of attribute created_utc.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#downs ⇒ Object
readonly
Returns the value of attribute downs.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#likes ⇒ Object
readonly
Returns the value of attribute likes.
-
#link_id ⇒ Object
readonly
Returns the value of attribute link_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_id ⇒ Object
readonly
Returns the value of attribute parent_id.
-
#replies ⇒ Object
readonly
Returns the value of attribute replies.
-
#subreddit ⇒ Object
readonly
Returns the value of attribute subreddit.
-
#subreddit_id ⇒ Object
readonly
Returns the value of attribute subreddit_id.
-
#ups ⇒ Object
readonly
Returns the value of attribute ups.
Attributes inherited from Api
Instance Method Summary collapse
- #add_distinction(verb) ⇒ Object
- #admin_distinguish ⇒ Object
- #approve ⇒ Object
- #downvote ⇒ Object
- #edit(newtext) ⇒ Object
-
#hide ⇒ Object
soft delete?.
- #id ⇒ Object
- #indistinguish ⇒ Object
-
#initialize(json) ⇒ Comment
constructor
A new instance of Comment.
- #inspect ⇒ Object
- #moderator_distinguish ⇒ Object
- #remove ⇒ Object
- #reply(text) ⇒ Object
- #short_body ⇒ Object
- #to_s ⇒ Object
- #upvote ⇒ Object
Methods included from JsonListing
Methods inherited from Api
#browse, #comments, #post_replies, #received_messages, #sent_messages
Constructor Details
#initialize(json) ⇒ Comment
Returns a new instance of Comment.
5 6 7 8 |
# File 'lib/ruby_reddit_api/comment.rb', line 5 def initialize(json) parse(json) @debug = StringIO.new end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def @author end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def body @body end |
#body_html ⇒ Object (readonly)
Returns the value of attribute body_html.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def body_html @body_html end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def created @created end |
#created_utc ⇒ Object (readonly)
Returns the value of attribute created_utc.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def created_utc @created_utc end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def debug @debug end |
#downs ⇒ Object (readonly)
Returns the value of attribute downs.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def downs @downs end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def kind @kind end |
#likes ⇒ Object (readonly)
Returns the value of attribute likes.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def likes @likes end |
#link_id ⇒ Object (readonly)
Returns the value of attribute link_id.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def link_id @link_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def name @name end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def parent_id @parent_id end |
#replies ⇒ Object (readonly)
Returns the value of attribute replies.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def replies @replies end |
#subreddit ⇒ Object (readonly)
Returns the value of attribute subreddit.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def subreddit @subreddit end |
#subreddit_id ⇒ Object (readonly)
Returns the value of attribute subreddit_id.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def subreddit_id @subreddit_id end |
#ups ⇒ Object (readonly)
Returns the value of attribute ups.
4 5 6 |
# File 'lib/ruby_reddit_api/comment.rb', line 4 def ups @ups end |
Instance Method Details
#add_distinction(verb) ⇒ Object
80 81 82 83 84 |
# File 'lib/ruby_reddit_api/comment.rb', line 80 def add_distinction(verb) resp=self.class.post("/api/distinguish/#{verb}", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "distinguishing..."}, :headers => base_headers, :debug_output => @debug }) puts resp.headers resp.code == 200 end |
#admin_distinguish ⇒ Object
50 51 52 |
# File 'lib/ruby_reddit_api/comment.rb', line 50 def admin_distinguish add_distinction "admin" end |
#approve ⇒ Object
41 42 43 44 |
# File 'lib/ruby_reddit_api/comment.rb', line 41 def approve resp=self.class.post("/api/approve", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#downvote ⇒ Object
67 68 69 |
# File 'lib/ruby_reddit_api/comment.rb', line 67 def downvote Vote.new(self).down end |
#edit(newtext) ⇒ Object
26 27 28 29 |
# File 'lib/ruby_reddit_api/comment.rb', line 26 def edit(newtext) resp=self.class.post("/api/editusertext", {:body => {:thing_id => id, :uh => modhash, :r => subreddit, :text => newtext }, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#hide ⇒ Object
soft delete?
31 32 33 34 |
# File 'lib/ruby_reddit_api/comment.rb', line 31 def hide # soft delete? resp=self.class.post("/api/del", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "removed" }, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#id ⇒ Object
14 15 16 |
# File 'lib/ruby_reddit_api/comment.rb', line 14 def id "#{kind}_#{@id}" end |
#indistinguish ⇒ Object
54 55 56 |
# File 'lib/ruby_reddit_api/comment.rb', line 54 def indistinguish add_distinction "no" end |
#inspect ⇒ Object
10 11 12 |
# File 'lib/ruby_reddit_api/comment.rb', line 10 def inspect "<Reddit::Comment author='#{@author}' body='#{short_body}'>" end |
#moderator_distinguish ⇒ Object
46 47 48 |
# File 'lib/ruby_reddit_api/comment.rb', line 46 def moderator_distinguish add_distinction "yes" end |
#remove ⇒ Object
36 37 38 39 |
# File 'lib/ruby_reddit_api/comment.rb', line 36 def remove resp=self.class.post("/api/remove", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#reply(text) ⇒ Object
58 59 60 61 |
# File 'lib/ruby_reddit_api/comment.rb', line 58 def reply(text) resp = self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#short_body ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/ruby_reddit_api/comment.rb', line 71 def short_body str = body.to_s if str.size > 15 str[0..15] + "..." else body end end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/ruby_reddit_api/comment.rb', line 22 def to_s body end |