Rubbit 0.0.2 → 0.0.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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGFiNTJkOWZmODhjYTNlNjllNmViNzc0YmIxN2Y3MTRiMmJlMzcyYQ==
4
+ MWM2ZjJkMzM2YjNjMmRmMGVmZTFkNTBmZTQ5ZDk1OTEyNWM0NzkwYw==
5
5
  data.tar.gz: !binary |-
6
- MDkzZGNiNmFlYjFiYjAwZGM0MWUzZDg0MjZlNDBjZmE0MmJmM2Q3ZA==
6
+ MTQ1ZTQ0MTI4NTI2NTc2ZTlhZGRhOGI1Y2YxMzRhNTA5YTk3NzRiMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MGQxNWFhZGFhYjU0MTMyYmE3NzAyNGI4ZGE2N2IxYmU3YjE2NzEwMmFkODkw
10
- ZDk1MzU2YjFkZWQ2NTYyYmRjNmE1MGQ3NjcyNWY1Y2E2Nzg3MGMyZGE1N2M5
11
- Y2NmYTYwYjRlOGEzOTY2YjcwYmZjMzQ3ZjVmOGMxODUyNWQ2NDk=
9
+ NWZmZDUwOThjYTg3N2MxZDI5MTc1MzJhOGZjZGJjNjkyY2U4MDVmZTQ2NjRl
10
+ Y2ExMjhiZjUxYmJjOWI1YmE3OGQxYTU4Mjc5NjY5NDFkNjUzNGVhNWI3NWRj
11
+ NjQyNmY4MWY2Zjk0NjFlYjExN2Y1N2M3ZGVhOTYzY2ViOWJhZWM=
12
12
  data.tar.gz: !binary |-
13
- MjkwMmMyYzcyYjJkMzk4MmM3Y2Q2NTM4MmZhZDNkMGQ0ZDdkOGZhMjM4YmYx
14
- MTVkNDRlYzE3YjVmZjE0ZWU3ZTQyNzA4ZGY5Y2QyMjhlMmZhNzVlYzQ0ZTlk
15
- NjgyN2UwYTg3YjAxMzU0Njg4ZmRmZmMwYWFjZjA0Y2Q5MTA4OTA=
13
+ MWZkMmE1NzgwNGUxZmYwMThiMDA2Mzk0YjIwOWM1ODU5OTE5YzAxZjBkMDM0
14
+ Y2YwY2Q3N2FkNDg5MDZjMjBjMWY4ODdmZWJlYWU2MmY0MDViOWYzYTg2MzZl
15
+ ODc1NzBkZWZlZDU4ZDI3NGY4ZTM5NjJiZmQwNzI3Y2JmNmE0OWI=
data/lib/Rubbit.rb CHANGED
@@ -141,4 +141,11 @@ class Rubbit
141
141
  end
142
142
  return nil
143
143
  end
144
+
145
+ def comment(text,parent)
146
+ if(@me!=nil)
147
+ return @rubbut_poster.comment(text,parent)
148
+ end
149
+ return nil
150
+ end
144
151
  end
@@ -94,7 +94,7 @@ class Reddit_Net_Wrapper
94
94
  }
95
95
 
96
96
  if(res.code=='302' or res.code=='301')
97
- res = make_request(request_type,res['location'],true)
97
+ res = make_request(request_type,res['location'],params,true)
98
98
  elsif(res['set-cookie']!=nil)
99
99
  @cookie=res['set-cookie']
100
100
  end
@@ -46,7 +46,7 @@ class Rubbit_Object_Builder
46
46
  def build_submission(link)
47
47
  response = Reddit_Net_Wrapper.instance.make_request('get',link.to_s+".json",{})
48
48
  if(response.code=='200')
49
- json = JSON.parse(response.body)
49
+ json = JSON.parse(response.body,:max_nesting=>100)
50
50
  if(json['kind']=='t1')
51
51
  return Comment.new(json)
52
52
  elsif(json['kind']=='t3')
@@ -59,6 +59,15 @@ class Rubbit_Object_Builder
59
59
  end
60
60
  end
61
61
 
62
+ def get_comments(link)
63
+ response = Reddit_Net_Wrapper.instance.make_request('get',link.to_s+".json",{})
64
+ if(response.code=='200')
65
+ json = JSON.parse(response.body,:max_nesting=>100)
66
+ return Listing.new(json[1])
67
+ end
68
+ return
69
+ end
70
+
62
71
  private_class_method :new
63
72
  end
64
73
 
