This repository has been archived by the owner on Oct 29, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class to mark multiple messages read/unread
- Loading branch information
james cook
committed
Nov 21, 2010
1 parent
0eef96f
commit d28f18f
Showing
7 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
== Ruby Reddit Client v0.2.5 | ||
== Ruby Reddit Client v0.2.6 | ||
Tested with ruby 1.8.7 & 1.9.2 | ||
|
||
== Usage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.5 | ||
0.2.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: Message Group | ||
I want to be able to mark multiple messages as read or unread | ||
|
||
Scenario: Mark multiple messages read | ||
Given I am logged in | ||
And I have unread messages | ||
When I mark all unread messages read | ||
Then I should have no unread messages | ||
|
||
Scenario: Mark multiple messages unread | ||
Given I am logged in | ||
And I have unread messages | ||
When I mark all read messages unread | ||
Then I should have no read messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Before do | ||
load_server_config | ||
Reddit::Api.base_uri @address | ||
Reddit::MessageGroup.base_uri @address | ||
Reddit::Base.instance_variable_set("@throttle_duration", 0) | ||
@api = Reddit::Api.new @user, @pass | ||
@api.login | ||
end | ||
|
||
When /^I mark all unread messages read$/ do | ||
group = Reddit::MessageGroup.new | ||
messages = @api.unread_messages | ||
result = group.mark_read messages | ||
result.should be true | ||
end | ||
|
||
When /^I mark all read messages unread$/ do | ||
group = Reddit::MessageGroup.new | ||
messages = @api.received_messages | ||
result = group.mark_unread messages | ||
result.should be true | ||
end | ||
|
||
Then /^I should have no unread messages$/ do | ||
@api.unread_messages.should == [] | ||
end | ||
|
||
Then /^I should have no read messages$/ do | ||
@api.received_messages.select{|m| !m.was_comment}.map(&:read?).uniq.should == [false] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# @author James Cook | ||
module Reddit | ||
class MessageGroup < Thing | ||
include JsonListing | ||
attr_reader :debug | ||
|
||
def initialize | ||
@debug = StringIO.new | ||
end | ||
|
||
def mark_read(messages) | ||
mark messages, "read" | ||
end | ||
|
||
def mark_unread(messages) | ||
mark messages, "unread" | ||
end | ||
|
||
protected | ||
def mark(messages, action) | ||
ids = ids(messages) | ||
action = action == "read" ? "read_message" : "unread_message" | ||
resp = self.class.post("/api/#{action}", {:body => {:id => ids.join(','), :uh => modhash }, :headers => base_headers, :debug_output => @debug }) | ||
resp.code == 200 | ||
end | ||
|
||
def ids(messages) | ||
if messages.is_a?(Array) | ||
if messages.first.is_a?(Reddit::Message) | ||
return messages.map{|m| m.id } | ||
else | ||
return messages # assume array of String | ||
end | ||
else | ||
return [ messages.id ] | ||
end | ||
end | ||
end | ||
end |