Rubbit 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -138,6 +138,14 @@ class Rubbit
138
138
  return @object_builder.build_user(@me.name)
139
139
  end
140
140
 
141
+ def create_live(title,description='',nsfw=false)
142
+ return @rubbit_poster.create_live(title,description,nsfw)
143
+ end
144
+
145
+ def create_subreddit(name,other_params)
146
+ return @rubbit_poster.create_subreddit(name,other_params)
147
+ end
148
+
141
149
  def update(curpass=nil,email=nil,newpass=nil,verify=nil,verpass=nil)
142
150
  if(@me==nil)
143
151
  print('Not logged in. Cannot update password or email')
@@ -85,6 +85,18 @@ class Rubbit_Poster
85
85
  Reddit_Net_Wrapper.instance(net_name)
86
86
  @logged_in_user = nil
87
87
  end
88
+
89
+ def set_subreddit_sticky(post_id,state)
90
+ params = {}
91
+ params['api_type']='json'
92
+ params['id']=post_id
93
+ params['state']=state
94
+ params['uh']=get_modhash
95
+
96
+ response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/set_subreddit_sticky/',params)
97
+
98
+ return JSON.parse(response.body)
99
+ end
88
100
 
89
101
  def self.instance(name=nil)
90
102
  if(@@instance==nil)
@@ -123,7 +135,7 @@ class Rubbit_Poster
123
135
 
124
136
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/clear_sessions/',params)
125
137
 
126
- return response.body
138
+ return JSON.parse(response.body)
127
139
  end
128
140
 
129
141
  def delete_user(user,passwd,message)
@@ -135,7 +147,7 @@ class Rubbit_Poster
135
147
  params['uh']=get_modhash
136
148
 
137
149
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/delete_user/',params)
138
- return response.body
150
+ return JSON.parse(response.body)
139
151
  end
140
152
 
141
153
  def update(email,newpass,curpass,verify,verpass)
@@ -149,7 +161,7 @@ class Rubbit_Poster
149
161
  params['uh']=get_modhash
150
162
 
151
163
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/update/',params)
152
- return response.body
164
+ return JSON.parse(response.body)
153
165
  end
154
166
 
155
167
  def submit(sr,title,url=nil,text=nil,kind='self',resubmit=nil,save=false,sendreplies=true)
@@ -174,14 +186,14 @@ class Rubbit_Poster
174
186
 
175
187
  def comment(parent,text)
176
188
  params = {}
177
- params['text']=text
189
+ params['api_type']='json'
178
190
  params['thing_id']=parent
191
+ params['text']=text
179
192
  params['uh']=get_modhash
180
- params['renderstylel']='html'
181
193
 
182
194
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params)
183
195
 
184
- return response.body
196
+ return JSON.parse(response.body)
185
197
  end
186
198
 
187
199
  def hide(id)
@@ -191,7 +203,7 @@ class Rubbit_Poster
191
203
 
192
204
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/hide',params)
193
205
 
194
- return response.body
206
+ return JSON.parse(response.body)
195
207
  end
196
208
 
197
209
  def delete(id)
@@ -201,7 +213,7 @@ class Rubbit_Poster
201
213
 
202
214
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/del',params)
203
215
 
204
- return response.body
216
+ return JSON.parse(response.body)
205
217
  end
206
218
 
207
219
  def edit(id,text)
@@ -213,7 +225,7 @@ class Rubbit_Poster
213
225
 
214
226
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/editusertext',params)
215
227
 
216
- return response.body
228
+ return JSON.parse(response.body)
217
229
  end
218
230
 
219
231
  def mark_nsfw(id)
@@ -223,7 +235,33 @@ class Rubbit_Poster
223
235
 
224
236
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/marknsfw',params)
225
237
 
226
- return response.body
238
+ return JSON.parse(response.body)
239
+ end
240
+
241
+ def create_live(title,description='',nsfw=false)
242
+ params = {}
243
+
244
+ params['api_type']='json'
245
+ params['title']=title
246
+ params['description']=description
247
+ params['nsfw']=nsfw
248
+ params['uh']=get_modhash
249
+
250
+ response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/create',params)
251
+
252
+ return Live_Thread.new(JSON.parse(response.body)['json']['data']['id'])
253
+ end
254
+
255
+ def update_live(id,body)
256
+ params = {}
257
+
258
+ params['api_type']='json'
259
+ params['body']=body
260
+ params['uh']=get_modhash
261
+
262
+ response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/live/'+id+'/update',params)
263
+
264
+ return JSON.parse(response.body)
227
265
  end
228
266
 
229
267
  def friend(type,user,container,info=nil,duration=nil)
@@ -231,7 +269,7 @@ class Rubbit_Poster
231
269
  params['api_type']='json'
232
270
  params['type']=type
233
271
  params['name']=user
234
- params['modhash']=get_modhash
272
+ params['uh']=get_modhash
235
273
  case type
