ruby_reddit_api 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- == Ruby Reddit Client v0.2.5
1
+ == Ruby Reddit Client v0.2.6
2
2
  Tested with ruby 1.8.7 & 1.9.2
3
3
 
4
4
  == Usage
@@ -0,0 +1,14 @@
1
+ Feature: Message Group
2
+ I want to be able to mark multiple messages as read or unread
3
+
4
+ Scenario: Mark multiple messages read
5
+ Given I am logged in
6
+ And I have unread messages
7
+ When I mark all unread messages read
8
+ Then I should have no unread messages
9
+
10
+ Scenario: Mark multiple messages unread
11
+ Given I am logged in
12
+ And I have unread messages
13
+ When I mark all read messages unread
14
+ Then I should have no read messages
@@ -0,0 +1,30 @@
1
+ Before do
2
+ load_server_config
3
+ Reddit::Api.base_uri @address
4
+ Reddit::MessageGroup.base_uri @address
5
+ Reddit::Base.instance_variable_set("@throttle_duration", 0)
6
+ @api = Reddit::Api.new @user, @pass
7
+ @api.login
8
+ end
9
+
10
+ When /^I mark all unread messages read$/ do
11
+ group = Reddit::MessageGroup.new
12
+ messages = @api.unread_messages
13
+ result = group.mark_read messages
14
+ result.should be true
15
+ end
16
+
17
+ When /^I mark all read messages unread$/ do
18
+ group = Reddit::MessageGroup.new
19
+ messages = @api.received_messages
20
+ result = group.mark_unread messages
21
+ result.should be true
22
+ end
23
+
24
+ Then /^I should have no unread messages$/ do
25
+ @api.unread_messages.should == []
26
+ end
27
+
28
+ Then /^I should have no read messages$/ do
29
+ @api.received_messages.select{|m| !m.was_comment}.map(&:read?).uniq.should == [false]
30
+ end
@@ -16,4 +16,5 @@ require "ruby_reddit_api/vote"
16
16
  require "ruby_reddit_api/submission"
17
17
  require "ruby_reddit_api/comment"
18
18
  require "ruby_reddit_api/message"
19
+ require "ruby_reddit_api/message_group"
19
20
 
@@ -15,6 +15,14 @@ module Reddit
15
15
  "#{kind}_#{@id}"
16
16
  end
17
17
 
18
+ def unread?
19
+ @new == true
20
+ end
21
+
22
+ def read?
23
+ @new == false
24
+ end
25
+
18
26
  # The author of the message. The data is lazy-loaded and cached on the message
19
27
  # @return [Reddit::User]
20
28
  def author
@@ -0,0 +1,39 @@
1
+ # @author James Cook
2
+ module Reddit
3
+ class MessageGroup < Thing
4
+ include JsonListing
5
+ attr_reader :debug
6
+
7
+ def initialize
8
+ @debug = StringIO.new
9
+ end
10
+
11
+ def mark_read(messages)
12
+ mark messages, "read"
13
+ end
14
+
15
+ def mark_unread(messages)
16
+ mark messages, "unread"
17
+ end
18
+
19
+ protected
20
+ def mark(messages, action)
21
+ ids = ids(messages)
22
+ action = action == "read" ? "read_message" : "unread_message"
23
+ resp = self.class.post("/api/#{action}", {:body => {:id => ids.join(','), :uh => modhash }, :headers => base_headers, :debug_output => @debug })
24
+ resp.code == 200
25
+ end
26
+
27
+ def ids(messages)
28
+ if messages.is_a?(Array)
29
+ if messages.first.is_a?(Reddit::Message)
30
+ return messages.map{|m| m.id }
31
+ else
32
+ return messages # assume array of String
33
+ end
34
+ else
35
+ return [ messages.id ]
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_reddit_api
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 5
9
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - James Cook
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-11-19 00:00:00 -06:00
18
+ date: 2010-11-21 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -38,6 +40,7 @@ dependencies:
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
43
+ hash: 3
41
44
  segments:
42
45
  - 0
43
46
  version: "0"
@@ -51,6 +54,7 @@ dependencies:
51
54
  requirements:
52
55
  - - ">="
53
56
  - !ruby/object:Gem::Version
57
+ hash: 3
54
58
  segments:
55
59
  - 0
