Skip to content

Commit

Permalink
Add ability to approve, hide, and remove comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
james cook committed Sep 29, 2010
1 parent 802f904 commit a4b6917
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 13 deletions.
19 changes: 19 additions & 0 deletions features/comment.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Feature: Comments
I want to be able to comment on a comment
I want to be able to delete my comments

Scenario: Valid comment text
Given I enter some text
Then I should be able to add a comment

Scenario: I want to hide a comment
Given I have a comment
Then I should be able to hide the comment

Scenario: I want to remove a comment
Given I have a comment
Then I should be able to remove the comment

Scenario: I want to approve a comment
Given I have a comment
Then I should be able to approve the comment
36 changes: 36 additions & 0 deletions features/step_definitions/comment_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Before do
load_server_config
Reddit::Api.base_uri @address
Reddit::Submission.base_uri @address
Reddit::Comment.base_uri @address
@api = Reddit::Api.new @user, @pass
@api.login
@submission ||= @api.browse("reddit_test0")[0]
end

Given /^I enter some text$/ do
@text = "SOME COMMENT"
end

Then /^I should be able to add a comment$/ do
@submission.add_comment(@text).should be true
end

Given /^I have a comment$/ do
@submission.add_comment("a comment")
@comment = @submission.comments.last
end

Then /^I should be able to hide the comment$/ do
@comment.hide
end

Then /^I should be able to remove the comment$/ do
@comment.remove
end

Then /^I should be able to approve the comment$/ do
@comment.approve
end


7 changes: 4 additions & 3 deletions features/step_definitions/submission_steps.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
Before do
end

Given /^I have a submission$/ do
load_server_config
Reddit::Api.base_uri @address
Expand Down Expand Up @@ -58,3 +55,7 @@
comments = @submission.comments
comments.size.should > 0
end

Then /^I should be able to post a comment$/ do
@submission.add_comment("TEST COMMENT").should be true
end
20 changes: 18 additions & 2 deletions lib/reddit/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def to_s
body
end

def hide # soft delete?
resp=self.class.post("/api/del", {:body => {:id => id, :uh => modhash, :r => subreddit, :executed => "removed" }, :headers => base_headers, :debug_output => @debug })
resp.code == 200
end

def remove
resp=self.class.post("/api/remove", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug })
resp.code == 200
end

def approve
resp=self.class.post("/api/approve", {:body => {:id => id, :uh => modhash, :r => subreddit}, :headers => base_headers, :debug_output => @debug })
resp.code == 200
end

def upvote
Vote.new(self).up
end
Expand Down Expand Up @@ -49,8 +64,9 @@ def parse(json)
modhash = data["modhash"] # Needed for api calls
children = data["children"]
children.each do |child|
@kind = child["kind"] if @kind.nil?
data["kind"] = child["kind"]
kind = child["kind"]
data = child["data"]
data["kind"] = kind
comments << Reddit::Comment.new(data)
end
comments
Expand Down
10 changes: 2 additions & 8 deletions lib/reddit/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ def reload
#TODO
end

#thing_id:t6_2f
#text:THIS IS A COMMENT
#r:reddit_test0 # subreddit
#uh:reddit #modhash?
def add_comment(text)
self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug })
end

def delete_comment(id)
resp = self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug })
resp.code == 200
end

def upvote
Expand Down

0 comments on commit a4b6917

Please sign in to comment.