@@ -151,9 +160,7 @@ class Rubbit_Poster
151
160
  params['extension']=nil
152
161
  params['kind']=kind
153
162
  params['resubmit']=resubmit
154
- if(save)
155
- params['save']=true
156
- end
163
+ params['save']=save
157
164
  params['sendreplies']=sendreplies
158
165
  params['id']='#newlink'
159
166
  params['sr']=sr
@@ -163,11 +170,27 @@ class Rubbit_Poster
163
170
  params['uh']=get_modhash
164
171
  params['url']=url
165
172
 
166
- puts params
167
-
168
173
  response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/submit/',params)
169
174
  return JSON.parse(response.body)
175
+ end
176
+
177
+ def comment(text,parent)
178
+ params = {}
179
+ params['text']=text
180
+ params['thing_id']=parent
181
+ params['uh']=get_modhash
182
+ params['renderstylel']='html'
183
+
184
+ puts params
185
+
186
+ response = Reddit_Net_Wrapper.instance.make_request('post','http://www.reddit.com/api/comment',params)
170
187
 
188
+ puts response.code
189
+
190
+ if(response.code=='200')
191
+ return true
192
+ end
193
+ return false
171
194
  end
172
195
 
173
196
  def get_modhash
@@ -38,6 +38,14 @@ class Subreddit
38
38
  def submit(title,url=nil,text=nil,kind='self',resubmit=false,save=false,sendreplies=true)
39
39
  return Rubbit_Poster.instance.submit(@display_name,title,url,text,kind,resubmit,save,sendreplies)
40
40
  end
41
+
42
+ def submit_text(title,text=nil,save=false,sendreplies=true)
43
+ return submit(title,nil,text,'self',false,save,sendreplies)
44
+ end
45
+
46
+ def submit_link(title,url,save=false,sendreplies=true)
47
+ return submit(title,url,nil,'link',false,save,sendreplies)
48
+ end
41
49
  end
42
50
 
43
51
  class Redditor
@@ -71,12 +79,14 @@ class ContentGenerator
71
79
  @source = nil
72
80
  @data = nil
73
81
  @after = nil
82
+ @modhash = nil
74
83
  def initialize(source,limit=100,after='')
75
84
  @source = source
76
85
  @limit = limit
77
86
  @count = 0
78
87
  @data = []
79
88
  @after = after
89
+ @modhash = nil
80
90
  end
81
91
 
82
92
  def each
@@ -159,6 +169,23 @@ class ContentGenerator
159
169
  def length
160
170
  return @data.length
161
171
  end
172
+
173
+ def next
174
+ listing = Rubbit_Object_Builder.instance.build_listing(@source+'?limit='+1.to_s+"&after="+@after+"&count="+@count.to_s)
175
+ if(listing.children[listing.children.length-1]!=nil)
176
+ @after = listing.children[listing.children.length-1].name
177
+ else
178
+ @after = nil
179
+ end
180
+ if(@after == nil)
181
+ @data+=[]
182
+ return nil
183
+ else
184
+ @data += listing.children
185
+ @count+= listing.children.length
186
+ return listing.children[0]
187
+ end
188
+ end
162
189
  end
163
190
 
164
191
  class Comment
@@ -171,10 +198,16 @@ class Comment
171
198
  end
172
199
  end
173
200
  end
201
+
202
+ def reply(text)
203
+ Rubbit_Poster.instance.comment(text,@name)
204
+ end
174
205
  end
175
206
 
176
207
  class Post
208
+ @comments = nil
177
209
  def initialize(json)
210
+ @comments = nil
178
211
  if(json['kind']=='t3')
179
212
  data = json['data']
180
213
  data.each_key do |k|
@@ -183,6 +216,16 @@ class Post
183
216
  end
184
217
  end
185
218
  end
219
+ def reply(text)
220
+ return Rubbit_Poster.instance.comment(text,@name)
221
+ end
222
+
223
+ def comments
224
+ if(@comments==nil)
225
+ @comments = Rubbit_Object_Builder.instance.get_comments('http://www.reddit.com'+@permalink).children
226
+ end
227
+ return @comments
228
+ end
186
229
  end
187
230
 
188
231
  class Message
@@ -195,6 +238,9 @@ class Message
195
238
  end
196
239
  end
197
240
  end
241
+ def reply(text)
242
+ Rubbit_Poster.instance.comment(text,@name)
243
+ end
198
244
  end
199
245
 
200
246
  class Listing
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.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - /u/The1RGood