Rubbit 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ODRiMzU0YWQxNzRkNmM1MDUzNDJkMDQ0N2IwYTE0MGY0N2E1YWNlOQ==
4
+ NjljN2VjOTY3MGYwMjg4YzY5YWU3MTExNTc4MDE5NzEyYTI1OGY5OQ==
5
5
  data.tar.gz: !binary |-
6
- MTI5YWEwNzYwYzY4ZDliMDkyZjlhMzNiMWM3NTAzODllMWY1NDgxMw==
6
+ ZWQ3MTc4YTY5MjQyYzcxMDk3YjViZjE1NTA3NDU3NDk0NDg0MDkwMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWMyOGI1NzQ2MWU0NDUyMzliYWNjYTUwZjk0OWM5NWUzMTI0YTQwNTAzNjE1
10
- YmEzYTUxNzU3MDI2NjJjNzYwMzY2Y2E2YWRmMTdkNjJmMzBhYjM3N2Y4YTE3
11
- ZWUxMzg2MWM0YWI0Yjg1MTY5ZDZkYmU5NmEwMjdmNGJjYWZjMDE=
9
+ N2JmNmRkMmJjOGIxZDc0MDY2NmU2OWVhZTE1YjlhZTEwYzA2NTE1ZTY5ZDVm
10
+ OGViM2ZkMjdiMzk5ZDk2M2I0MWVlNzc3ZWVhMzNhZWY3ZjI4M2VmMDgwOTVl
11
+ NTA1OTE5NmIzY2VlYTliMzI0ZjkxY2M5MWJlNzZkMzhjZjExYjk=
12
12
  data.tar.gz: !binary |-
13
- ZTQ1YTJiNzIwZTA1ZDY0OGZmODI5ZjU2MjZkZmVkMjM1NGMxYmRmYWI2NTU4
14
- MDFlNmIwOGZlMjgxMTNhZjAzMGE5NTk5ZGQxZGRlYjNlMDFjYmY1MTBlNzY4
15
- N2Q0MzI1Yzg2MmYyZDllNjFiYTYxYTNkYzQ3NmNjNGUwNWQ4N2U=
13
+ NmM3ZGIyYWZlZGYwYjBkZWY4YmFmYmNmMWFjYWQ5ZDkzNDI4ZjcxM2VhY2Fl
14
+ MWE1MDYwMTBmMjJjYzk5MWJjMzRkYzNjNzcwYzExZDc4YmUwMjgzYTM3Mjg4
15
+ ZDk1MTI4MGFhMzBlMzJlOGU5NGIzMDk3NGFkNzZhMTFmNWE0NTk=
@@ -2,9 +2,20 @@ require 'Rubbit/Rubbit_Objects'
2
2
  require 'Rubbit/Rubbit_Construction_Layer'
3
3
  require 'io/console'
4
4
 
5
+ # == Rubbit Client
6
+ #
7
+ # Contains highest level Rubbit functionality
8
+ #
5
9
  class Rubbit
6
10
  attr_accessor :client_name, :object_builder, :rubbit_poster, :me
7
11
 
12
+ # ==== Description
13
+ #
14
+ # Initialize the Rubbit client with an ID that's added to the user agent
15
+ #
16
+ # ==== Attributes
17
+ #
18
+ # * +name+ - Attribute that identifies the bot using Rubbit. Is added to the user-agent.
8
19
  def initialize(name)
9
20
  @client_name = name
10
21
  @object_builder = Rubbit_Object_Builder.instance(name)
@@ -12,18 +23,49 @@ class Rubbit
12
23
  @me = nil
13
24
  end
14
25
 
26
+ # ==== Description
27
+ #
28
+ # Gets a Subreddit object, created by subreddit name
29
+ #
30
+ # ==== Attributes
31
+ #
32
+ # * +display_name+ - Display name of the subreddit a user wishes to create an object representation for
15
33
  def get_subreddit(display_name)
16
34
  return @object_builder.build_subreddit(display_name)
17
35
  end
18
36
 
