class Rubbit
Rubbit
Client¶ ↑
Contains highest level Rubbit
functionality
Attributes
client_name[RW]
me[RW]
object_builder[RW]
rubbit_poster[RW]
Public Class Methods
new(name)
click to toggle source
Description¶ ↑
Initialize the Rubbit
client with an ID that's added to the user agent
Attributes¶ ↑
-
name
- Attribute that identifies the bot usingRubbit
. Is added to the user-agent.
# File lib/Rubbit.rb, line 19 def initialize(name) @client_name = name @object_builder = Rubbit_Object_Builder.instance(name) @rubbit_poster = Rubbit_Poster.instance(name) @me = nil end
Public Instance Methods
clear_session(curpass=nil)
click to toggle source
Description¶ ↑
Clears the current session.
Attributes¶ ↑
-
curpass
- Password required to log in with that user
# File lib/Rubbit.rb, line 91 def clear_session(curpass=nil) if(@me==nil) print('Not logged in. No session to clear') elsif(curpass==nil) print('Enter password for '+user.to_s+': ') passwd = STDIN.noecho(&:gets).chomp end return @rubbit_poster.clear_sessions(curpass) end
comment(text,parent)
click to toggle source
# File lib/Rubbit.rb, line 229 def comment(text,parent) if(@me!=nil) return @rubbut_poster.comment(text,parent) end return nil end
create_live(title,description='',nsfw=false)
click to toggle source
# File lib/Rubbit.rb, line 141 def create_live(title,description='',nsfw=false) return @rubbit_poster.create_live(title,description,nsfw) end
create_subreddit(name,other_params)
click to toggle source
# File lib/Rubbit.rb, line 145 def create_subreddit(name,other_params) return @rubbit_poster.create_subreddit(name,other_params) end
delete_user(user=nil,passwd=nil,message="")
click to toggle source
Description¶ ↑
Deletes desired user. Requires auth info for that user.
Attributes¶ ↑
-
user
- Username of account you wish to delete. -
passwd
- Password required to log in with that user -
message
- Reason for deleting account.
# File lib/Rubbit.rb, line 111 def delete_user(user=nil,passwd=nil,message="") confirm = nil if(user==nil) print('Enter username: ') user = gets.chomp print('Enter password for '+user.to_s+': ') passwd = STDIN.noecho(&:gets).chomp elsif(passwd==nil) print('Enter password for '+user.to_s+': ') passwd = STDIN.noecho(&:gets).chomp end while(confirm==nil) print('Confirm deletion of '+user.to_s+' (y/n): ') answer = gets.chomp if(answer=='y') confirm = true elsif(answer=='n') confirm = false else puts("Invalid input.") end end return @rubbit_poster.delete_user(user,passwd,confirm,message) end
friend(user)
click to toggle source
# File lib/Rubbit.rb, line 207 def friend(user) return @rubbit_poster.friend('friend',user,@me.name) end
get_comments(subreddit,limit)
click to toggle source
# File lib/Rubbit.rb, line 189 def get_comments(subreddit,limit) return @object_builder.get_comments('http://www.reddit.com/r/'+subreddit+'/comments.json',limit) end
get_inbox(limit=100)
click to toggle source
# File lib/Rubbit.rb, line 193 def get_inbox(limit=100) if(me!=nil) return ContentGenerator.new('http://www.reddit.com/message/inbox.json',limit) end return nil end
get_me()
click to toggle source
# File lib/Rubbit.rb, line 137 def get_me() return @object_builder.build_user(@me.name) end
get_redditor(user)
click to toggle source
get_sent(limit=100)
click to toggle source
# File lib/Rubbit.rb, line 215 def get_sent(limit=100) if(me!=nil) return ContentGenerator.new('http://www.reddit.com/message/sent.json',limit) end return nil end
get_submission(link)
click to toggle source
# File lib/Rubbit.rb, line 185 def get_submission(link) return @object_builder.build_submission(link) end
get_subreddit(display_name)
click to toggle source
get_unread(limit=100)
click to toggle source
# File lib/Rubbit.rb, line 200 def get_unread(limit=100) if(me!=nil) return ContentGenerator.new('http://www.reddit.com/message/unread.json',limit) end return nil end
login(user=nil,passwd=nil)
click to toggle source
Description¶ ↑
Login to Reddit and create a session. User and passwd are not required. This function will prompt the user for missing information at runtime.
Attributes¶ ↑
-
user
- Username that you wish to log in with -
passwd
- Password required to log in with that user
# File lib/Rubbit.rb, line 69 def login(user=nil,passwd=nil) if(user==nil) print('Enter username: ') user = gets.chomp print('Enter password for '+user.to_s+': ') passwd = STDIN.noecho(&:gets).chomp elsif(passwd==nil) print('Enter password for '+user.to_s+': ') passwd = STDIN.noecho(&:gets).chomp end @me = @rubbit_poster.login(user,passwd) return @me end
set_request_period(period)
click to toggle source
submit(sr,title,url=nil,text=nil,kind='self',resubmit=false,save=false,sendreplies=true)
click to toggle source
# File lib/Rubbit.rb, line 222 def submit(sr,title,url=nil,text=nil,kind='self',resubmit=false,save=false,sendreplies=true) if(@me!=nil) return @rubbit_poster.submit(sr,title,url,text,kind,resubmit,save,sendreplies) end return nil end
unfriend(user)
click to toggle source
# File lib/Rubbit.rb, line 211 def unfriend(user) return @rubbut_poster.unfriend('friend',user,@me.name) end
update(curpass=nil,email=nil,newpass=nil,verify=nil,verpass=nil)
click to toggle source
# File lib/Rubbit.rb, line 149 def update(curpass=nil,email=nil,newpass=nil,verify=nil,verpass=nil) if(@me==nil) print('Not logged in. Cannot update password or email') return false else if(curpass == nil) print('Enter password for '+@me.name.to_s+': ') curpass = STDIN.noecho(&:gets).chomp end if(email == nil) print('Enter new email: ') email = gets.chomp end if(newpass == nil) print('Enter new password for '+@me.name.to_s+': ') newpass = STDIN.noecho(&:gets).chomp end if(verify == nil) while(verify==nil) print('Are you sure? (y/n): ') input = gets.chomp if(input=='y') verify=true elsif(input=='n') verify= false end end end if(verpass==nil) print('Verify password for '+@me.name.to_s+': ') verpass = STDIN.noecho(&:gets).chomp end return @rubbit_poster.update(curpass,email,newpass,verify,verpass) end end