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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a075b973c4926b6dde15536b3b2fa4a4cd20bc
4
- data.tar.gz: 075052f1d7a6e61659bd80ce5cbf52f9900d720f
3
+ metadata.gz: 49db034fca6fc3ed9d26f4bbc5b24b4dad9667f0
4
+ data.tar.gz: 5e1dfe3b5a7784e75bae375e613ce7bcaf67f8a9
5
5
  SHA512:
6
- metadata.gz: 31aaab845087793e3febfc3f23f214701fd4648d9873c23a961ac26e0cb7a2489bbd03eef927833ed1104e595c0ada4ba23d5d985f924ec7a685295f66e023a6
7
- data.tar.gz: 6060034dfb3282c53472e1174c2038a704c5debf5fbcac7a9a95d5067cd182050846a2bdb2b41014a3f651af4f32d5b3faddb310beb2d1748b76a296fcb8420e
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
- begin
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
- posts
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
- body[0..96]
19
+ "#{submission_title}-#{reddit_id}"
20
20
  end
21
21
 
22
22
  def submission_title
@@ -6,7 +6,7 @@ module RedditArchiver
6
6
  end
7
7
 
8
8
  def subdirectories
9
- self.submission_title ? File.join(subdirectory, self.submission_title) : subdirectory
9
+ self.subreddit ? File.join(subdirectory, self.subreddit) : subdirectory
10
10
  end
11
11
 
12
12
  def filename
@@ -1,3 +1,3 @@
1
1
  module RedditArchiver
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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 "retreives the posts three times" do
18
- expect(connection).to receive(:get_user_listing).exactly(3).times
19
- account.comments
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
@@ -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-37_hello') }
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('Hello.') }
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.1
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-23 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler