module NeonRAW::Objects::Subreddit::Utilities

Utilities for subreddits.

Public Instance Methods

moderators() click to toggle source

Returns data on the moderators of the subreddit. @!method moderators @return [Array<Hash<String, String, Array<String>, Float, String,

String>>] Returns data on the moderators.
# File lib/NeonRAW/objects/subreddit/utilities.rb, line 81
def moderators
  path = "/r/#{display_name}/about/moderators"
  data = @client.request_data(path, :get)[:data][:children]
  data.each do |user|
    user[:username] = user.delete(:name)
    user[:name] = user.delete(:id) # this is for consistency
  end
  data
end
stream(queue, params = { limit: 25 }) click to toggle source

Streams content from subreddits. @!method stream(queue, params = { limit: 25 }) @param queue [Symbol] The queue to get data from [hot, top, new,

controversial, gilded, comments]

@param params [Hash] The parameters for the request. @option params :t [String] Time for relevant sorting [hour, day, week,

month, year, all]

@option params :after [String] The name of the next data block. @option params :before [String] The name of the previous data block. @option params :count [Integer] The number of items already in the

listing.

@option params :limit [1..1000] The number of items to fetch. @option params :show [String] Literally the string 'all'. @yield [NeonRAW::Objects::Comment/Submission] Yields listing items. @return [Enumerator] Returns an enumerator for the streamed data. @example Simple comment stream.

client = NeonRAW.script(...)
comments = client.subreddit(...).stream :comments
comments.each do |comment|
  comment.reply 'world' if comment.body =~ /hello/i
end
# File lib/NeonRAW/objects/subreddit/utilities.rb, line 73
def stream(queue, params = { limit: 25 })
  @client.send(:stream, "/r/#{display_name}/#{queue}", params)
end
submit(title, params = {}) click to toggle source

Submit a thread to the subreddit. @!method submit(title, params = {}) @param title [String] The title of the submission (300

characters maximum).

@param params [Hash] The parameters. @option params :text [String] The text of the submission (selfpost). @option params :url [String] The URL of the submission (link post). @return [NeonRAW::Objects::Submission] Returns the submission object. @note This method uses 2 API requests, as it calls info since the

JSON returned doesn't give you the submission data.
# File lib/NeonRAW/objects/subreddit/utilities.rb, line 16
def submit(title, params = {})
  params[:kind] = 'self' if params[:text]
  params[:kind] = 'link' if params[:url]
  params[:api_type] = 'json'
  params[:sr] = display_name
  params[:title] = title
  response = @client.request_data('/api/submit', :post, params)
  @client.info(name: response[:json][:data][:name]).first
end