236
274
  when 'friend'
237
275
  params['note']=info
@@ -244,6 +282,7 @@ class Rubbit_Poster
244
282
  params['permissions']=info
245
283
  when 'contributor'
246
284
  params['container']=container
285
+ params['r']=info
247
286
  when 'banned'
248
287
  params['container']=container
249
288
  params['note']=info
@@ -255,10 +294,10 @@ class Rubbit_Poster
255
294
  when 'wikicontributor'
256
295
  params['container']=container
257
296
  end
258
-
297
+
259
298
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/friend',params)
260
299
 
261
- return response.body
300
+ return JSON.parse(response.body)
262
301
  end
263
302
 
264
303
  def unfriend(type,user,container)
@@ -266,15 +305,34 @@ class Rubbit_Poster
266
305
  params['api_type']='json'
267
306
  params['type']=type
268
307
  params['name']=user
269
- params['modhash']=get_modhash
308
+ params['uh']=get_modhash
270
309
  params['container']=container
271
310
 
272
311
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/unfriend',params)
273
312
 
274
313
  return response.body
275
314
  end
315
+
316
+ def create_subreddit(name,other_params)
317
+ params = {}
318
+ params['link_type']='any'
319
+ params['wikimode']='disabled'
320
+ params['type'] = 'public'
321
+ params['name'] = name
322
+ other_params.keys.each do |k|
323
+ params[k] = other_params[k]
324
+ end
325
+ params['uh']=get_modhash
326
+
327
+ response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/site_admin',params)
328
+
329
+ return response.body
330
+ end
276
331
 
277
332
  def get_modhash
333
+ if(@logged_in_user==nil)
334
+ raise LoginException, 'Not logged in.'
335
+ end
278
336
  response = Reddit_Net_Wrapper.instance.make_request('get','http://www.reddit.com/user/'+@logged_in_user+'/about.json',{})
279
337
  data = JSON.parse(response.body)
280
338
  return data['data']['modhash']
@@ -175,7 +175,16 @@ class Subreddit
175
175
  def get_moderators
176
176
  return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/moderators.json',nil)
177
177
  end
178
+
179
+ def get_modmail(limit=100)
180
+ return ContentGenerator.new("http://www.reddit.com/r/#{@display_name.to_s}/about/message/inbox/.json",limit)
181
+ end
178
182
 
183
+ def is_contributor?(name)
184
+ contrib_check = ContentGenerator.new("http://www.reddit.com/r/#{@display_name.to_s}/about/contributors/.json?user=#{name}")
185
+ user = contrib_check.next
186
+ return user != nil
187
+ end
179
188
 
180
189
  # ==== Description
181
190
  #
@@ -198,7 +207,7 @@ class Subreddit
198
207
  # * +name+ - name of user to add as a contributor
199
208
  #
200
209
  def add_contributor(name)
201
- return Rubbit_Poster.instance.friend('contributor',name,@display_name)
210
+ return Rubbit_Poster.instance.friend('contributor',name,@name,@display_name)
202
211
  end
203
212
 
204
213
  # ==== Description
@@ -403,7 +412,6 @@ class ContentGenerator
403
412
  end
404
413
  else
405
414
  listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+100.to_s+"&after="+@after+"&count="+@count.to_s)
406
- puts(@source+@limit_param+100.to_s+"&after="+@after+"&count="+@count.to_s)
407
415
  @after = listing.after
408
416
  @data += listing.children
409
417
  @count += listing.children.length
@@ -432,14 +440,13 @@ class ContentGenerator
432
440
  if(@index>=@data.length)
433
441
  if(@limit!=nil)
434
442
  if(@limit-@count>0)
435
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
443
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
436
444
  @after = listing.after
437
445
  @data += listing.children
438
446
  @count += listing.children.length
439
447
  end
440
448
  else
