Rubbit 0.0.6 → 0.0.7

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGFmMGJmOTMxYjQzNjhmNmE2ZGZlOGU0NDQyMTRkZWRjMmY3Njg4MQ==
4
+ NzY2MmNhYTY2ZmExYjJmZWE4N2U3OTBjYzA0YjUxMzVlMjc3NmE4Yw==
5
5
  data.tar.gz: !binary |-
6
- MTIzYmQ5NTZkNjBmZTMxNGE2NDAyZDkxNmNkMmY2NzY4NDFlYzg4NQ==
6
+ ZmQyMzA3OThhZmY2MmUyYTBkNjc1NDFmYTgyZjA3OTgxMjY2OTQyYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGY2MTM4OTJhMDI1ZjcwMjFjZDEzZjAxYTJjNWU3NDRiNjY5ODAxMWZjMDAx
10
- ZTMyY2M1NzgzYzdhMzU0ZWViOGFkMDViZjZiY2I3MzZlNDgyMjc0NGYzODY3
11
- MDU1MDhkMTllNGQ1MzAzYmM1NWRlZDQ1OTE5ZDM5ZjczNWI2MDI=
9
+ NTMwMzgzMzUyZTI3MzUwYzI4ZTM5YmMxMWJiMDBjYzU0YmI4NmViYzBjMjJi
10
+ ZjA2YzNkMTNkZDA0NTdkZDViNTBkZWU1MjE5Y2QzOTBhZjBiNTExMTI5MTJi
11
+ NTI4NGYxMmUxYWE2YzUzMzg1NWEyMGMwMzkyN2U1ZWU2NWQ0NWI=
12
12
  data.tar.gz: !binary |-
13
- YzM1ZDRjZTdlZGFkMzZjZWM0MTllNDkwZjA5ZTMxY2Y2NzJkYzliNWNiMzRk
14
- MDQ0YzA1M2YzMDNiYTY0ZjgyOGJmZjY0ZTg3MGNlNzNkMDJmNTA1ZmZiZjUw
15
- NWEzZDBkMGIyOGIzMTBiYjEwMGM3MDAyYjdkM2NlYjY5ZWZkZWQ=
13
+ YTg2YTY5ZmQxZjA5Mjk1NWQyZTE4ZmM3ZDMxOTNjNjY5NGY0ZDE1NDU1MWU0
14
+ ZDNmYzc0YTE2Y2NjMDYwOWY2YzZiZWZmNTgzMTU4OGI3YzNlNmIyZTA0MGYw
15
+ OWM1ZGQzNGU0MjEzZWY2NTg3ZDQzNGY3ZGYyZjc3MDdkM2Q4NjM=
@@ -41,6 +41,7 @@ class Rubbit_Object_Builder
41
41
  if(response.code=='200')
42
42
  return Listing.new(JSON.parse(response.body,:max_nesting => 100))
43
43
  end
44
+ return nil
44
45
  end
45
46
 
46
47
  def build_submission(link)
@@ -46,6 +46,14 @@ class Subreddit
46
46
  def submit_link(title,url,save=false,sendreplies=true)
47
47
  return submit(title,url,nil,'link',false,save,sendreplies)
48
48
  end
49
+
50
+ def get_contributors(limit=100)
51
+ return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/contributors.json',limit)
52
+ end
53
+
54
+ def get_banned(limit=100)
55
+ return ContentGenerator.new('http://www.reddit.com/r/'+@display_name.to_s+'/about/banned.json',limit)
56
+ end
49
57
  end
50
58
 
51
59
  class Redditor
@@ -56,6 +64,12 @@ class Redditor
56
64
  self.class.module_eval {attr_accessor(k)}
57
65
  self.send("#{k}=",data[k])
58
66
  end
67
+ elsif(json['id'][0..2]=='t2_')
68
+ data = json
69
+ data.each_key do |k|
70
+ self.class.module_eval {attr_accessor(k)}
71
+ self.send("#{k}=",data[k])
72
+ end
59
73
  end
60
74
  end
61
75
 
@@ -70,6 +84,14 @@ class Redditor
70
84
  def get_submitted(limit=100)
71
85
  return ContentGenerator.new('http://www.reddit.com/user/'+@name.to_s+'/submitted.json',limit)
72
86
  end
87
+
88
+ def rebuild
89
+ rebuilt_user = Rubbit_Object_Builder.instance.build_user(@name)
90
+ rebuilt_user.instance_variables.each do |attr_name|
91
+ self.class.module_eval{attr_accessor(attr_name[1..-1])}
92
+ self.send("#{attr_name[1..-1]}=",rebuilt_user.instance_variable_get(attr_name))
93
+ end
94
+ end
73
95
  end
74
96
 
75
97
  class ContentGenerator
@@ -91,29 +113,17 @@ class ContentGenerator
91
113
 
92
114
  def each
93
115
  index = 0
