Class: Subreddit

Inherits:
Object
  • Object
show all
Defined in:
lib/Rubbit/Rubbit_Objects.rb

Overview

Rubbit Object

Object Representing a Subreddit.

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Subreddit

Returns a new instance of Subreddit.



9
10
11
12
13
14
15
16
17
# 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

Instance Method Details

#add_contributor(name) ⇒ Object

Description

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

Attributes

  • name - name of user to add as a contributor



209
210
211
# 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) ⇒ Object

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



198
199
200
# 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) ⇒ Object

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



223
224
225
# 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) ⇒ Object

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



162
163
164
# 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) ⇒ Object

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



149
150
151
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the controversial queue

Attributes

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



87
88
89
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the gilded queue

Attributes

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



63
64
65
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the hot queue

Attributes

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



39
40
41
# 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_moderatorsObject

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



175
176
177
# 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) ⇒ Object



179
180
181
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the new queue

Attributes

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



27
28
29
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the rising queue

Attributes

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



75
76
77
# 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) ⇒ Object

Description

Returns enumerable ContentGenerator object representing the top queue

Attributes

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



51
52
53
# 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) ⇒ Boolean

Returns:



183
184
185
186
187
# 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) ⇒ Object

Description

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

Attributes

  • name - name of contributor to remove



247
248
249
# 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) ⇒ Object

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



235
236
237
# 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) ⇒ Object

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



106
107
108
# 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

Description

Function for submitting link posts to a subreddit.

Attributes

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

  • url - The url for the post.

  • 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



137
138
139
# File 'lib/Rubbit/Rubbit_Objects.rb', line 137

def submit_link(title,url,resubmit=false,save=false,sendreplies=true)
  return submit(title,url,nil,'link',resubmit,save,sendreplies)
end

#submit_self(title, text = nil, save = false, sendreplies = true) ⇒ Object

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



121
122
123
# 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) ⇒ Object

Description

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

Attributes

  • name - name of user to unban



259
260
261
# File 'lib/Rubbit/Rubbit_Objects.rb', line 259

def unban(name)
  return Rubbit_Poster.instance.unfriend('ban',name,@display_name)
end