56
60
  version: "0"
@@ -66,35 +70,38 @@ extensions: []
66
70
  extra_rdoc_files: []
67
71
 
68
72
  files:
69
- - lib/ruby_reddit_api/json_listing.rb
70
- - lib/ruby_reddit_api/comment.rb
73
+ - lib/ruby_reddit_api.rb
71
74
  - lib/ruby_reddit_api/voteable.rb
72
- - lib/ruby_reddit_api/api.rb
73
- - lib/ruby_reddit_api/vote.rb
74
- - lib/ruby_reddit_api/submission.rb
75
- - lib/ruby_reddit_api/version.rb
75
+ - lib/ruby_reddit_api/thing.rb
76
76
  - lib/ruby_reddit_api/user.rb
77
+ - lib/ruby_reddit_api/comment.rb
77
78
  - lib/ruby_reddit_api/message.rb
78
- - lib/ruby_reddit_api/thing.rb
79
+ - lib/ruby_reddit_api/version.rb
80
+ - lib/ruby_reddit_api/message_group.rb
81
+ - lib/ruby_reddit_api/vote.rb
82
+ - lib/ruby_reddit_api/submission.rb
83
+ - lib/ruby_reddit_api/api.rb
84
+ - lib/ruby_reddit_api/json_listing.rb
79
85
  - lib/ruby_reddit_api/base.rb
80
- - lib/ruby_reddit_api.rb
81
86
  - README.rdoc
82
87
  - features/reddit.yml
83
- - features/search.feature
84
- - features/api.feature
85
88
  - features/submission.feature
86
- - features/base.feature
87
89
  - features/comment.feature
88
- - features/step_definitions/user_steps.rb
90
+ - features/user.feature
91
+ - features/base.feature
92
+ - features/message.feature
93
+ - features/message_group.feature
94
+ - features/search.feature
95
+ - features/api.feature
96
+ - features/step_definitions/message_steps.rb
97
+ - features/step_definitions/submission_steps.rb
89
98
  - features/step_definitions/search_steps.rb
99
+ - features/step_definitions/message_group_steps.rb
90
100
  - features/step_definitions/api_steps.rb
91
- - features/step_definitions/submission_steps.rb
101
+ - features/step_definitions/user_steps.rb
92
102
  - features/step_definitions/comment_steps.rb
93
- - features/step_definitions/message_steps.rb
94
103
  - features/step_definitions/base_steps.rb
95
- - features/message.feature
96
104
  - features/support/base_helpers.rb
97
- - features/user.feature
98
105
  has_rdoc: yard
99
106
  homepage: http://github.com/jamescook/RubyRedditAPI
100
107
  licenses: []
@@ -109,6 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
116
  requirements:
110
117
  - - ">="
111
118
  - !ruby/object:Gem::Version
119
+ hash: 57
112
120
  segments:
113
121
  - 1
114
122
  - 8
@@ -119,6 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
127
  requirements:
120
128
  - - ">="
121
129
  - !ruby/object:Gem::Version
130
+ hash: 23
122
131
  segments:
123
132
  - 1
124
133
  - 3
@@ -133,18 +142,20 @@ specification_version: 3
133
142
  summary: Wrapper for reddit API
134
143
  test_files:
135
144
  - features/reddit.yml
136
- - features/search.feature
137
- - features/api.feature
138
145
  - features/submission.feature
139
- - features/base.feature
140
146
  - features/comment.feature
141
- - features/step_definitions/user_steps.rb
147
+ - features/user.feature
148
+ - features/base.feature
149
+ - features/message.feature
150
+ - features/message_group.feature
151
+ - features/search.feature
152
+ - features/api.feature
153
+ - features/step_definitions/message_steps.rb
154
+ - features/step_definitions/submission_steps.rb
142
155
  - features/step_definitions/search_steps.rb
156
+ - features/step_definitions/message_group_steps.rb
143
157
  - features/step_definitions/api_steps.rb
144
- - features/step_definitions/submission_steps.rb
158
+ - features/step_definitions/user_steps.rb
145
159
  - features/step_definitions/comment_steps.rb
146
- - features/step_definitions/message_steps.rb
147
160
  - features/step_definitions/base_steps.rb
148
- - features/message.feature
149
161
  - features/support/base_helpers.rb
150
- - features/user.feature