37
+ # ==== Description
38
+ #
39
+ # Gets a Redditor object, created by username
40
+ #
41
+ # ==== Attributes
42
+ #
43
+ # * +user+ - That Redditor's username
19
44
  def get_redditor(user)
20
45
  return @object_builder.build_user(user)
21
46
  end
22
47
 
48
+ # ==== Description
49
+ #
50
+ # Gets a Subreddit object, created by subreddit name
51
+ #
52
+ # ==== Attributes
53
+ #
54
+ # * +display_name+ - Display name of the subreddit a user wishes to create an object representation for
23
55
  def set_request_period(period)
24
56
  @object_builder.set_request_period(period)
25
57
  end
26
58
 
59
+ # ==== Description
60
+ #
61
+ # Login to Reddit and create a session.
62
+ # User and passwd are *not* required. This function will prompt the user for missing information at runtime.
63
+ #
64
+ # ==== Attributes
65
+ #
66
+ # * +user+ - Username that you wish to log in with
67
+ # * +passwd+ - Password required to log in with that user
68
+ #
27
69
  def login(user=nil,passwd=nil)
28
70
  if(user==nil)
29
71
  print('Enter username: ')
@@ -38,17 +80,35 @@ class Rubbit
38
80
  return @me
39
81
  end
40
82
 
41
- def clear_session(curpass=nil,uh=nil)
83
+ # ==== Description
84
+ #
85
+ # Clears the current session.
86
+ #
87
+ # ==== Attributes
88
+ #
89
+ # * +curpass+ - Password required to log in with that user
90
+ #
91
+ def clear_session(curpass=nil)
42
92
  if(@me==nil)
43
93
  print('Not logged in. No session to clear')
44
94
  elsif(curpass==nil)
45
95
  print('Enter password for '+user.to_s+': ')
46
96
  passwd = STDIN.noecho(&:gets).chomp
47
97
  end
48
- return @rubbit_poster.clear_sessions(curpass,uh)
49
- end
50
-
51
- def delete_user(user=nil,passwd=nil,message="",uh=nil)
98
+ return @rubbit_poster.clear_sessions(curpass)
99
+ end
100
+
101
+ # ==== Description
102
+ #
103
+ # Deletes desired user. Requires auth info for that user.
104
+ #
105
+ # ==== Attributes
106
+ #
107
+ # * +user+ - Username of account you wish to delete.
108
+ # * +passwd+ - Password required to log in with that user
109
+ # * +message+ - Reason for deleting account.
110
+ #
111
+ def delete_user(user=nil,passwd=nil,message="")
52
112
  confirm = nil
53
113
  if(user==nil)
54
114
  print('Enter username: ')
@@ -71,7 +131,7 @@ class Rubbit
71
131
  end
72
132
  end
73
133
 
74
- return @rubbit_poster.delete_user(user,passwd,confirm,message,@me.uh)
134
+ return @rubbit_poster.delete_user(user,passwd,confirm,message)
75
135
  end
76
136
 
77
137
  def get_me()
@@ -29,6 +29,7 @@ class Reddit_Net_Wrapper
29
29
 
30
30
  def set_reset_period(period=60)
31
31
  if(period%2!=0 or period>60 or period<2)
32
+ print('Reset period must be an even integer between 2 and 60')
32
33
  return false
33
34
  else
34
35
  @reset_timer = period
@@ -126,7 +126,7 @@ class Rubbit_Poster
126
126
  return response.body
127
127
  end
128
128
 
129
- def delete_user(user,passwd,message,confirm)
129
+ def delete_user(user,passwd,message)
130
130
  params = {}
131
131
  params['api_type']='json'
132
132
  params['user']=user
@@ -1,8 +1,10 @@
1
1
  require 'Rubbit/Reddit_Net_Wrapper'
2
2
  require 'Rubbit/Rubbit_Exceptions'
3
3
 
4
- # == Subreddit
4
+ # == Rubbit Object
5
+ #
5
6
  # Object Representing a Subreddit.
7
+ #
6
8
  class Subreddit
7
9
  def initialize(json)
8
10
  if(json['kind']=='t5')
