Class: Rubbit
- Inherits:
-
Object
- Object
- Rubbit
- Defined in:
- lib/Rubbit.rb
Overview
Rubbit Client
Contains highest level Rubbit functionality
Instance Attribute Summary collapse
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#me ⇒ Object
Returns the value of attribute me.
-
#object_builder ⇒ Object
Returns the value of attribute object_builder.
-
#rubbit_poster ⇒ Object
Returns the value of attribute rubbit_poster.
Instance Method Summary collapse
-
#clear_session(curpass = nil) ⇒ Object
Description.
- #comment(text, parent) ⇒ Object
- #create_live(title, description = '', nsfw = false) ⇒ Object
- #create_subreddit(name, other_params) ⇒ Object
-
#delete_user(user = nil, passwd = nil, message = "") ⇒ Object
Description.
- #friend(user) ⇒ Object
- #get_comments(subreddit, limit) ⇒ Object
- #get_inbox(limit = 100) ⇒ Object
- #get_me ⇒ Object
-
#get_redditor(user) ⇒ Object
Description.
- #get_sent(limit = 100) ⇒ Object
- #get_submission(link) ⇒ Object
-
#get_subreddit(display_name) ⇒ Object
Description.
- #get_unread(limit = 100) ⇒ Object
-
#initialize(name) ⇒ Rubbit
constructor
Description.
-
#login(user = nil, passwd = nil) ⇒ Object
Description.
-
#set_request_period(period) ⇒ Object
Description.
- #submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = false, save = false, sendreplies = true) ⇒ Object
- #unfriend(user) ⇒ Object
- #update(curpass = nil, email = nil, newpass = nil, verify = nil, verpass = nil) ⇒ Object
Constructor Details
#initialize(name) ⇒ Rubbit
Description
Initialize the Rubbit client with an ID that’s added to the user agent
Attributes
-
name
- Attribute that identifies the bot using Rubbit. Is added to the user-agent.
19 20 21 22 23 24 |
# 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 |
Instance Attribute Details
#client_name ⇒ Object
Returns the value of attribute client_name.
10 11 12 |
# File 'lib/Rubbit.rb', line 10 def client_name @client_name end |
#me ⇒ Object
Returns the value of attribute me.
10 11 12 |
# File 'lib/Rubbit.rb', line 10 def me @me end |
#object_builder ⇒ Object
Returns the value of attribute object_builder.
10 11 12 |
# File 'lib/Rubbit.rb', line 10 def object_builder @object_builder end |
#rubbit_poster ⇒ Object
Returns the value of attribute rubbit_poster.
10 11 12 |
# File 'lib/Rubbit.rb', line 10 def rubbit_poster @rubbit_poster end |
Instance Method Details
#clear_session(curpass = nil) ⇒ Object
Description
Clears the current session.
Attributes
-
curpass
- Password required to log in with that user
91 92 93 94 95 96 97 98 99 |
# 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) ⇒ Object
229 230 231 232 233 234 |
# 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) ⇒ Object
141 142 143 |
# 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) ⇒ Object
145 146 147 |
# 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 = "") ⇒ Object
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.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/Rubbit.rb', line 111 def delete_user(user=nil,passwd=nil,="") 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,) end |
#friend(user) ⇒ Object
207 208 209 |
# File 'lib/Rubbit.rb', line 207 def friend(user) return @rubbit_poster.friend('friend',user,@me.name) end |
#get_comments(subreddit, limit) ⇒ Object
189 190 191 |
# 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) ⇒ Object
193 194 195 196 197 198 |
# 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 ⇒ Object
137 138 139 |
# File 'lib/Rubbit.rb', line 137 def get_me() return @object_builder.build_user(@me.name) end |
#get_redditor(user) ⇒ Object
Description
Gets a Redditor object, created by username
Attributes
-
user
- That Redditor’s username
44 45 46 |
# File 'lib/Rubbit.rb', line 44 def get_redditor(user) return @object_builder.build_user(user) end |
#get_sent(limit = 100) ⇒ Object
215 216 217 218 219 220 |
# 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) ⇒ Object
185 186 187 |
# File 'lib/Rubbit.rb', line 185 def get_submission(link) return @object_builder.build_submission(link) end |
#get_subreddit(display_name) ⇒ Object
Description
Gets a Subreddit object, created by subreddit name
Attributes
-
display_name
- Display name of the subreddit a user wishes to create an object representation for
33 34 35 |
# File 'lib/Rubbit.rb', line 33 def get_subreddit(display_name) return @object_builder.build_subreddit(display_name) end |
#get_unread(limit = 100) ⇒ Object
200 201 202 203 204 205 |
# 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) ⇒ Object
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
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# 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) ⇒ Object
Description
Gets a Subreddit object, created by subreddit name
Attributes
-
display_name
- Display name of the subreddit a user wishes to create an object representation for
55 56 57 |
# File 'lib/Rubbit.rb', line 55 def set_request_period(period) @object_builder.set_request_period(period) end |
#submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = false, save = false, sendreplies = true) ⇒ Object
222 223 224 225 226 227 |
# 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) ⇒ Object
211 212 213 |
# 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) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# 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 |