reddit_archiver 0.0.1 → 0.0.2
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 +4 -4
- data/lib/reddit_archiver/account.rb +8 -9
- data/lib/reddit_archiver/comment.rb +2 -2
- data/lib/reddit_archiver/file_writer.rb +1 -1
- data/lib/reddit_archiver/version.rb +1 -1
- data/spec/account_spec.rb +6 -3
- data/spec/comment_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49db034fca6fc3ed9d26f4bbc5b24b4dad9667f0
|
4
|
+
data.tar.gz: 5e1dfe3b5a7784e75bae375e613ce7bcaf67f8a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8381752e87791e648f0cdcd36d4b32277b5716d460e581d1af4d48276749e370241b23fd88dd71ad623b201840813c8efbc4c32a767e90b886f35c5081d7c0
|
7
|
+
data.tar.gz: 09bdb689785592c1cc3ab4905360f31ee44750195559c8add875bf33b7e8ec091d0a34f46360ac1346ec274bbc5642b3ca2a536c39ddbf903568ac6cdd97468e
|
@@ -21,21 +21,20 @@ module RedditArchiver
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def posts(type)
|
24
|
+
def posts(type, reddit_id = nil)
|
25
25
|
# Reddit's API only allows a maximum of 100 comments at a time.
|
26
26
|
# To retrieve more than that (up to the hard limit of 1k), we
|
27
27
|
# have to get the 'name' attribute of the last comment and then
|
28
28
|
# request the next collection of comments that occur after it.
|
29
|
-
posts = retrieve_posts(type: type.to_s)
|
30
|
-
current_name = ""
|
31
29
|
|
32
|
-
|
33
|
-
previous_name = current_name
|
34
|
-
current_name = posts.last["name"]
|
35
|
-
posts += retrieve_posts(type: type.to_s, after: current_name)
|
36
|
-
end until previous_name == current_name
|
30
|
+
retrieved_posts = retrieve_posts(type: type.to_s, after: reddit_id)
|
37
31
|
|
38
|
-
|
32
|
+
if retrieved_posts.empty?
|
33
|
+
return retrieved_posts
|
34
|
+
else
|
35
|
+
last_id = retrieved_posts.last["name"]
|
36
|
+
retrieved_posts += posts(type, last_id)
|
37
|
+
end
|
39
38
|
end
|
40
39
|
|
41
40
|
def retrieve_posts(args = {})
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RedditArchiver
|
2
2
|
class Comment < Post
|
3
|
-
attr_reader :body, :score, :link_title, :link_id, :link_author
|
3
|
+
attr_reader :subreddit, :body, :score, :link_title, :link_id, :link_author
|
4
4
|
|
5
5
|
def initialize(comment)
|
6
6
|
@body = comment["body"]
|
@@ -16,7 +16,7 @@ module RedditArchiver
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def title
|
19
|
-
|
19
|
+
"#{submission_title}-#{reddit_id}"
|
20
20
|
end
|
21
21
|
|
22
22
|
def submission_title
|
data/spec/account_spec.rb
CHANGED
@@ -14,8 +14,11 @@ describe RedditArchiver::Account do
|
|
14
14
|
allow(Snoo::Client).to receive(:new).and_return(connection)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
18
|
-
expect(
|
19
|
-
|
17
|
+
it "can retreive comments" do
|
18
|
+
expect(account.comments.first).to have_class(RedditArchiver::Comment)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can retrieve submissions" do
|
22
|
+
expect(account.submissions.first).to have_class(RedditArchiver::Submission)
|
20
23
|
end
|
21
24
|
end
|
data/spec/comment_spec.rb
CHANGED
@@ -6,11 +6,11 @@ describe RedditArchiver::Comment do
|
|
6
6
|
subject { RedditArchiver::Comment.new(post) }
|
7
7
|
|
8
8
|
its(:year_month_date) { should eq("2013-09-19_00-29-37") }
|
9
|
-
its(:filename) { should eq('2013-09-19_00-29-
|
9
|
+
its(:filename) { should eq('2013-09-19_00-29-37_test-test-test-t1_cccccc') }
|
10
10
|
its(:body) { should eq('Hello.') }
|
11
11
|
its(:score) { should eq(3) }
|
12
12
|
its(:subdirectory) { should eq('comments') }
|
13
|
-
its(:title) { should eq('
|
13
|
+
its(:title) { should eq('test-test-test-t1_cccccc') }
|
14
14
|
|
15
15
|
context "The file" do
|
16
16
|
let(:comment) { RedditArchiver::Comment.new(post) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reddit_archiver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothy King
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|