ruby_reddit_api 0.2.0 → 0.2.1
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.
- data/README +1 -1
- data/features/step_definitions/submission_steps.rb +5 -5
- data/features/step_definitions/user_steps.rb +2 -0
- data/lib/ruby_reddit_api.rb +10 -9
- data/lib/ruby_reddit_api/base.rb +1 -1
- data/lib/ruby_reddit_api/comment.rb +12 -1
- data/lib/ruby_reddit_api/json_listing.rb +1 -1
- data/lib/ruby_reddit_api/submission.rb +4 -15
- data/lib/ruby_reddit_api/thing.rb +1 -1
- data/lib/ruby_reddit_api/user.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -53,11 +53,6 @@ Then /^I should be able to downvote it$/ do
|
|
53
53
|
@submission.downvote.should be true
|
54
54
|
end
|
55
55
|
|
56
|
-
Then /^I should be able to see the comments$/ do
|
57
|
-
comments = @submission.comments
|
58
|
-
comments.size.should > 0
|
59
|
-
end
|
60
|
-
|
61
56
|
Then /^I should not be able to save the submission$/ do
|
62
57
|
@submission.save.should be false
|
63
58
|
end
|
@@ -115,3 +110,8 @@ end
|
|
115
110
|
Then /^I should be able to indistinguish the submission$/ do
|
116
111
|
@submission.indistinguish
|
117
112
|
end
|
113
|
+
|
114
|
+
Then /^I should be able to see the comments$/ do
|
115
|
+
comments = @submission.comments
|
116
|
+
comments.size.should > 0
|
117
|
+
end
|
data/lib/ruby_reddit_api.rb
CHANGED
@@ -5,13 +5,14 @@ end
|
|
5
5
|
|
6
6
|
require "httparty"
|
7
7
|
require "json"
|
8
|
-
require "
|
9
|
-
require "
|
10
|
-
require "
|
11
|
-
require "
|
12
|
-
require "
|
13
|
-
require "
|
14
|
-
require "
|
15
|
-
require "
|
16
|
-
require "
|
8
|
+
require "ruby_reddit_api/version"
|
9
|
+
require "ruby_reddit_api/json_listing"
|
10
|
+
require "ruby_reddit_api/base"
|
11
|
+
require "ruby_reddit_api/thing"
|
12
|
+
require "ruby_reddit_api/api"
|
13
|
+
require "ruby_reddit_api/user"
|
14
|
+
require "ruby_reddit_api/vote"
|
15
|
+
require "ruby_reddit_api/submission"
|
16
|
+
require "ruby_reddit_api/comment"
|
17
|
+
require "ruby_reddit_api/message"
|
17
18
|
|
data/lib/ruby_reddit_api/base.rb
CHANGED
@@ -103,7 +103,7 @@ module Reddit
|
|
103
103
|
|
104
104
|
def capture_user_id
|
105
105
|
return true if user_id
|
106
|
-
this_user = read("/user/#{user}/about.json", :handler => "User")
|
106
|
+
this_user = read("/user/#{user}/about.json", :handler => "User")[0]
|
107
107
|
Reddit::Base.instance_variable_set("@user_id", this_user.id)
|
108
108
|
end
|
109
109
|
|
@@ -3,7 +3,7 @@ module Reddit
|
|
3
3
|
class Comment < Thing
|
4
4
|
|
5
5
|
include JsonListing
|
6
|
-
attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :
|
6
|
+
attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :num_comments, :subreddit, :ups, :debug, :kind
|
7
7
|
def initialize(json)
|
8
8
|
parse(json)
|
9
9
|
@debug = StringIO.new
|
@@ -18,6 +18,17 @@ module Reddit
|
|
18
18
|
body
|
19
19
|
end
|
20
20
|
|
21
|
+
# Fetch comments
|
22
|
+
# @return [Array<Reddit::Comment>]
|
23
|
+
def comments
|
24
|
+
opts = {:handler => "Comment",
|
25
|
+
:verb => "post",
|
26
|
+
:body =>
|
27
|
+
{:link_id => id, :depth => 10, :r => subreddit, :uh => modhash, :renderstyle => "json", :pv_hex => "", :id => id}
|
28
|
+
}
|
29
|
+
return read("/api/morechildren", opts )
|
30
|
+
end
|
31
|
+
|
21
32
|
# Modify a comment
|
22
33
|
# @return [true,false]
|
23
34
|
def edit(newtext)
|
@@ -20,7 +20,7 @@ module Reddit
|
|
20
20
|
data = json["data"]
|
21
21
|
Reddit::Base.instance_variable_set("@modhash", data["modhash"]) # Needed for api calls
|
22
22
|
|
23
|
-
children = data["children"]
|
23
|
+
children = data["children"] || [{"data" => data, "kind" => json["kind"] }]
|
24
24
|
children.each do |message|
|
25
25
|
kind = message["kind"]
|
26
26
|
message["data"]["kind"] = kind
|
@@ -55,21 +55,10 @@ module Reddit
|
|
55
55
|
# Fetch submission comments
|
56
56
|
# @todo Move to 'Thing' class
|
57
57
|
# @return [Array<Reddit::Comment>]
|
58
|
-
def comments
|
59
|
-
|
60
|
-
if
|
61
|
-
|
62
|
-
:verb => "post",
|
63
|
-
:body =>
|
64
|
-
{:link_id => last_comment_id, :depth => 0, :r => subreddit, :uh => modhash, :renderstyle => "json", :pv_hex => "", :id => id}
|
65
|
-
}
|
66
|
-
return read("/api/morechildren", opts )
|
67
|
-
|
68
|
-
else
|
69
|
-
_comments = read( permalink + ".json", {:handler => "Comment", :query => {:limit => 50}} )
|
70
|
-
@last_comment_id = _comments.last.id if _comments && _comments.any?
|
71
|
-
return _comments
|
72
|
-
end
|
58
|
+
def comments
|
59
|
+
_comments = read( permalink + ".json", {:handler => "Comment", :query => {:limit => 250}} )
|
60
|
+
@last_comment_id = _comments.last.id if _comments && _comments.any?
|
61
|
+
return _comments
|
73
62
|
end
|
74
63
|
|
75
64
|
protected
|
@@ -17,7 +17,7 @@ module Reddit
|
|
17
17
|
# The author of the entity. The data is lazy-loaded and cached on the object
|
18
18
|
# @return [Reddit::User]
|
19
19
|
def author
|
20
|
-
@author_data ||= read("/user/#{@author}/about.json", :handler => "User")
|
20
|
+
@author_data ||= read("/user/#{@author}/about.json", :handler => "User")[0]
|
21
21
|
end
|
22
22
|
|
23
23
|
# Upvote thing
|
data/lib/ruby_reddit_api/user.rb
CHANGED