module NeonRAW::Clients::Base::ObjectBuilder

Methods for building objects.

Constants

SUBREDDIT_DEFAULTS

Public Instance Methods

create_multireddit(data, multireddit_path) click to toggle source

Creates a multireddit. @!method create_multireddit(data, multireddit_path) @param data [JSON] The multireddit data. @param multireddit_path [String] The path to the multireddit (e.g.

/user/username/m/multireddit_name)

@return [NeonRAW::Objects::MultiReddit] Returns the multireddit

object.

@see www.reddit.com/dev/api#POST_api_multi_{multipath}

# File lib/NeonRAW/clients/base/objectbuilder.rb, line 92
def create_multireddit(data, multireddit_path)
  params = { model: data, multipath: multireddit_path,
             expand_srs: false }
  data = request_data("/api/multi/#{multireddit_path}", :post, params)
  Objects::MultiReddit.new(self, data[:data])
end
create_subreddit(name, title, description, opts = {}) click to toggle source

Creates a subreddit. @!method create_subreddit(name, title, description, opts = {}) @param name [String] The name of the subreddit. @param title [String] The title of the subreddit (100

characters maximum).

@param description [String] The sidebar text for the subreddit. @param opts [Hash] Optional parameters. @option opts allow_top [Boolean] Whether or not the subreddit can be

displayed on /r/all.

@option opts collapse_deleted_comments [Boolean] Whether or not to

collapse deleted comments.

@option opts comment_score_hide_mins [0..1440] The number of minutes

to hide comment scores.

@option opts exclude_banned_modqueue [Boolean] Whether or not to

exclude sitewide banned users from modqueue.

@option opts header-title [String] The title for the subreddit (500

characters maximum).

@option opts hide_ads [Boolean] Whether or not to hide ads in the

subreddit.

@option opts lang [String] The IETF language tags of the subreddit

separated by underscores.

@option opts link_type [String] The type of submissions allowed [any,

link, self].

@option opts over_18 [Boolean] Whether or not the subreddit is NSFW. @option opts public_description [String] The message that will get

shown to people when the subreddit is private.

@option opts public_traffic [Boolean] Whether or not the subreddit's

traffic stats are publicly available.

@option opts show_media [Boolean] Whether or not to show media. @option opts spam_comments [String] Set the spamfilter [low, high,

all].

@option opts spam_links [String] Set the spamfilter [low, high, all]. @option opts spam_selfposts [String] Set the spamfilter [low, high,

all].

@option opts submit_text_label [String] The label for the selfpost

button (60 characters maximum).

@option opts submit_text [String] The text to display when making a

selfpost.

@option opts submit_link_label [String] The label for the link button

(60 characters maximum).

@option opts suggested_comment_sort [String] The suggested comment

sort for the subreddit [confidence, top, new, controversial, old,
random, qa].

@option opts type [String] The subreddit type [gold_restricted,

archived, restricted, gold_only, employees_only, private, public].

@option opts wiki_edit_age [Integer] The minimum account age needed to

edit the wiki.

@option opts wiki_edit_karma [Integer] The minimum karma needed to

edit the wiki.

@option opts wikimode [String] The mode of the subreddit's wiki

[disabled, modonly, anyone].

@return [NeonRAW::Objects::Subreddit] Returns the subreddit object.

# File lib/NeonRAW/clients/base/objectbuilder.rb, line 151
def create_subreddit(name, title, description, opts = {})
  params = SUBREDDIT_DEFAULTS.dup
  params.merge! opts
  params['api_type'] = 'json'
  params['name'] = name
  params['title'] = title
  params['description'] = description
  request_data('/api/site_admin', :post, params)
  subreddit(name)
end
me() click to toggle source

Fetches yourself. @!method me @return [NeonRAW::Objects::Me] Returns the me object.

# File lib/NeonRAW/clients/base/objectbuilder.rb, line 67
def me
  data = request_data('/api/v1/me', :get)
  Objects::Me.new(self, data)
end
multireddit(multireddit_path) click to toggle source

Fetches a multireddit. @!method multireddit(multireddit_path) @param multireddit_path [String] The path to the multireddit (e.g.

/user/username/m/multireddit_name).

@return [NeonRAW::Objects::MultiReddit] Returns the multireddit

object.
# File lib/NeonRAW/clients/base/objectbuilder.rb, line 78
def multireddit(multireddit_path)
  params = { multipath: multireddit_path, expand_srs: false }
  data = request_data("/api/multi/#{multireddit_path}", :get, params)
  Objects::MultiReddit.new(self, data[:data])
end
subreddit(name) click to toggle source

Fetches a subreddit. @!method subreddit(name) @param name [String] The name of the subreddit. @return [NeonRAW::Objects::Subreddit/All/Popular] Returns the

subreddit/all/popular object.
# File lib/NeonRAW/clients/base/objectbuilder.rb, line 44
def subreddit(name)
  if name == 'all'
    Objects::All.new(self)
  elsif name == 'popular'
    Objects::Popular.new(self)
  else
    data = request_data("/r/#{name}/about", :get)[:data]
    Objects::Subreddit.new(self, data)
  end
end
user(name) click to toggle source

Fetches a user. @!method user(name) @param name [String] The name of the user. @return [NeonRAW::Objects::User] Returns the user object.

# File lib/NeonRAW/clients/base/objectbuilder.rb, line 59
def user(name)
  data = request_data("/user/#{name}/about", :get)[:data]
  Objects::User.new(self, data)
end
wikipage(page) click to toggle source

Fetches a wiki page. @!method wikipage(page) @param page [String] The name of the page. @return [NeonRAW::Objects::WikiPage] Returns the wiki page object.

# File lib/NeonRAW/clients/base/objectbuilder.rb, line 166
def wikipage(page)
  params = { page: page }
  path = "/wiki/#{page}"
  data = request_data(path, :get, params)
  data[:data][:name] = page
  Objects::WikiPage.new(self, data[:data])
end