@@ -170,8 +172,8 @@ class Subreddit
170
172
  #
171
173
  # * +limit+ - Maximum entries that the returned ContentGenerator will hold. For no limit, use *nil*
172
174
  #
173
- def get_moderators(limit=100)
174
- return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/moderators.json',limit)
175
+ def get_moderators
176
+ return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/moderators.json',nil)
175
177
  end
176
178
 
177
179
 
@@ -250,6 +252,12 @@ class Subreddit
250
252
  end
251
253
  end
252
254
 
255
+ # == Rubbit Object
256
+ #
257
+ # Object Representing a Redditor.
258
+ # If the requested Redditor is logged in, this object also contains a modhash.
259
+ # If obtained from a subreddit list, this object will need to be rebuilt using the rebuild function
260
+ #
253
261
  class Redditor
254
262
  def initialize(json)
255
263
  if(json['kind']=='t2')
@@ -267,18 +275,49 @@ class Redditor
267
275
  end
268
276
  end
269
277
 
278
+ # ==== Description
279
+ #
280
+ # Function for getting user overview content from a profile, including both comments and posts
281
+ #
282
+ # ==== Attributes
283
+ #
284
+ # * +limit+ - Maximum entries that the ContentGenerator can contain
285
+ # * +sort+ - Sort order by which the content is returned
286
+ #
270
287
  def get_overview(limit=100,sort='new')
271
288
  return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/.json?sort='+sort,limit)
272
289
  end
273
290
 
291
+ # ==== Description
292
+ #
293
+ # Function for getting user comment from a profile
294
+ #
295
+ # ==== Attributes
296
+ #
297
+ # * +limit+ - Maximum entries that the ContentGenerator can contain
298
+ # * +sort+ - Sort order by which the content is returned
299
+ #
274
300
  def get_comments(limit=100,sort='new')
275
301
  return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/comments.json?sort='+sort,limit)
276
302
  end
277
303
 
304
+ # ==== Description
305
+ #
306
+ # Function for getting user posts from a profile
307
+ #
308
+ # ==== Attributes
309
+ #
310
+ # * +limit+ - Maximum entries that the ContentGenerator can contain
311
+ # * +sort+ - Sort order by which the content is returned
312
+ #
278
313
  def get_submitted(limit=100,sort='new')
279
314
  return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/submitted.json?sort='+sort,limit)
280
315
  end
281
316
 
317
+ # ==== Description
318
+ #
319
+ # Function for rebuilding user object using data from their profile page
320
+ #
282
321
  def rebuild
283
322
  rebuilt_user = Rubbit_Object_Builder.instance.build_user(@name)
284
323
  rebuilt_user.instance_variables.each do |attr_name|
@@ -288,6 +327,10 @@ class Redditor
288
327
  end
289
328
  end
290
329
 
330
+ # == Rubbit Object
331
+ #
332
+ # Enumerable object that allows a user to iterate over data sets
333
+ #
291
334
  class ContentGenerator
292
335
  include Enumerable
293
336
  @limit = nil
@@ -297,6 +340,18 @@ class ContentGenerator
297
340
  @after = nil
298
341
  @modhash = nil
299
342
  @index
343
+ @limit_param
344
+
345
+ # ==== Description
346
+ #
347
+ # Initializes a ContentGenerator Object
348
+ #
349
+ # ==== Attributes
350
+ #
351
+ # * +source+ - *Required.* Link to the .json page for the content
352
+ # * +limit+ - Maximum number of entries the ContentGenerator will load. *nil* for no limit.
353
+ # * +after+ - ID of entry to load content after.
354
+ #
300
355
  def initialize(source,limit=100,after='')
301
356
  @source = source
302
357
  @limit = limit
@@ -304,19 +359,28 @@ class ContentGenerator
304
359
  @data = []
305
360
  @after = after
306
361
  @index = 0
362
+ if(@source.include?('?'))
363
+ @limit_param = '&limit='
364
+ else
365
+ @limit_param = '?limit='
366
+ end
307
367
  end
308
368
 
