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(text, parent) ⇒ Object
- #delete_user(user, passwd, message, confirm) ⇒ Object
- #get_modhash ⇒ Object
-
#initialize(net_name) ⇒ Rubbit_Poster
constructor
A new instance of Rubbit_Poster.
- #login(user, passwd) ⇒ Object
- #submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = nil, save = false, sendreplies = true) ⇒ Object
- #update(email, newpass, curpass, verify, verpass) ⇒ Object
Constructor Details
#initialize(net_name) ⇒ Rubbit_Poster
Returns a new instance of Rubbit_Poster.
78 79 80 81 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 78 def initialize(net_name) Reddit_Net_Wrapper.instance(net_name) @logged_in_user = nil end |
Class Method Details
.instance(name = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 83 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
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 111 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) if(response.code=='200') return true end return false end |
#comment(text, parent) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 177 def comment(text,parent) params = {} params['text']=text params['thing_id']=parent params['uh']=get_modhash params['renderstylel']='html' puts params response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params) puts response.code if(response.code=='200') return true end return false end |
#delete_user(user, passwd, message, confirm) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 125 def delete_user(user,passwd,,confirm) 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) if(response.code=='200') return true end return false end |
#get_modhash ⇒ Object
196 197 198 199 200 201 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 196 def get_modhash response = Reddit_Net_Wrapper.instance.make_request('get','http://www.reddit.com/user/'+@logged_in_user+'/about.json',{}) data = JSON.parse(response.body) puts data return data['data']['modhash'] end |
#login(user, passwd) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 94 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('the1rgood') @logged_in_user = user.name return user end return nil end |
#submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = nil, save = false, sendreplies = true) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 157 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 |
#update(email, newpass, curpass, verify, verpass) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 140 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) if(response.code=='200') return true end return false end |