bterlson-reddit 0.1.0
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/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +29 -0
- data/README.txt +66 -0
- data/Rakefile +3 -0
- data/lib/reddit/article.rb +44 -0
- data/lib/reddit/comment.rb +33 -0
- data/lib/reddit/comment_list.rb +31 -0
- data/lib/reddit/reddit.rb +25 -0
- data/lib/reddit/resource_list.rb +27 -0
- data/lib/reddit/session.rb +41 -0
- data/lib/reddit/user.rb +25 -0
- data/lib/reddit/version.rb +9 -0
- data/lib/reddit.rb +14 -0
- data/spec/article_spec.rb +12 -0
- data/spec/comment_list_spec.rb +31 -0
- data/spec/comment_spec.rb +21 -0
- data/spec/reddit_spec.rb +30 -0
- data/spec/resource_list_spec.rb +29 -0
- data/spec/session_spec.rb +21 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/user_spec.rb +23 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- metadata +85 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Brian Terlson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
config/hoe.rb
|
8
|
+
config/requirements.rb
|
9
|
+
lib/reddit.rb
|
10
|
+
lib/reddit/article.rb
|
11
|
+
lib/reddit/comment.rb
|
12
|
+
lib/reddit/comment_list.rb
|
13
|
+
lib/reddit/reddit.rb
|
14
|
+
lib/reddit/resource_list.rb
|
15
|
+
lib/reddit/session.rb
|
16
|
+
lib/reddit/user.rb
|
17
|
+
lib/reddit/version.rb
|
18
|
+
script/console
|
19
|
+
script/destroy
|
20
|
+
script/generate
|
21
|
+
script/txt2html
|
22
|
+
setup.rb
|
23
|
+
spec/reddit_spec.rb
|
24
|
+
spec/spec.opts
|
25
|
+
spec/spec_helper.rb
|
26
|
+
tasks/deployment.rake
|
27
|
+
tasks/environment.rake
|
28
|
+
tasks/rspec.rake
|
29
|
+
tasks/website.rake
|
data/README.txt
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= reddit
|
2
|
+
|
3
|
+
* http://github.com/bterlson/reddit/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
An interface to the reddit API.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Retreive articles and their comments
|
12
|
+
* Retreive user pages
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'reddit'
|
18
|
+
|
19
|
+
reddit = Reddit::Session.new
|
20
|
+
|
21
|
+
reddit.main.articles.each do |article|
|
22
|
+
p article.url
|
23
|
+
|
24
|
+
article.comments.each do |comment|
|
25
|
+
p comment.body
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
p reddit.subreddit("programming").articles[1].author
|
30
|
+
|
31
|
+
reddit.user("radhruin").comments.each do |comment|
|
32
|
+
p comment.body
|
33
|
+
end
|
34
|
+
|
35
|
+
== REQUIREMENTS:
|
36
|
+
|
37
|
+
* JSON >= 1.1.2
|
38
|
+
|
39
|
+
== INSTALL:
|
40
|
+
|
41
|
+
* sudo gem install bterlson-reddit --source=http://gems.github.com
|
42
|
+
|
43
|
+
== LICENSE:
|
44
|
+
|
45
|
+
(The MIT License)
|
46
|
+
|
47
|
+
Copyright (c) 2008 FIX
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
'Software'), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
63
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
64
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Reddit
|
2
|
+
# A reddit article or submission.
|
3
|
+
class Article
|
4
|
+
attr_reader :score, :name, :title, :comment_count, :ups, :downs, :url, :domain, :author, :id, :created_at
|
5
|
+
|
6
|
+
# Initializes the data for the article. Takes a hash of the various attributes as taken from the API.
|
7
|
+
def initialize(attributes)
|
8
|
+
@score = attributes['score']
|
9
|
+
@name = attributes['name']
|
10
|
+
@title = attributes['title']
|
11
|
+
@comment_count = attributes['num_comments']
|
12
|
+
@ups = attributes['ups']
|
13
|
+
@downs = attributes['downs']
|
14
|
+
@url = attributes['url']
|
15
|
+
@domain = attributes['domain']
|
16
|
+
@author = User.new(attributes['author']) unless attributes['author'].nil?
|
17
|
+
@id = attributes['id']
|
18
|
+
@created_at = Time.at(attributes['created']) unless attributes['created'].nil?
|
19
|
+
@saved = attributes['saved']
|
20
|
+
@clicked = attributes['clicked']
|
21
|
+
@hidden = attributes['hidden']
|
22
|
+
end
|
23
|
+
|
24
|
+
# indicates if the current logged in user has saved the article.
|
25
|
+
def saved?
|
26
|
+
return @saved
|
27
|
+
end
|
28
|
+
|
29
|
+
# indicates if the current logged in user has clicked the article.
|
30
|
+
def clicked?
|
31
|
+
return @clicked
|
32
|
+
end
|
33
|
+
|
34
|
+
# indicates if the current logged in user has hidden the article.
|
35
|
+
def hidden?
|
36
|
+
return @hidden
|
37
|
+
end
|
38
|
+
|
39
|
+
# returns a CommentList of this article's comments.
|
40
|
+
def comments
|
41
|
+
return CommentList.new(@id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Reddit
|
2
|
+
|
3
|
+
# A reddit comment.
|
4
|
+
class Comment
|
5
|
+
attr_reader :body, :name, :ups, :downs, :url, :domain, :author, :id, :created_at, :replies
|
6
|
+
|
7
|
+
# Initializes the data for the comment. Takes a hash of the various attributes as taken from the API.
|
8
|
+
def initialize(attributes)
|
9
|
+
@score = attributes['score']
|
10
|
+
@name = attributes['name']
|
11
|
+
@ups = attributes['ups']
|
12
|
+
@downs = attributes['downs']
|
13
|
+
@author = User.new(attributes['author']) unless attributes['author'].nil?
|
14
|
+
@id = attributes['id']
|
15
|
+
@created_at = Time.at(attributes['created']) unless attributes['created'].nil?
|
16
|
+
@body = attributes['body']
|
17
|
+
@replies = []
|
18
|
+
|
19
|
+
unless attributes['replies'].nil?
|
20
|
+
attributes['replies']['data']['children'].each do |reply|
|
21
|
+
@replies << Comment.new(reply['data'])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the score for this comment.
|
28
|
+
def score
|
29
|
+
return @ups - @downs
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Reddit
|
2
|
+
|
3
|
+
# The list of comments found for an article.
|
4
|
+
class CommentList < ResourceList
|
5
|
+
|
6
|
+
# Initializes a comments list. Takes the ID of the article for which the comments belong to.
|
7
|
+
def initialize(article_id)
|
8
|
+
@article_id = article_id
|
9
|
+
@url = COMMENTS_URL.gsub('[id]', @article_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
# returns the top level comments for the thread.
|
13
|
+
def top_level
|
14
|
+
resources = get_resources(@url)
|
15
|
+
|
16
|
+
comments = []
|
17
|
+
resources.each do |comment|
|
18
|
+
comments << Comment.new(comment['data'])
|
19
|
+
end
|
20
|
+
|
21
|
+
return comments
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# forward any method calls to the top level comments array.
|
27
|
+
def method_missing(meth, *args, &block)
|
28
|
+
top_level.send(meth, *args, &block)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Reddit
|
2
|
+
|
3
|
+
# The main reddit or a subreddit.
|
4
|
+
class Reddit < ResourceList
|
5
|
+
|
6
|
+
# Initialize the reddit. If no name is specified, the reddit will be the main reddit.
|
7
|
+
def initialize(name = nil)
|
8
|
+
@name = name
|
9
|
+
@url = @name.nil? ? BASE_URL : SUBREDDIT_URL.gsub('[subreddit]', @name)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Returns the articles found in this reddit.
|
13
|
+
def articles
|
14
|
+
resources = get_resources(@url)
|
15
|
+
|
16
|
+
articles = []
|
17
|
+
|
18
|
+
resources.each do |article|
|
19
|
+
articles << Article.new(article['data'])
|
20
|
+
end
|
21
|
+
|
22
|
+
return articles
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Reddit
|
2
|
+
|
3
|
+
# A list of resources, such as a list of comments from an article or a user's page.
|
4
|
+
class ResourceList
|
5
|
+
attr_reader :url
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
# Grabs the resources at the URL and returns the parsed json.
|
10
|
+
def get_resources(url)
|
11
|
+
url = URI.parse(url)
|
12
|
+
|
13
|
+
res = Net::HTTP.start(url.host, url.port) {|http|
|
14
|
+
http.get(url.path + ".json")
|
15
|
+
}
|
16
|
+
|
17
|
+
raise SubredditNotFound if res.is_a?(Net::HTTPRedirection)
|
18
|
+
resources = JSON.parse(res.body, :max_nesting => 0)
|
19
|
+
|
20
|
+
# comments pages are contained in an array where the first element is the article
|
21
|
+
# and the second is the actual comments. This is hackish.
|
22
|
+
resources = resources.last if resources.is_a?(Array)
|
23
|
+
|
24
|
+
return resources['data']['children']
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Reddit
|
2
|
+
BASE_URL = "http://www.beta.reddit.com/"
|
3
|
+
PROFILE_URL = BASE_URL + "user/[username]/"
|
4
|
+
SUBREDDIT_URL = BASE_URL + "r/[subreddit]/"
|
5
|
+
COMMENTS_URL = BASE_URL + "info/[id]/comments/"
|
6
|
+
|
7
|
+
# raised when attempting to interact with a subreddit that doesn't exist.
|
8
|
+
class SubredditNotFound < StandardError; end
|
9
|
+
|
10
|
+
# raised when attempting to interact with a profile that doesn't exist.
|
11
|
+
class ProfileNotFound < StandardError; end
|
12
|
+
|
13
|
+
# raised when attempting to log in with incorrect credentials.
|
14
|
+
class AuthenticationException < StandardError; end
|
15
|
+
|
16
|
+
# A reddit browsing session.
|
17
|
+
class Session
|
18
|
+
|
19
|
+
# initialize the session with a username and password. Currently not used.
|
20
|
+
def initialize(username = "", password = "")
|
21
|
+
@username = username
|
22
|
+
@password = password
|
23
|
+
end
|
24
|
+
|
25
|
+
# return the main reddit.
|
26
|
+
def main
|
27
|
+
return Reddit.new()
|
28
|
+
end
|
29
|
+
|
30
|
+
# return a specific subreddit.
|
31
|
+
def subreddit(subreddit)
|
32
|
+
return Reddit.new(subreddit)
|
33
|
+
end
|
34
|
+
|
35
|
+
# return a specific user's page.
|
36
|
+
def user(username)
|
37
|
+
return User.new(username)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/reddit/user.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Reddit
|
2
|
+
|
3
|
+
# A user's page.
|
4
|
+
class User < ResourceList
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
# Initialize based on the user's name.
|
8
|
+
def initialize(name)
|
9
|
+
@name = name
|
10
|
+
@url = PROFILE_URL.gsub('[username]', @name)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Get the user's comments.
|
14
|
+
def comments
|
15
|
+
resources = get_resources(@url)
|
16
|
+
|
17
|
+
comments = []
|
18
|
+
resources.each do |comment|
|
19
|
+
comments << Comment.new(comment['data'])
|
20
|
+
end
|
21
|
+
|
22
|
+
return comments
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/reddit.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'json'
|
6
|
+
require 'net/http'
|
7
|
+
require 'reddit/resource_list'
|
8
|
+
require 'reddit/comment_list'
|
9
|
+
require 'reddit/comment'
|
10
|
+
require 'reddit/session'
|
11
|
+
require 'reddit/version'
|
12
|
+
require 'reddit/reddit'
|
13
|
+
require 'reddit/article'
|
14
|
+
require 'reddit/user'
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::Article do
|
4
|
+
before do
|
5
|
+
@article = Reddit::Article.new({"id" => "id"})
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be able to get the article's comments comments" do
|
9
|
+
Reddit::CommentList.should_receive(:new).with("id").and_return("reddit!")
|
10
|
+
@article.comments.should == "reddit!"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::CommentList do
|
4
|
+
before do
|
5
|
+
@comments_list = Reddit::CommentList.new('id')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should know its url" do
|
9
|
+
@comments_list.url.should == Reddit::COMMENTS_URL.gsub('[id]', 'id')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should fetch the top level comments" do
|
13
|
+
@comments_list.should_receive(:get_resources).and_return([
|
14
|
+
{:type => 't1', :data => {:attribute => 'value'}},
|
15
|
+
{:type => 't1', :data => {:attribute => 'value2'}}
|
16
|
+
])
|
17
|
+
|
18
|
+
mock_comment = mock(Reddit::Comment)
|
19
|
+
Reddit::Comment.should_receive(:new).twice.and_return(mock_comment)
|
20
|
+
|
21
|
+
@comments_list.top_level.should == [mock_comment, mock_comment]
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should redirect method calls to the top level comments" do
|
25
|
+
top_level_mock = mock('top_level')
|
26
|
+
top_level_mock.should_receive(:[]).and_return("array")
|
27
|
+
@comments_list.stub!(:top_level).and_return(top_level_mock)
|
28
|
+
|
29
|
+
@comments_list[1].should == "array"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::Comment do
|
4
|
+
before do
|
5
|
+
@comment = Reddit::Comment.new({
|
6
|
+
'ups' => 5,
|
7
|
+
'downs' => 6,
|
8
|
+
'replies' => {'data' => {'children' => [
|
9
|
+
{'data' => {'ups' => 1, 'downs' => 6}}
|
10
|
+
]}}
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have replies" do
|
15
|
+
@comment.replies.should_not be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should calculate its score" do
|
19
|
+
@comment.score.should == -1
|
20
|
+
end
|
21
|
+
end
|
data/spec/reddit_spec.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::Reddit do
|
4
|
+
before do
|
5
|
+
@reddit = Reddit::Reddit.new("programming")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should know its url" do
|
9
|
+
@reddit.url.should == Reddit::SUBREDDIT_URL.gsub('[subreddit]', 'programming')
|
10
|
+
end
|
11
|
+
|
12
|
+
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
|
+
])
|
17
|
+
|
18
|
+
mock_article = mock(Reddit::Article)
|
19
|
+
Reddit::Article.should_receive(:new).twice.and_return(mock_article)
|
20
|
+
|
21
|
+
@reddit.articles.should == [mock_article, mock_article]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe Reddit::Reddit, "With no subreddit specified" do
|
26
|
+
it "should use the main reddit" do
|
27
|
+
reddit = Reddit::Reddit.new()
|
28
|
+
reddit.url.should == Reddit::BASE_URL
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::ResourceList, ".get_resources" do
|
4
|
+
before do
|
5
|
+
@resource_list = Reddit::ResourceList.new
|
6
|
+
@http_mock = mock('http')
|
7
|
+
@http_mock.stub!(:get)
|
8
|
+
@response_mock = mock(Net::HTTPResponse)
|
9
|
+
@response_mock.stub!(:body).and_return('{"kind": "Listing", "data": {"children": [{"kind": "t3", "data": {"attribute": "value"}}]}}')
|
10
|
+
Net::HTTP.stub!(:start).and_yield(@http_mock).and_return(@response_mock)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should get the resources from Reddit" do
|
14
|
+
Net::HTTP.should_receive(:start).and_yield(@http_mock).and_return(@response_mock)
|
15
|
+
@resource_list.send(:get_resources, "http://reddit.com")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse the JSON" do
|
19
|
+
JSON.should_receive(:parse).and_return({'kind' => 'Listing', 'data' => {'children' => [{'data' => {'attribute' => 'value'}}]}})
|
20
|
+
@resource_list.send(:get_resources, "http://reddit.com")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should raise an error when the subreddit is not found" do
|
24
|
+
reddit = Reddit::Reddit.new("not found")
|
25
|
+
@response_mock.stub!(:is_a?).and_return(Net::HTTPRedirection)
|
26
|
+
|
27
|
+
proc {@resource_list.send(:get_resources, "http://reddit.com")}.should raise_error(Reddit::SubredditNotFound)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::Session, "without logging in" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@reddit = Reddit::Session.new()
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should grab the main page" do
|
10
|
+
@reddit.main.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should grab a user's profile page" do
|
14
|
+
@reddit.user("radhruin").should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should grab a subreddit" do
|
18
|
+
@reddit.subreddit("programming").should_not be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe Reddit::User do
|
4
|
+
before do
|
5
|
+
@user = Reddit::User.new('radhruin')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should know its url" do
|
9
|
+
@user.url.should == Reddit::PROFILE_URL.gsub('[username]', 'radhruin')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should fetch the user's comments" do
|
13
|
+
@user.should_receive(:get_resources).and_return([
|
14
|
+
{:type => 't1', :data => {:attribute => 'value'}},
|
15
|
+
{:type => 't1', :data => {:attribute => 'value2'}}
|
16
|
+
])
|
17
|
+
|
18
|
+
mock_comment = mock(Reddit::Comment)
|
19
|
+
Reddit::Comment.should_receive(:new).twice.and_return(mock_comment)
|
20
|
+
|
21
|
+
@user.comments.should == [mock_comment, mock_comment]
|
22
|
+
end
|
23
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
rescue LoadError
|
10
|
+
puts <<-EOS
|
11
|
+
To use rspec for testing you must install rspec gem:
|
12
|
+
gem install rspec
|
13
|
+
EOS
|
14
|
+
exit(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Run the specs under spec/models"
|
18
|
+
Spec::Rake::SpecTask.new do |t|
|
19
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bterlson-reddit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brian Terlson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.2
|
23
|
+
version:
|
24
|
+
description:
|
25
|
+
email: btthalion@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- README.txt
|
32
|
+
files:
|
33
|
+
- History.txt
|
34
|
+
- lib/reddit.rb
|
35
|
+
- lib/reddit/article.rb
|
36
|
+
- lib/reddit/comment.rb
|
37
|
+
- lib/reddit/comment_list.rb
|
38
|
+
- lib/reddit/reddit.rb
|
39
|
+
- lib/reddit/resource_list.rb
|
40
|
+
- lib/reddit/session.rb
|
41
|
+
- lib/reddit/user.rb
|
42
|
+
- lib/reddit/version.rb
|
43
|
+
- License.txt
|
44
|
+
- Manifest.txt
|
45
|
+
- Rakefile
|
46
|
+
- README.txt
|
47
|
+
- spec/article_spec.rb
|
48
|
+
- spec/comment_list_spec.rb
|
49
|
+
- spec/comment_spec.rb
|
50
|
+
- spec/reddit_spec.rb
|
51
|
+
- spec/resource_list_spec.rb
|
52
|
+
- spec/session_spec.rb
|
53
|
+
- spec/spec.opts
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
- spec/user_spec.rb
|
56
|
+
- tasks/environment.rake
|
57
|
+
- tasks/rspec.rake
|
58
|
+
has_rdoc: true
|
59
|
+
homepage: http://github.com/bterlson/reddit/
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.0.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 2
|
83
|
+
summary: Interface with the Reddit.com API.
|
84
|
+
test_files: []
|
85
|
+
|