class NeonRAW::Objects::MultiReddit

The multireddit object. @!attribute [r] editable?

@return [Boolean] Returns whether or not you can edit the multireddit.

@!attribute [r] display_name

@return [String] Returns the display name of the multireddit.

@!attribute [r] name

@return [String] Returns the name of the multireddit.

@!attribute [r] description_html

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

@!attribute [r] copied_from

@return [String, nil] Returns where the multireddit was copied from or
  nil if it wasn't copied.

@!attribute [r] icon_url

@return [String, nil] Returns the icon URL of the multireddit or nil if
  there is none.

@!attribute [r] key_color

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

@!attribute [r] visibility

@return [String] Returns the visibility status of the multireddit
  [public, private, hidden].

@!attribute [r] icon_name

@return [String, nil] Returns the name of the icon or nil if there is
  none ['art and design', 'ask', 'books', 'business', 'cars',
  'comics', 'cute animals', 'diy', 'entertainment', 'food and drink',
  'funny', 'games', 'grooming', 'health', 'life advice', 'military',
  'models pinup', 'music', 'news', 'philosophy', 'pictures and gifs',
  'science', 'shopping', 'sports', 'style', 'tech', 'travel',
  'unusual stories', 'video', '', 'None'].

@!attribute [r] weighting_scheme

@return [String] Returns the weighting scheme for the multireddit
  [classic, fresh].

@!attribute [r] path

@return [String] Returns the path to the multireddit.

@!attribute [r] description

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

Public Class Methods

new(client, data) click to toggle source
# File lib/NeonRAW/objects/multireddit.rb, line 46
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 subreddits].include?(key)
    self.class.send(:attr_reader, key)
  end
  class << self
    alias_method :editable?, :can_edit
    alias_method :description, :description_md
  end
end

Public Instance Methods

add_subreddit(subreddit) click to toggle source

Adds a subreddit to the multireddit. @!method add_subreddit(subreddit) @param subreddit [String] The name of the subreddit to add.

# File lib/NeonRAW/objects/multireddit.rb, line 118
def add_subreddit(subreddit)
  params = { model: { 'name' => subreddit }.to_json, multipath: path,
             srname: subreddit }
  api_path = "/api/multi/#{path}/r/#{subreddit}"
  @client.request_data(api_path, :put, params)
  @subreddits << { name: subreddit }
end
copy(opts = {}) click to toggle source

Copy the multireddit. @!method copy(opts = {}) @param opts [Hash] Optional parameters. @option opts :name [String] The new name of the multireddit. Defaults to

the name of the original copy.

@return [NeonRAW::Objects::MultiReddit] Returns the new object.

# File lib/NeonRAW/objects/multireddit.rb, line 77
def copy(opts = {})
  params = { display_name: display_name, from: path,
             to: "/user/#{@client.me.name}/m/" }
  params[:to] += opts[:name] || display_name
  data = @client.request_data('/api/multi/copy', :post, params)
  MultiReddit.new(@client, data[:data])
end
delete!() click to toggle source

Deletes the multireddit. @!method delete!

# File lib/NeonRAW/objects/multireddit.rb, line 98
def delete!
  @client.request_nonjson("/api/multi/#{path}", :delete)
end
edit(data) click to toggle source

Edit the multireddit. @!method edit(data) @param data [JSON] The data for the multireddit. @see www.reddit.com/dev/api#PUT_api_multi_{multipath}

# File lib/NeonRAW/objects/multireddit.rb, line 106
def edit(data)
  params = { model: data, multipath: path, expand_srs: false }
  data = @client.request_data("/api/multi/#{path}", :put, params)
  data[:data].each do |key, value|
    value = nil if ['', [], {}].include?(value)
    instance_variable_set(:"@#{key}", value)
  end
end
remove_subreddit(subreddit) click to toggle source

Remove a subreddit from the multireddit. @!method remove_subreddit(subreddit) @param subreddit [String] The name of the subreddit to remove.

# File lib/NeonRAW/objects/multireddit.rb, line 129
def remove_subreddit(subreddit)
  params = { multipath: path, srname: subreddit }
  api_path = "/api/multi/#{path}/r/#{subreddit}"
  @client.request_nonjson(api_path, :delete, params)
  @subreddits.delete(name: subreddit)
end
rename!(new_name) click to toggle source

Renames the multireddit. @!method rename!(new_name) @param new_name [String] The new name for the multireddit. @return [NeonRAW::objects::MultiReddit] Returns the multireddit object.

# File lib/NeonRAW/objects/multireddit.rb, line 89
def rename!(new_name)
  params = { display_name: new_name, from: path,
             to: "/user/#{@client.me.name}/m/#{new_name}" }
  data = @client.request_data('/api/multi/rename', :post, params)
  MultiReddit.new(@client, data[:data])
end
subreddits() click to toggle source

Fetches a list of subreddits in the multireddit. @!method subreddits @return [Array<String>] Returns a list of subreddit display_names.

# File lib/NeonRAW/objects/multireddit.rb, line 66
def subreddits
  subreddits = @subreddits || []
  subreddits.map { |subreddit| subreddit[:name] }
end