94
- if(@limit!=nil)
95
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
96
- if(listing.children[listing.children.length-1]!=nil)
97
- @after = listing.children[listing.children.length-1].name
98
- else
99
- @after = nil
100
- end
101
- if(@after == nil)
102
- @data+=[]
103
- else
104
- @data += listing.children
105
- @count += listing.children.length
106
- end
107
- else
108
- listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+100.to_s+"&after="+@after+"&count="+@count.to_s)
109
- if(listing.children[listing.children.length-1]!=nil)
110
- @after = listing.children[listing.children.length-1].name
111
- else
112
- @after = nil
113
- end
114
- if(@after == nil)
115
- @data+=[]
116
+ if(@data.length==0)
117
+ if(@limit!=nil)
118
+ if(@limit-@count>0)
119
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
120
+ @after = listing.after
121
+ @data += listing.children
122
+ @count += listing.children.length
123
+ end
116
124
  else
125
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+100.to_s+"&after="+@after+"&count="+@count.to_s)
126
+ @after = listing.after
117
127
  @data += listing.children
118
128
  @count+= listing.children.length
119
129
  end
@@ -124,39 +134,21 @@ class ContentGenerator
124
134
  index+=1
125
135
  if(index==@data.length)
126
136
  if(@after==nil)
127
- @after=''
137
+ break
128
138
  end
129
139
  if(@limit!=nil)
130
140
  if(@limit-@count>0)
131
141
  listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+[@limit-@count,100].min.to_s+"&after="+@after+"&count="+@count.to_s)
132
- if(listing.children[listing.children.length-1]!=nil)
133
- @after = listing.children[listing.children.length-1].name
134
- else
135
- @after = nil
136
- end
137
- if(@after == nil)
138
- @data+=[]
139
- else
140
- @data += listing.children
141
- @count += listing.children.length
142
- end
143
- else
144
- @data += []
142
+ @after = listing.after
143
+ @data += listing.children
144
+ @count += listing.children.length
145
145
  end
146
146
  else
147
147
  listing = Rubbit_Object_Builder.instance.build_listing(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
148
148
  puts(@source+"?limit="+100.to_s+"&after="+@after+"&count="+@count.to_s)
149
- if(listing.children[listing.children.length-1]!=nil)
150
- @after = listing.children[listing.children.length-1].name
151
- else
152
- @after = nil
153
- end
154
- if(@after == nil)
155
- @data+=[]
156
- else
157
- @data += listing.children
158
- @count += listing.children.length
159
- end
149
+ @after = listing.after
150
+ @data += listing.children
151
+ @count += listing.children.length
160
152
  end
161
153
  end
162
154
  end
@@ -166,10 +158,6 @@ class ContentGenerator
166
158
  return @data[i]
167
159
  end
168
160
 
169
- def length
170
- return @data.length
171
- end
172
-
173
161
  def next
174
162
  listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+1.to_s+"&after="+@after+"&count="+@count.to_s)
175
163
  if(listing.children[listing.children.length-1]!=nil)
@@ -196,6 +184,18 @@ class Comment
196
184
  self.class.module_eval {attr_accessor(k)}
197
185
  self.send("#{k}=",data[k])
198
186
  end
187
+ children = []
188
+ if(@replies!= nil and @replies['data']!=nil and @replies['data']['children']!=nil)
189
+ @replies['data']['children'].each do |c|
190
+ if(c!=nil)
191
+ children += [Comment.new(c)]
192
+ end
193
+ end
194
+ @replies = children
195
+ end
196
+ if(@replies=="")
197
+ replies = nil
198
+ end
199
199
  end
200
200
  end
201
201
 
@@ -232,7 +232,7 @@ class Post
232
232
  return Rubbit_Poster.instance.comment(@name,text)
233
233
  end
234
234
 
235
- def comments
235
+ def replies
236
236
  if(@comments==nil)
237
237
  @comments = Rubbit_Object_Builder.instance.get_comments('http://www.reddit.com'+@permalink).children
238
238
  end
@@ -282,18 +282,20 @@ class Listing
282
282
  end
283
283
  children_objects = []
284
284
  @children.each do |c|
285
- case c['kind']
286
- when 't1'
285
+ if(c['id']==nil)
286
+ c['id']=' '
287
+ end
288
+ if(c['kind'] == 't1' or c['id'][0..2]=='t1_')
287
289
  children_objects += [Comment.new(c)]
288
- when 't2'
290
+ elsif(c['kind'] == 't2' or c['id'][0..2]=='t2_')
289
291
  children_objects += [Redditor.new(c)]
290
- when 't3'
292
+ elsif(c['kind'] == 't3' or c['id'][0..2]=='t3_')
291
293
  children_objects += [Post.new(c)]
292
- when 't4'
294
+ elsif(c['kind'] == 't4' or c['id'][0..2]=='t4_')
293
295
  children_objects += [Message.new(c)]
294
- when 't5'
296
+ elsif(c['kind'] == 't5' or c['id'][0..2]=='t5_')
295
297
  children_objects += [Subreddit.new(c)]
296
- when 'Listing'
298
+ elsif(c['kind'] == 'Listing')
297
299
  children_objects += [Listing.new(c)]
298
300
  end
299
301
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Rubbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - /u/The1RGood