class Subreddit

Rubbit Object

Object Representing a Subreddit.

Public Class Methods

new(json) click to toggle source
# File lib/Rubbit/Rubbit_Objects.rb, line 9
def initialize(json)
        if(json['kind']=='t5')
                data = json['data']
                data.each_key do |k|
                        self.class.module_eval {attr_accessor(k)}
                        self.send("#{k}=",data[k])
                end
        end
end

Public Instance Methods

add_contributor(name) click to toggle source

Description

Function for adding contributor to a subreddit. Only works if subreddit moderator.

Attributes

  • name - name of user to add as a contributor

# File lib/Rubbit/Rubbit_Objects.rb, line 209
def add_contributor(name)
        return Rubbit_Poster.instance.friend('contributor',name,@name,@display_name)
end
add_moderator(name,permissions) click to toggle source

Description

Function for adding moderator to a subreddit. Only works if subreddit moderator.

Attributes

  • name - name of user to add as a moderator

  • permissions - string containing permissions to give this user

# File lib/Rubbit/Rubbit_Objects.rb, line 198
def add_moderator(name,permissions)
        return Rubbit_Poster.instance.friend('moderator_invite',name,@display_name,permissions)
end
ban(name,note,duration) click to toggle source

Description

Function for banning a user from a subreddit. Only works if subreddit moderator.

Attributes

  • name - name of user to ban

  • note - note for the ban

  • duration - length of period they are banned for, in days. Send nil for permanent

# File lib/Rubbit/Rubbit_Objects.rb, line 223
def ban(name,note,duration)
        return Rubbit_Poster.instance.friend('banned',name,@display_name,note,duration)
end
get_banned(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing banned users of a subreddit. Will only work if subreddit moderator.

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 162
def get_banned(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/banned.json',limit)
end
get_contributors(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing approved contributors to a subreddit

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 149
def get_contributors(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/contributors.json',limit)
end
get_controversial(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the controversial queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 87
def get_controversial(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/controversial.json',limit)
end
get_gilded(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the gilded queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 63
def get_gilded(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/gilded.json',limit)
end
get_hot(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the hot queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 39
def get_hot(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/hot.json',limit)
end
get_moderators() click to toggle source

Description

Returns enumerable ContentGenerator object representing moderators of a subreddit. Will only work if subreddit is viewable.

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 175
def get_moderators
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/moderators.json',nil)
end
get_modmail(limit=100) click to toggle source
# File lib/Rubbit/Rubbit_Objects.rb, line 179
def get_modmail(limit=100)
        return ContentGenerator.new("http://www.reddit.com/r/#{@display_name.to_s}/about/message/inbox/.json",limit)
end
get_new(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the new queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 27
def get_new(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/new.json',limit)
end
get_rising(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the rising queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 75
def get_rising(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/rising.json',limit)
end
get_top(limit=100) click to toggle source

Description

Returns enumerable ContentGenerator object representing the top queue

Attributes

  • limit - Maximum entries that the returned ContentGenerator will hold. For no limit, use nil

# File lib/Rubbit/Rubbit_Objects.rb, line 51
def get_top(limit=100)
        return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/top.json',limit)
end
is_contributor?(name) click to toggle source
# File lib/Rubbit/Rubbit_Objects.rb, line 183
def is_contributor?(name)
        contrib_check = ContentGenerator.new("http://www.reddit.com/r/#{@display_name.to_s}/about/contributors/.json?user=#{name}")
        user = contrib_check.next
        return user != nil
end
remove_contributor(name) click to toggle source

Description

Function for removing a contributor from a subreddit. Only works if subreddit moderator.

Attributes

  • name - name of contributor to remove

# File lib/Rubbit/Rubbit_Objects.rb, line 247
def remove_contributor(name)
        return Rubbit_Poster.instance.unfriend('contributor',name,@display_name)
end
remove_moderator(name) click to toggle source

Description

Function for removing a moderator from a subreddit. Only works if subreddit moderator and has higher permissions than mod to remove.

Attributes

  • name - name of moderator to remove

# File lib/Rubbit/Rubbit_Objects.rb, line 235
def remove_moderator(name)
        return Rubbit_Poster.instance.unfriend('moderator',name,@display_name)
end
submit(title,url=nil,text=nil,kind='self',resubmit=false,save=false,sendreplies=true) click to toggle source

Description

General function for submitting content to a subreddit

Attributes

  • title - REQUIRED. Title for post. Cannot be empty or the function will not work.

  • url - The url for the post. Will only be used if kind is “link”

  • text - The text for the post. Will only be used if kind is “self”

  • kind - Determines type of post. Either link or self.

  • resubmit - If true, will make post to subreddit regardless if it is a repost

  • save - Will save the post in user's “saved” links if true

  • sendreplies - Will send replies to post to user's inbox by default, unless this is set to false

# File lib/Rubbit/Rubbit_Objects.rb, line 106
def submit(title,url=nil,text=nil,kind='self',resubmit=false,save=false,sendreplies=true)
        return Rubbit_Poster.instance.submit(@display_name,title,url,text,kind,resubmit,save,sendreplies)
end
submit_self(title,text=nil,save=false,sendreplies=true) click to toggle source

Description

Function for submitting self posts to a subreddit.

Attributes

  • title - REQUIRED. Title for post. Cannot be empty or the function will not work.

  • text - The text for the post.

  • save - Will save the post in user's “saved” links if true

  • sendreplies - Will send replies to post to user's inbox by default, unless this is set to false

# File lib/Rubbit/Rubbit_Objects.rb, line 121
def submit_self(title,text=nil,save=false,sendreplies=true)
        return submit(title,nil,text,'self',false,save,sendreplies)
end
unban(name) click to toggle source

Description

Function for unbanning a user from a subreddit. Only works if subreddit moderator.

Attributes

  • name - name of user to unban

# File lib/Rubbit/Rubbit_Objects.rb, line 259
def unban(name)
        return Rubbit_Poster.instance.unfriend('ban',name,@display_name)
end