Class: Reddit::Comment

Inherits:
Api
  • Object
show all
Includes:
JsonListing
Defined in:
lib/ruby_reddit_api/comment.rb

Instance Attribute Summary collapse

Attributes inherited from Api

#last_action

Instance Method Summary collapse

Methods included from JsonListing

included

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

#authorObject (readonly)

Returns the value of attribute author.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def author
  @author
end

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def body
  @body
end

#body_htmlObject (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

#createdObject (readonly)

Returns the value of attribute created.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def created
  @created
end

#created_utcObject (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

#debugObject (readonly)

Returns the value of attribute debug.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def debug
  @debug
end

#downsObject (readonly)

Returns the value of attribute downs.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def downs
  @downs
end

#kindObject (readonly)

Returns the value of attribute kind.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def kind
  @kind
end

#likesObject (readonly)

Returns the value of attribute likes.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def likes
  @likes
end

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

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def name
  @name
end

#parent_idObject (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

#repliesObject (readonly)

Returns the value of attribute replies.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def replies
  @replies
end

#subredditObject (readonly)

Returns the value of attribute subreddit.



4
5
6
# File 'lib/ruby_reddit_api/comment.rb', line 4

def subreddit
  @subreddit
end

#subreddit_idObject (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

#upsObject (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_distinguishObject



50
51
52
# File 'lib/ruby_reddit_api/comment.rb', line 50

def admin_distinguish
  add_distinction "admin"
end

#approveObject



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

#downvoteObject



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

#hideObject

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

#idObject



14
15
16
# File 'lib/ruby_reddit_api/comment.rb', line 14

def id
  "#{kind}_#{@id}"
end

#indistinguishObject



54
55
56
# File 'lib/ruby_reddit_api/comment.rb', line 54

def indistinguish
  add_distinction "no"
end

#inspectObject



10
11
12
# File 'lib/ruby_reddit_api/comment.rb', line 10

def inspect
  "<Reddit::Comment author='#{@author}' body='#{short_body}'>"
end

#moderator_distinguishObject



46
47
48
# File 'lib/ruby_reddit_api/comment.rb', line 46

def moderator_distinguish
  add_distinction "yes"
end

#removeObject



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_bodyObject



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_sObject



22
23
24
# File 'lib/ruby_reddit_api/comment.rb', line 22

def to_s
  body
end

#upvoteObject



63
64
65
# File 'lib/ruby_reddit_api/comment.rb', line 63

def upvote
  Vote.new(self).up
end