class NeonRAW::Objects::Submission

The submission object. @!attribute [r] archived?

@return [Boolean] Returns whether or not the submission is archived.

@!attribute [r] author

@return [String] Returns the author of the submission.

@!attribute [r] author_flair_css_class

@return [String, nil] Returns the CSS class of the submitter's flair or
  nil if there is none.

@!attribute [r] author_flair_text

@return [String, nil] Returns the flair's text of the submitter's flair
  or nil if there is none.

@!attribute [r] clicked?

@return [Boolean] Returns whether or not the submission has been
  "clicked".

@!attribute [r] domain

@return [String] Returns the domain of the submitted item.

@!attribute [r] hidden?

@return [Boolean] Returns whether or not you hid the submission.

@!attribute [r] selfpost?

@return [Boolean] Returns whether or not the submission is a selfpost.

@!attribute [r] link_flair_css_class

@return [String, nil] Returns the CSS class for the submission's link
  flair or nil if there is none.

@!attribute [r] link_flair_text

@return [String, nil] Returns the Link flair's text or nil if there is
  none.

@!attribute [r] locked?

@return [Boolean] Returns whether or not the submission is locked.

@!attribute [r] media

@return [Hash, nil] Returns an object containing information about a
  video and its origins or nil if there is none.

@!attribute [r] media_embed

@return [Hash, nil] Returns an object containing technical embed
  information or nil if there is none.

@!attribute [r] num_comments

@return [Integer] Returns the number of comments in the submission.

@!attribute [r] nsfw?

@return [Boolean] Returns whether or not the post is flagged as NSFW.

@!attribute [r] permalink

@return [String] Returns the permalink of the submission.

@!attribute [r] saved?

@return [Boolean] Returns whether or not you saved the submission.

@!attribute [r] score

@return [Integer] Returns the submission's karma score.

@!attribute [r] selftext

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

@!attribute [r] selftext_html

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

@!attribute [r] subreddit

@return [String] Returns the subreddit the submission was posted to.

@!attribute [r] subreddit_id

@return [String] Returns the ID of the subreddit where the submission
  was posted to.

@!attribute [r] thumbnail

@return [String, nil] Returns the URL to the thumbnail of the post or
  nil if there is none.

@!attribute [r] title

@return [String] Returns the title of the submission.

@!attribute [r] url

@return [String] Either the URL submitted (link post) or the
  submission's permalink (selfpost).

Public Class Methods

new(client, data) click to toggle source

@!method initialize(client, data) @param client [NeonRAW::Clients::Web/Installed/Script] The client

object.

@param data [Hash] The object data.

# File lib/NeonRAW/objects/submission.rb, line 88
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)
    if key == :permalink
      instance_variable_set(:"@#{key}", 'https://www.reddit.com' + value)
    else
      instance_variable_set(:"@#{key}", value)
    end
    next if %i[created created_utc].include?(key)
    self.class.send(:attr_reader, key)
  end
  class << self
    alias_method :clicked?, :clicked
    alias_method :hidden?, :hidden
    alias_method :selfpost?, :is_self
    alias_method :locked?, :locked
    alias_method :nsfw?, :over_18
    alias_method :saved?, :saved
    alias_method :archived?, :archived
    alias_method :add_comment, :reply
  end
end

Public Instance Methods

comment?() click to toggle source

Checks whether or not this is a comment. @!method comment? @return [Boolean] Returns false.

# File lib/NeonRAW/objects/submission.rb, line 139
def comment?
  false
end
comments() click to toggle source

Fetches the comments for a submission. @!method comments @return [Array] Returns an array full of Comments and MoreComments

objects.
# File lib/NeonRAW/objects/submission.rb, line 147
def comments
  data = @client.request_data("/comments/#{id}", :get)
  data_arr = []
  data[1][:data][:children].each do |comment|
    if comment[:kind] == 't1'
      data_arr << Comment.new(@client, comment[:data])
    elsif comment[:kind] == 'more'
      data_arr << MoreComments.new(@client, comment[:data])
    end
  end
  data_arr
end
contest_mode(enable) click to toggle source

Set contest mode on or off. @!method contest_mode(enable) @param enable [Boolean] Turns it on or off.

# File lib/NeonRAW/objects/submission.rb, line 224
def contest_mode(enable)
  params = { api_type: 'json', id: name, state: enable }
  @client.request_data('/api/set_contest_mode', :post, params)
end
duplicates(params = { limit: 25 }) click to toggle source

Fetches duplicates for the submission. @!method duplicates(params = { limit: 25 }) @param params [Hash] Optional parameters. @option :after [String] The fullname of the next data block. @option :before [String] The fullname of the previous data block. @option :count [Integer] The number of posts already in the listing. @option :limit [1..1000] The number of listing items to fetch. @option :show [String] Literally the string 'all'. @return [NeonRAW::Objects::Listing] Returns the listing with all the

duplicate submissions.
# File lib/NeonRAW/objects/submission.rb, line 170
def duplicates(params = { limit: 25 })
  params[:sr_detail] = false
  data_arr = []
  until data_arr.length == params[:limit]
    data = @client.request_data("/duplicates/#{id}", :get, params)
    params[:after] = data[1][:data][:after]
    params[:before] = data[1][:data][:before]
    data[1][:data][:children].each do |submission|
      data_arr << Submission.new(@client, submission[:data])
      break if data_arr.length == params[:limit]
    end
    break if params[:after].nil?
  end
  listing = Listing.new(params[:after], params[:before])
  data_arr.each { |submission| listing << submission }
  listing
end
flair?() click to toggle source

Checks whether or not the submission has flair. @!method flair? @return [Boolean] Returns whether or not the submission has flair.

# File lib/NeonRAW/objects/submission.rb, line 125
def flair?
  !@link_flair_text.nil? || !@link_flair_css_class.nil?
end
inbox_replies(enable) click to toggle source

Toggle getting inbox replies from the submission. @!method inbox_replies(enable) @param enable [Boolean] Turns it on or off.

# File lib/NeonRAW/objects/submission.rb, line 216
def inbox_replies(enable)
  params = { id: name, state: enable }
  @client.request_data('/api/sendreplies', :post, params)
end
linkpost?() click to toggle source

Checks whether or not the submission is a link post. @!method linkpost? @return [Boolean] Returns whether or not the submission is a link post.

# File lib/NeonRAW/objects/submission.rb, line 118
def linkpost?
  !@is_self
end
sticky(enable) click to toggle source

Sticky a submission/comment. @!method sticky(enable) @param enable [Boolean] Stickies/unstickies the thing.

# File lib/NeonRAW/objects/submission.rb, line 241
def sticky(enable)
  params = { api_type: 'json', id: name, state: enable }
  @client.request_data('/api/set_subreddit_sticky', :post, params)
end
submission?() click to toggle source

Checks whether or not this is a submission. @!method submission? @return [Boolean] Returns true.

# File lib/NeonRAW/objects/submission.rb, line 132
def submission?
  true
end
suggested_sort(sort) click to toggle source

Sets the suggested sort for a submission. @!method suggested_sort(sort) @param sort [Symbol] The sort to set [confidence, top, new,

controversial, old, random, qa]
# File lib/NeonRAW/objects/submission.rb, line 233
def suggested_sort(sort)
  params = { api_type: 'json', id: name, sort: sort }
  @client.request_data('/api/set_suggested_sort', :post, params)
end