Class: Rubbit_Poster

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

Constant Summary collapse

@@instance =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(net_name) ⇒ Rubbit_Poster

Returns a new instance of Rubbit_Poster.



79
80
81
82
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 79

def initialize(net_name)
  Reddit_Net_Wrapper.instance(net_name)
  @logged_in_user = nil
end

Class Method Details

.instance(name = nil) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 84

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



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 112

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(parent, id) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 178

def comment(parent,id)
  params = {}
  params['text']=text
  params['thing_id']=parent
  params['uh']=get_modhash
  params['renderstylel']='html'

  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params)

  if(response.code=='200')
    return true
  end
  return false
end

#delete(id) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 206

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)

  if(response.code=='200')
    return true
  end
  return false
end

#delete_user(user, passwd, message, confirm) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 126

def delete_user(user,passwd,message,confirm)
  params = {}
  params['api_type']='json'
  params['user']=user
  params['passwd']=passwd
  params['message']=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

#edit(id, text) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
# 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)

  if(response.code=='200')
    return true
  end
  return false
end

#get_modhashObject



247
248
249
250
251
252
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 247

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

#hide(id) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 193

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)

  if(response.code=='200')
    return true
  end
  return false
end

#login(user, passwd) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 95

def (user,passwd)
  params = {}
  params['op']='login'
  params['user']=user
  params['passwd']=passwd
  params['api-type']='json'
  
   = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/login/',params).code

  if(=='200')
    user = Rubbit_Object_Builder.instance.build_user('the1rgood')
    @logged_in_user = user.name
    return user
  end
  return nil
end

#mark_nsfw(id) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 234

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)

  if(response.code=='200')
    return true
  end
  return false
end

#submit(sr, title, url = nil, text = nil, kind = 'self', resubmit = nil, save = false, sendreplies = true) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 158

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



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/Rubbit/Rubbit_Construction_Layer.rb', line 141

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