class NeonRAW::Objects::Subreddit
The subreddit object. @!attribute [r] subscribed?
@return [Boolean] Returns whether or not you're subscribed to the subreddit.
@!attribute [r] approved_submitter?
@return [Boolean] Returns whether or not you're an approved submitter to the subreddit.
@!attribute [r] moderator?
@return [Boolean] Returns whether or not you're a moderator of the subreddit.
@!attribute [r] im_banned?
@return [Boolean] Returns whether or not you're banned from the subreddit.
@!attribute [r] collapse_deleted_comments?
@return [Boolean] Returns whether or not the subreddit collapses deleted comments.
@!attribute [r] nsfw?
@return [Boolean] Returns whether or not the subreddit is marked for adult content.
@!attribute [r] muted?
@return [Boolean] Returns whether or not you're muted from the subreddit's modmail.
@!attribute [r] quarantined?
@return [Boolean] Returns whether or not the subreddit is quarantined.
@!attribute [r] public_traffic?
@return [Boolean] Returns whether or not the subreddit made their traffic stats public.
@!attribute [r] theme_enabled?
@return [Boolean] Returns whether or not you have the subreddit theme enabled.
@!attribute [r] wiki_enabled?
@return [Boolean] Returns whether or not the subreddit has its wiki enabled.
@!attribute [r] hide_ads?
@return [Boolean] Returns whether or not the subreddit hides ads.
@!attribute [r] banner_img
@return [String, nil] Returns a string container a link to the banner image or nil if there is none.
@!attribute [r] submit_text_html
@return [String, nil] Returns the text with HTML included in the thread submission page or nil if there is none..
@!attribute [r] submit_text
@return [String, nil] Returns the text included in the thread submission page or nil if there is none.
@!attribute [r] display_name
@return [String] Returns the display name of the subreddit.
@!attribute [r] header_img
@return [String, nil] Returns the link to the header image or nil if there is none.
@!attribute [r] sidebar_html
@return [String, nil] Returns the subreddit's sidebar text with HTML or nil if there is none..
@!attribute [r] title
@return [String] Returns the subreddit's title.
@!attribute [r] public_description
@return [String, nil] Returns the subreddit's public description or nil if there is none..
@!attribute [r] public_description_html
@return [String, nil] Returns the subreddit's public description with HTML included or nil if there is none.
@!attribute [r] suggested_comment_sort
@return [String, nil] Returns the subreddit's suggested comment sort or nil if there isn't one [hot, top, new, old, controversial, random]
@!attribute [r] submit_link_label
@return [String, nil] Returns the subreddit's custom label for the submit link button or nil if there is none.
@!attribute [r] submit_text_label
@return [String, nil] Returns the subreddit's custom label for the submit text button or nil if there is none.
@!attribute [r] header_title
@return [String, nil] Returns the header title or nil if there is none.
@!attribute [r] sidebar
@return [String] Returns the subreddit's sidebar text.
@!attribute [r] accounts_active
@return [Integer] Returns the number of users online browsing the subreddit.
@!attribute [r] header_size
@return [Array<Integer, Integer>, nil] Returns an array containing the header's dimensions or nil if there isn't one.
@!attribute [r] subscribers
@return [Integer] Returns the number of subscribers the subreddit has.
@!attribute [r] lang
@return [String] Returns the subreddit's primary language.
@!attribute [r] url
@return [String] Returns the subreddit's URL.
@!attribute [r] comment_score_hide_mins
@return [Integer] Returns the number of minutes that comment scores are hidden.
@!attribute [r] subreddit_type
@return [String] Returns the type of subreddit [public, restricted, private, gold_restricted, archived].
@!attribute [r] submission_type
@return [String] Returns the type of submissions allowed to be posted [any, link, self].
Public Class Methods
@!method initialize(client, data) @param client [NeonRAW::Clients::Web/Installed/Script] The client. @param data [Hash] The object data.
# File lib/NeonRAW/objects/subreddit.rb, line 124 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].include?(key) self.class.send(:attr_reader, key) end class << self alias_method :subscribed?, :user_is_subscriber alias_method :approved_submitter?, :user_is_contributor alias_method :moderator?, :user_is_moderator alias_method :im_banned?, :user_is_banned alias_method :collapses_deleted_comments?, :collapse_deleted_comments alias_method :nsfw?, :over18 alias_method :muted?, :user_is_muted alias_method :quarantined?, :quarantine alias_method :public_traffic?, :public_traffic alias_method :theme_enabled?, :user_sr_theme_enabled alias_method :wiki_enabled?, :wiki_enabled alias_method :hide_ads?, :hide_ads alias_method :sidebar, :description alias_method :sidebar_html, :description_html end end
Public Instance Methods
Fetches the subreddit's rules. @!method rules @return [Array<NeonRAW::Objects::Rule>] Returns a list of the rules.
# File lib/NeonRAW/objects/subreddit.rb, line 156 def rules data = @client.request_data("/r/#{display_name}/about/rules", :get) data[:rules].map { |rule| Rule.new(@client, rule) } end
Search for links in the subreddit. @!method search(query, opts = { limit: 25 }) @param query [String] The text to search for (512 characters maximum). @param opts [Hash] Optional parameters. @option opts :after [String] Fullname of the next data block. @option opts :before [String] Fullname of the previous data block. @option opts :count [Integer] Number of items already in the listing. @option opts :include_facets [Boolean] Whether or not to include facets. @option opts :limit [1..1000] The number of listing items to fetch. @option opts :show [String] Literally the string 'all'. @option opts :sort [String] The sort of the data [relevance, hot, top,
new, comments].
@option opts :syntax [String] The type of search you want [cloudsearch,
lucene, plain]
@option opts :t [String] Time for relevant sorting [hour, day, week,
month, year, all]
# File lib/NeonRAW/objects/subreddit.rb, line 211 def search(query, opts = { limit: 25 }) params = opts params[:q] = query params[:restrict_sr] = true params[:sr_detail] = false params[:type] = 'link' @client.send(:build_listing, "/r/#{display_name}/search", params) end
Fetches the subreddit's stylesheet. @!method stylesheet @return [Hash<Array, String, String>] Returns the stylesheet data.
# File lib/NeonRAW/objects/subreddit.rb, line 164 def stylesheet path = "/r/#{display_name}/about/stylesheet" @client.request_data(path, :get)[:data] end