Class: Rubbit_Poster
- Inherits:
-
Object
- Object
- Rubbit_Poster
- Defined in:
- lib/Rubbit/Rubbit_Construction_Layer.rb
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #clear_sessions(curpass) ⇒ Object
- #comment(parent, text) ⇒ Object
- #create_live(title, description = '', nsfw = false) ⇒ Object
- #create_subreddit(name, other_params) ⇒ Object
- #delete(id) ⇒ Object
- #delete_user(user, passwd, message) ⇒ Object
- #edit(id, text) ⇒ Object
- #friend(type, user, container, info = nil, duration = nil) ⇒ Object
- #get_modhash ⇒ Object
- #hide(id) ⇒ Object
-
#initialize(net_name) ⇒ Rubbit_Poster
constructor
A new instance of Rubbit_Poster.
- #login(user, passwd) ⇒ Object
- #mark_nsfw(id) ⇒ Object
- #set_subreddit_sticky(post_id, state) ⇒ Object
- #submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = nil, save = false, sendreplies = true) ⇒ Object
- #unfriend(type, user, container) ⇒ Object
- #update(email, newpass, curpass, verify, verpass) ⇒ Object
- #update_live(id, body) ⇒ Object
Constructor Details
#initialize(net_name) ⇒ Rubbit_Poster
Returns a new instance of Rubbit_Poster.
84 85 86 87 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 84 def initialize(net_name) Reddit_Net_Wrapper.instance(net_name) @logged_in_user = nil end |
Class Method Details
.instance(name = nil) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 101 def self.instance(name=nil) if(@@instance==nil) if(name!=nil) @@instance = new(name) else return nil end end return @@instance end |
Instance Method Details
#clear_sessions(curpass) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 130 def clear_sessions(curpass) params = {} params['api_type']='json' params['curpass'] = curpass params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/clear_sessions/',params) return JSON.parse(response.body) end |
#comment(parent, text) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 187 def comment(parent,text) params = {} params['api_type']='json' params['thing_id']=parent params['text']=text params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params) return JSON.parse(response.body) end |
#create_live(title, description = '', nsfw = false) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 241 def create_live(title,description='',nsfw=false) params = {} params['api_type']='json' params['title']=title params['description']=description params['nsfw']=nsfw params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/create',params) return Live_Thread.new(JSON.parse(response.body)['json']['data']['id']) end |
#create_subreddit(name, other_params) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 316 def create_subreddit(name,other_params) params = {} params['link_type']='any' params['wikimode']='disabled' params['type'] = 'public' params['name'] = name other_params.keys.each do |k| params[k] = other_params[k] end params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/site_admin',params) return response.body end |
#delete(id) ⇒ Object
209 210 211 212 213 214 215 216 217 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 209 def delete(id) params = {} params['id'] = id params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/del',params) return JSON.parse(response.body) end |
#delete_user(user, passwd, message) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 141 def delete_user(user,passwd,) params = {} params['api_type']='json' params['user']=user params['passwd']=passwd params['message']= params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/delete_user/',params) return JSON.parse(response.body) end |
#edit(id, text) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 219 def edit(id,text) params = {} params['api_type']='json' params['text']=text params['id'] = id params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/editusertext',params) return JSON.parse(response.body) end |
#friend(type, user, container, info = nil, duration = nil) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 267 def friend(type,user,container,info=nil,duration=nil) params = {} params['api_type']='json' params['type']=type params['name']=user params['uh']=get_modhash case type when 'friend' params['note']=info params['container']=container when 'moderator' params['container']=container params['permissions']=info when 'moderator_invite' params['container']=container params['permissions']=info when 'contributor' params['container']=container params['r']=info when 'banned' params['container']=container params['note']=info params['duration']=duration when 'wikibanned' params['container']=container params['note']=info params['duration']=duration when 'wikicontributor' params['container']=container end response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/friend',params) return JSON.parse(response.body) end |
#get_modhash ⇒ Object
332 333 334 335 336 337 338 339 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 332 def get_modhash if(@logged_in_user==nil) raise LoginException, 'Not logged in.' end response = Reddit_Net_Wrapper.instance.make_request('get','http://www.reddit.com/user/'+@logged_in_user+'/about.json',{}) data = JSON.parse(response.body) return data['data']['modhash'] end |
#hide(id) ⇒ Object
199 200 201 202 203 204 205 206 207 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 199 def hide(id) params = {} params['id'] = id params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/hide',params) return JSON.parse(response.body) end |
#login(user, passwd) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 112 def login(user,passwd) params = {} params['op']='login' params['user']=user params['passwd']=passwd params['api-type']='json' login_status = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/login/',params).code if(login_status=='200') user = Rubbit_Object_Builder.instance.build_user(user) @logged_in_user = user.name return user else raise InvalidUserException, "Could not validate login credentials" end end |
#mark_nsfw(id) ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 231 def mark_nsfw(id) params = {} params['id'] = id params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/marknsfw',params) return JSON.parse(response.body) end |
#set_subreddit_sticky(post_id, state) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 89 def set_subreddit_sticky(post_id,state) params = {} params['api_type']='json' params['id']=post_id params['state']=state params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/set_subreddit_sticky/',params) return JSON.parse(response.body) end |
#submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = nil, save = false, sendreplies = true) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 167 def submit(sr,title,url=nil,text=nil,kind='self',resubmit=nil,save=false,sendreplies=true) params = {} params['api_type']='json' params['extension']=nil params['kind']=kind params['resubmit']=resubmit params['save']=save params['sendreplies']=sendreplies params['id']='#newlink' params['sr']=sr params['r']=sr params['text']=text params['title']=title params['uh']=get_modhash params['url']=url response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/submit/',params) return JSON.parse(response.body) end |
#unfriend(type, user, container) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 303 def unfriend(type,user,container) params = {} params['api_type']='json' params['type']=type params['name']=user params['uh']=get_modhash params['container']=container response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/unfriend',params) return response.body end |
#update(email, newpass, curpass, verify, verpass) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 153 def update(email,newpass,curpass,verify,verpass) params = {} params['api_type']='json' params['curpass']=curpass params['email']=email params['newpass']=newpass params['verify']=verify params['verpass']=verpass params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/update/',params) return JSON.parse(response.body) end |
#update_live(id, body) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 255 def update_live(id,body) params = {} params['api_type']='json' params['body']=body params['uh']=get_modhash response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/'+id+'/update',params) return JSON.parse(response.body) end |