369
+ # ==== Description
370
+ #
371
+ # Iterates over the content from a specific source until there is no content left or until a limit is reached
372
+ #
309
373
  def each
310
374
  if(@data.length==0)
311
375
  if(@limit!=nil)
312
376
  if(@limit-@count>0)
313
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
377
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
314
378
  @after = listing.after
315
379
  @data += listing.children
316
380
  @count += listing.children.length
317
381
  end
318
382
  else
319
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+100.to_s+"&after="+@after+"&count="+@count.to_s)
383
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+100.to_s+"&after="+@after+"&count="+@count.to_s)
320
384
  @after = listing.after
321
385
  @data += listing.children
322
386
  @count+= listing.children.length
@@ -332,14 +396,14 @@ class ContentGenerator
332
396
  end
333
397
  if(@limit!=nil)
334
398
  if(@limit-@count>0)
335
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
399
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+@limit_param+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
336
400
  @after = listing.after
337
401
  @data += listing.children
338
402
  @count += listing.children.length
339
403
  end
340
404
  else
341
- listing = Rubbit_Object_Builder.instance.build_listing(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
342
- puts(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
405
+ 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)
343
407
  @after = listing.after
344
408
  @data += listing.children
345
409
  @count += listing.children.length
@@ -348,10 +412,22 @@ class ContentGenerator
348
412
  end
349
413
  end
350
414
 
351
- def [](i)
352
- return @data[i]
415
+ # ==== Description
416
+ #
417
+ # Returns an object in the ContentGenerator at a particular index. Only works after it has been iterated through and loaded.
418
+ #
419
+ # ==== Attributes
420
+ #
421
+ # * +index+ - The index of the object in the ContentGenerator that will be returned.
422
+ #
423
+ def [](index)
424
+ return @data[index]
353
425
  end
354
426
 
427
+ # ==== Description
428
+ #
429
+ # Returns the next object in the ContentGenerator. If none is loaded, it will try to load more, until a limit is reached.
430
+ #
355
431
  def next
356
432
  if(@index>=@data.length)
357
433
  if(@limit!=nil)
@@ -376,6 +452,10 @@ class ContentGenerator
376
452
  return to_return
377
453
  end
378
454
 
455
+ # ==== Description
456
+ #
457
+ # Returns the previous object in the ContentGenerator. If the index is at 0, nil is returned
458
+ #
379
459
  def prev
380
460
  if(@index>1)
381
461
  @index-=1
@@ -385,15 +465,31 @@ class ContentGenerator
385
465
  end
386
466
  end
387
467
 
388
- def reset_generator(i=0)
389
- @index=i
468
+ # ==== Description
469
+ #
470
+ # Resets the index of the current entry in ContentGenerator
471
+ #
472
+ # ==== Attributes
473
+ #
474
+ # * +index+ - The index that the ContentGenerator will be set to. Defaults to 0.
475
+ #
476
+ def reset_generator(index=0)
477
+ @index=index
390
478
  end
391
479
 
480
+ # ==== Description
481
+ #
482
+ # Returns the length of data already loaded into the ContentGenerator.
483
+ #
392
484
  def length
393
485
  return @data.length
394
486
  end
395
487
  end
396
488
 
489
+ # == Rubbit Object
490
+ #
491
+ # Object that represents an individual comment
492
+ #
397
493
  class Comment
398
494
  def initialize(json)
399
495
  if(json['kind']=='t1')
@@ -417,23 +513,51 @@ class Comment
417
513
  end
418
514
  end
419
515
 
516
+ # ==== Description
517
+ #
518
+ # Submits a reply to a comment.
519
+ #
520
+ # ==== Attributes
521
+ #
522
+ # * +text+ - The body of the response
523
+ #
420
524
  def reply(text)
421
525
  Rubbit_Poster.instance.comment(@name,text)
422
526
  end
423
527
 
528
+ # ==== Description
529
+ #
530
+ # Deletes this comment. Only works if the comment was made by you.
531
+ #
424
532
  def delete
425
533
  Rubbit_Poster.instance.delete(@name)
426
534
  end
427
535
 
536
+ # ==== Description
537
+ #
538
+ # Modifies the text of this comment. Only works if the comment was made by you.
539
+ #
540
+ # ==== Attributes
541
+ #
542
+ # * +text+ - The new comment body.
543
+ #
428
544
  def edit(text)
429
545
  Rubbit_Poster.instance.edit(@name,text)
430
546
  end
431
547
 
548
+ # ==== Description
549
+ #
550
+ # No longer shows the comment to you on Reddit.
551
+ #
432
552
  def hide
433
553
  Rubbit_Poster.instance.hide(@name)
434
554
  end
435
555
  end
436
556
 
557
+ # == Rubbit Object
558
+ #
559
+ # Object representing a Reddit Post
560
+ #
437
561
  class Post
438
562
  @comments = nil
439
563
  def initialize(json)
@@ -446,10 +570,23 @@ class Post
446
570
  end
447
571
  end
448
572
  end
573
+
574
+ # ==== Description
575
+ #
576
+ # Makes a reply to a post
577
+ #
578
+ # ==== Attributes
579
+ #
580
+ # * +text+ - The new comment body.
581
+ #
449
582
  def reply(text)
450
583
  return Rubbit_Poster.instance.comment(@name,text)
451
584
  end
452
585
 
586
+ # ==== Description
587
+ #
588
+ # Retrieves the comments of a post in a list tree.
589
+ #
453
590
  def replies
454
591
  if(@comments==nil)
455
592
  @comments = Rubbit_Object_Builder.instance.get_comments('http://www.reddit.com'+@permalink).children
@@ -457,23 +594,47 @@ class Post
457
594
  return @comments
458
595
  end
459
596
 
597
+ # ==== Description
598
+ #
599
+ # Deletes this post. Only works if you made the post.
600
+ #
460
601
  def delete
461
602
  Rubbit_Poster.instance.delete(@name)
462
603
  end
463
604
 
605
+ # ==== Description
606
+ #
607
+ # Modifies the text of this post. Only works if the post was made by you and is a self post.
608
+ #
609
+ # ==== Attributes
610
+ #
611
+ # * +text+ - The new post body.
612
+ #
464
613
  def edit(text)
465
614
  Rubbit_Poster.instance.edit(@name,text)
466
615
  end
467
616
 
617
+ # ==== Description
618
+ #
619
+ # Hides the post and no longer displays it when retrieving Reddit data
620
+ #
468
621
  def hide
469
622
  Rubbit_Poster.instance.hide(@name)
470
623
  end
471
624
 
625
+ # ==== Description
626
+ #
627
+ # Marks a post as NSFW. Only works if you made the post or are a moderator of the subreddit it is in.
628
+ #
472
629
  def mark_nsfw
473
630
  Rubbit_Poster.instance.mark_nsfw(@name)
474
631
  end
475
632
  end
476
633
 
634
+ # == Rubbit Object
635
+ #
636
+ # Object that represents a Personal Message
637
+ #
477
638
  class Message
478
639
  def initialize(json)
479
640
  if(json['kind']=='t4')
@@ -485,6 +646,14 @@ class Message
485
646
  end
486
647
  end
487
648
 
649
+ # ==== Description
650
+ #
651
+ # Responds to an inbox message.
652
+ #
653
+ # ==== Attributes
654
+ #
655
+ # * +text+ - The new message body.
656
+ #
488
657
  def reply(text)
489
658
  Rubbit_Poster.instance.comment(text,@name)
490
659
  end
@@ -493,7 +662,8 @@ end
493
662
  class Listing
494
663
  @after = nil
495
664
  def initialize(json)
496
- if(json['kind']=='Listing')
665
+ if(json['kind']=='Listing' or json['kind']=='UserList')
666
+ @after = nil
497
667
  data = json['data']
498
668
  data.each_key do |k|
499
669
  self.class.module_eval {attr_accessor(k)}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Rubbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - /u/The1RGood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-13 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple Ruby-based Reddit API Wrapper
14
14
  email: randy@kindofabigdeal.org