441
- listing = Rubbit_Object_Builder.instance.build_listing(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
442
- puts(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
449
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+100.to_s+"&after="+@after+"&count="+@count.to_s)
443
450
  @after = listing.after
444
451
  @data += listing.children
445
452
  @count += listing.children.length
@@ -582,14 +589,18 @@ class Post
582
589
  def reply(text)
583
590
  return Rubbit_Poster.instance.comment(@name,text)
584
591
  end
592
+
593
+ def set_as_sticky(state)
594
+ return Rubbit_Poster.instance.set_subreddit_sticky(@name,state)
595
+ end
585
596
 
586
597
  # ==== Description
587
598
  #
588
599
  # Retrieves the comments of a post in a list tree.
589
600
  #
590
- def replies
601
+ def replies(limit=100)
591
602
  if(@comments==nil)
592
- @comments = Rubbit_Object_Builder.instance.get_comments('http://www.reddit.com'+@permalink).children
603
+ @comments = Rubbit_Object_Builder.instance.get_comments("http://www.reddit.com#{permalink}.json",limit)
593
604
  end
594
605
  return @comments
595
606
  end
@@ -655,7 +666,50 @@ class Message
655
666
  # * +text+ - The new message body.
656
667
  #
657
668
  def reply(text)
658
- Rubbit_Poster.instance.comment(text,@name)
669
+ return Rubbit_Poster.instance.comment(@name,text)
670
+ end
671
+ end
672
+
673
+ # == Rubbit Object
674
+ #
675
+ # Object that represents a Live Thread
676
+ #
677
+ class Live_Thread
678
+ @id = nil
679
+ def initialize(id)
680
+ @id = id
681
+ end
682
+
683
+ def get_updates
684
+ return ContentGenerator.new('http://www.reddit.com/live/'+@id+'.json',limit)
685
+ end
686
+
687
+ def make_update(body)
688
+ return Rubbit_Poster.instance.update_live(@id,body)
689
+ end
690
+ end
691
+
692
+ # == Rubbit Object
693
+ #
694
+ # Object that represents an Update in a Live Thread
695
+ #
696
+ class Live_Update
697
+ def initialize(json)
698
+ if(json['kind']=='LiveUpdate')
699
+ data = json['data']
700
+ data.each_key do |k|
701
+ self.class.module_eval {attr_accessor(k)}
702
+ self.send("#{k}=",data[k])
703
+ end
704
+ end
705
+ end
706
+
707
+ def strike
708
+
709
+ end
710
+
711
+ def delete
712
+
659
713
  end
660
714
  end
661
715
 
@@ -686,6 +740,8 @@ class Listing
686
740
  children_objects += [Subreddit.new(c)]
687
741
  elsif(c['kind'] == 'Listing')
688
742
  children_objects += [Listing.new(c)]
743
+ elsif(c['kind'] == 'LiveUpdate')
744
+ children_objects += [Live_Update.new(c)]
689
745
  end
690
746
  end
691
747
  @children = children_objects
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Rubbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - /u/The1RGood
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-09-26 00:00:00.000000000 Z
12
+ date: 2015-02-07 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: A simple Ruby-based Reddit API Wrapper
14
15
  email: randy@kindofabigdeal.org
@@ -18,31 +19,32 @@ extra_rdoc_files: []
18
19
  files:
19
20
  - lib/Rubbit.rb
20
21
  - lib/Rubbit/Reddit_Net_Wrapper.rb
22
+ - lib/Rubbit/Rubbit_Objects.rb
21
23
  - lib/Rubbit/Rubbit_Construction_Layer.rb
22
24
  - lib/Rubbit/Rubbit_Exceptions.rb
23
- - lib/Rubbit/Rubbit_Objects.rb
24
25
  homepage: http://rubygems.org/gems/rubbit
25
26
  licenses:
26
27
  - GPL v3
27
- metadata: {}
28
28
  post_install_message:
29
29
  rdoc_options: []
30
30
  require_paths:
31
31
  - lib
32
32
  required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
33
34
  requirements:
34
35
  - - ! '>='
35
36
  - !ruby/object:Gem::Version
36
37
  version: '0'
37
38
  required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
38
40
  requirements:
39
41
  - - ! '>='
40
42
  - !ruby/object:Gem::Version
41
43
  version: '0'
42
44
  requirements: []
43
45
  rubyforge_project:
44
- rubygems_version: 2.2.2
46
+ rubygems_version: 1.8.23
45
47
  signing_key:
46
- specification_version: 4
48
+ specification_version: 3
47
49
  summary: Ruby API Wrapper for Reddit
48
50
  test_files: []
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NjljN2VjOTY3MGYwMjg4YzY5YWU3MTExNTc4MDE5NzEyYTI1OGY5OQ==
5
- data.tar.gz: !binary |-
6
- ZWQ3MTc4YTY5MjQyYzcxMDk3YjViZjE1NTA3NDU3NDk0NDg0MDkwMQ==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- N2JmNmRkMmJjOGIxZDc0MDY2NmU2OWVhZTE1YjlhZTEwYzA2NTE1ZTY5ZDVm
10
- OGViM2ZkMjdiMzk5ZDk2M2I0MWVlNzc3ZWVhMzNhZWY3ZjI4M2VmMDgwOTVl
11
- NTA1OTE5NmIzY2VlYTliMzI0ZjkxY2M5MWJlNzZkMzhjZjExYjk=
12
- data.tar.gz: !binary |-
13
- NmM3ZGIyYWZlZGYwYjBkZWY4YmFmYmNmMWFjYWQ5ZDkzNDI4ZjcxM2VhY2Fl
14
- MWE1MDYwMTBmMjJjYzk5MWJjMzRkYzNjNzcwYzExZDc4YmUwMjgzYTM3Mjg4
15
- ZDk1MTI4MGFhMzBlMzJlOGU5NGIzMDk3NGFkNzZhMTFmNWE0NTk=