bterlson-reddit 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.2.1 2008-06-19
2
+
3
+ * 1 tiny modification:
4
+ * Can retreive various reddit/subreddit pages (hot, new, controversial, top).
5
+
6
+ == 0.2.0 2008-06-09
7
+
8
+ * 1 minor modification:
9
+ * Changed the beta URL of reddit to the new URL of reddit
10
+
1
11
  == 0.1.0 2008-05-22
2
12
 
3
13
  * 1 major enhancement:
data/lib/reddit/reddit.rb CHANGED
@@ -9,9 +9,25 @@ module Reddit
9
9
  @url = @name.nil? ? BASE_URL : SUBREDDIT_URL.gsub('[subreddit]', @name)
10
10
  end
11
11
 
12
+ def hot
13
+ articles 'hot'
14
+ end
15
+
16
+ def top
17
+ articles 'top'
18
+ end
19
+
20
+ def new
21
+ articles 'new'
22
+ end
23
+
24
+ def controversial
25
+ articles 'controversial'
26
+ end
27
+
12
28
  # Returns the articles found in this reddit.
13
- def articles
14
- resources = get_resources(@url)
29
+ def articles(page = 'hot')
30
+ resources = get_resources("#{@url}#{page}/")
15
31
 
16
32
  articles = []
17
33
 
@@ -8,6 +8,7 @@ module Reddit
8
8
 
9
9
  # Grabs the resources at the URL and returns the parsed json.
10
10
  def get_resources(url)
11
+ puts "Getting URL: #{url}"
11
12
  url = URI.parse(url)
12
13
 
13
14
  res = Net::HTTP.start(url.host, url.port) {|http|
@@ -1,8 +1,8 @@
1
1
  module Reddit #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 0
4
+ MINOR = 2
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/spec/reddit_spec.rb CHANGED
@@ -5,21 +5,58 @@ describe Reddit::Reddit do
5
5
  @reddit = Reddit::Reddit.new("programming")
6
6
  end
7
7
 
8
+ def test_articles
9
+ [
10
+ {:type => 't1', :data => {:attribute => 'value'}},
11
+ {:type => 't1', :data => {:attribute => 'value2'}}
12
+ ]
13
+ end
14
+
8
15
  it "should know its url" do
9
16
  @reddit.url.should == Reddit::SUBREDDIT_URL.gsub('[subreddit]', 'programming')
10
17
  end
11
18
 
12
19
  it "should find the articles" do
13
- @reddit.should_receive(:get_resources).and_return([
14
- {:type => 't1', :data => {:attribute => 'value'}},
15
- {:type => 't1', :data => {:attribute => 'value2'}}
16
- ])
20
+ @reddit.should_receive(:get_resources).and_return(test_articles)
17
21
 
18
22
  mock_article = mock(Reddit::Article)
19
23
  Reddit::Article.should_receive(:new).twice.and_return(mock_article)
20
24
 
21
25
  @reddit.articles.should == [mock_article, mock_article]
22
26
  end
27
+
28
+ it "should find top articles" do
29
+ mock_article = mock(Reddit::Article)
30
+
31
+ @reddit.should_receive(:articles).with('top').and_return([mock_article, mock_article])
32
+
33
+ @reddit.top.should == [mock_article, mock_article]
34
+ end
35
+
36
+ it "should find new articles" do
37
+ mock_article = mock(Reddit::Article)
38
+
39
+ @reddit.should_receive(:articles).with('new').and_return([mock_article, mock_article])
40
+
41
+ @reddit.new.should == [mock_article, mock_article]
42
+ end
43
+
44
+ it "should find controversial articles" do
45
+ mock_article = mock(Reddit::Article)
46
+
47
+ @reddit.should_receive(:articles).with('controversial').and_return([mock_article, mock_article])
48
+
49
+ @reddit.controversial.should == [mock_article, mock_article]
50
+ end
51
+
52
+ it "should find hot articles" do
53
+ mock_article = mock(Reddit::Article)
54
+
55
+ @reddit.should_receive(:articles).with('hot').and_return([mock_article, mock_article])
56
+
57
+ @reddit.hot.should == [mock_article, mock_article]
58
+ end
59
+
23
60
  end
24
61
 
25
62
  describe Reddit::Reddit, "With no subreddit specified" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bterlson-reddit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Terlson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-05 00:00:00 -07:00
12
+ date: 2008-06-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency