class NeonRAW::Objects::PrivateMessage

The private message object. @!attribute [r] author

@return [String] Returns the author of the private message.

@!attribute [r] body

@return [String, nil] Returns the PM text body or nil if there is none.

@!attribute [r] was_comment?

@return [Boolean] Returns whether or not the object was a comment first.

@!attribute [r] first_message

@return [String, nil] Returns the first message ID or nil if there was
  none.

@!attribute [r] dest

@return [String] Returns the user whom the PM was sent to.

@!attribute [r] body_html

@return [String, nil] Returns the text body with HTML or nil if there
  is none.

@!attribute [r] subreddit

@return [String, nil] Returns the subreddit it was sent from or nil if
  it wasn't a comment.

@!attribute [r] context

@return [String, nil] Returns the comment permalink with context or nil
  if it wasn't a comment.

@!attribute [r] new?

@return [Boolean] Returns whether or not the message is unread.

@!attribute [r] subject

@return [String] Returns the subject of the PM.

Public Class Methods

new(client, data) click to toggle source
# File lib/NeonRAW/objects/privatemessage.rb, line 36
def initialize(client, data)
  @client = client
  data.each do |key, value|
    # for consistency, empty strings/arrays/hashes are set to nil
    # because most of the keys returned by Reddit are nil when they
    # don't have a value, besides a few
    value = nil if ['', [], {}].include?(value)
    instance_variable_set(:"@#{key}", value)
    next if %i[created created_utc replies].include?(key)
    self.class.send(:attr_reader, key)
  end
  class << self
    alias_method :was_comment?, :was_comment
  end
end

Public Instance Methods

block!() click to toggle source

Block a user. @!method block!

# File lib/NeonRAW/objects/privatemessage.rb, line 67
def block!
  params = { id: name }
  @client.request_data('/api/block', :post, params)
end
replies() click to toggle source

Creates a list of replies to a private message. @!method replies @return [Array<NeonRAW::Objects::PrivateMessage>] Returns a list of

replies.
# File lib/NeonRAW/objects/privatemessage.rb, line 56
def replies
  return nil if @replies.nil?
  messages = []
  @replies[:data][:children].each do |reply|
    messages << PrivateMessage.new(@client, reply[:data])
  end
  messages
end