Class: Reddit::Message
- Includes:
- JsonListing
- Defined in:
- lib/ruby_reddit_api/message.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#body_html ⇒ Object
readonly
Returns the value of attribute body_html.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#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.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#first_message ⇒ Object
readonly
Returns the value of attribute first_message.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#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.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#subreddit ⇒ Object
readonly
Returns the value of attribute subreddit.
-
#was_comment ⇒ Object
readonly
Returns the value of attribute was_comment.
Attributes inherited from Base
Instance Method Summary collapse
-
#author ⇒ Reddit::User
The author of the message.
-
#id ⇒ String
The reddit ID of this message.
-
#initialize(json) ⇒ Message
constructor
A new instance of Message.
- #inspect ⇒ Object
- #mark_read ⇒ Object
- #mark_unread ⇒ Object
- #read? ⇒ Boolean
-
#reply(text) ⇒ true, false
Reply to this message.
-
#short_body ⇒ String
Trimmed comment body suitable for #inspect.
- #unread? ⇒ Boolean
Methods included from JsonListing
Methods inherited from Thing
Methods inherited from Base
base_headers, #base_headers, #cookie, #logged_in?, #login, #logout, #modhash, #read, #user, #user_agent, user_agent, #user_id
Constructor Details
#initialize(json) ⇒ Message
Returns a new instance of Message.
7 8 9 10 |
# File 'lib/ruby_reddit_api/message.rb', line 7 def initialize(json) parse(json) @debug = StringIO.new end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def body @body end |
#body_html ⇒ Object (readonly)
Returns the value of attribute body_html.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def body_html @body_html end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def context @context end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def created @created end |
#created_utc ⇒ Object (readonly)
Returns the value of attribute created_utc.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def created_utc @created_utc end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def debug @debug end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def dest @dest end |
#first_message ⇒ Object (readonly)
Returns the value of attribute first_message.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def @first_message end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def kind @kind end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def name @name end |
#parent_id ⇒ Object (readonly)
Returns the value of attribute parent_id.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def parent_id @parent_id end |
#replies ⇒ Object (readonly)
Returns the value of attribute replies.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def replies @replies end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def subject @subject end |
#subreddit ⇒ Object (readonly)
Returns the value of attribute subreddit.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def subreddit @subreddit end |
#was_comment ⇒ Object (readonly)
Returns the value of attribute was_comment.
6 7 8 |
# File 'lib/ruby_reddit_api/message.rb', line 6 def was_comment @was_comment end |
Instance Method Details
#author ⇒ Reddit::User
The author of the message. The data is lazy-loaded and cached on the message
28 29 30 |
# File 'lib/ruby_reddit_api/message.rb', line 28 def @author_data ||= read("/user/#{@author}/about.json", :handler => "User") end |
#id ⇒ String
The reddit ID of this message
14 15 16 |
# File 'lib/ruby_reddit_api/message.rb', line 14 def id "#{kind}_#{@id}" end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/ruby_reddit_api/message.rb', line 49 def inspect "<Reddit::Message '#{short_body}'>" end |
#mark_read ⇒ Object
44 45 46 47 |
# File 'lib/ruby_reddit_api/message.rb', line 44 def mark_read resp = self.class.post("/api/read_message", {:body => {:id => id, :uh => modhash }, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#mark_unread ⇒ Object
39 40 41 42 |
# File 'lib/ruby_reddit_api/message.rb', line 39 def mark_unread resp = self.class.post("/api/unread_message", {:body => {:id => id, :uh => modhash}, :headers => base_headers, :debug_output => @debug }) resp.code == 200 end |
#read? ⇒ Boolean
22 23 24 |
# File 'lib/ruby_reddit_api/message.rb', line 22 def read? @new == false end |
#reply(text) ⇒ true, false
Reply to this message
34 35 36 37 |
# File 'lib/ruby_reddit_api/message.rb', line 34 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 ⇒ String
Trimmed comment body suitable for #inspect
55 56 57 58 59 60 61 |
# File 'lib/ruby_reddit_api/message.rb', line 55 def short_body if body.size > 15 body[0..15] else body end end |
#unread? ⇒ Boolean
18 19 20 |
# File 'lib/ruby_reddit_api/message.rb', line 18 def unread? @new == true end |