ruby_reddit_api 0.2.4 → 0.2.5

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.
@@ -1,4 +1,4 @@
1
- == Ruby Reddit Client v0.2.3
1
+ == Ruby Reddit Client v0.2.5
2
2
  Tested with ruby 1.8.7 & 1.9.2
3
3
 
4
4
  == Usage
@@ -1,5 +1,19 @@
1
1
  Feature: Messaging
2
+
2
3
  Scenario: I want to be able to read my sent messages
3
4
  Given I am logged in
4
5
  When I go to the sent messages page
5
6
  Then I should see a listing of messages
7
+
8
+ Scenario: I want to change message read status
9
+ Given I am logged in
10
+ And I have received messages
11
+ When I go to the received messages page
12
+ Then I should be able to mark them as unread
13
+ And I should be able to mark them as read
14
+
15
+ Scenario: I want to be able to read my unread messages
16
+ Given I am logged in
17
+ And I have unread messages
18
+ When I go to the unread messages page
19
+ Then I should see a listing of messages
@@ -2,6 +2,7 @@ Before do
2
2
  load_server_config
3
3
  Reddit::Api.base_uri @address
4
4
  Reddit::Message.base_uri @address
5
+ Reddit::Base.instance_variable_set("@throttle_duration", 0)
5
6
  end
6
7
 
7
8
  Given /^I am logged in$/ do
@@ -13,6 +14,55 @@ When /^I go to the sent messages page$/ do
13
14
  @result = @api.sent_messages
14
15
  end
15
16
 
17
+ When /^I go to the unread messages page$/ do
18
+ @result = @api.unread_messages
19
+ end
20
+
21
+ When /^I go to the received messages page$/ do
22
+ @result = @api.received_messages
23
+ end
24
+
16
25
  Then /^I should see a listing of messages$/ do
17
26
  @result.any?{|r| r.is_a?(Reddit::Message) == false}.should be false
18
27
  end
28
+
29
+ Given /^I have received messages$/ do
30
+ @api.received_messages.size.should be > 0
31
+ end
32
+
33
+ Given /^I have unread messages$/ do
34
+ unread = @api.unread_messages
35
+ unless unread.size > 0
36
+ @api.received_messages[0].mark_unread
37
+ end
38
+ end
39
+
40
+ Then /^I should be able to mark them as unread/ do
41
+ unread = @api.unread_messages
42
+ unread.each do |m|
43
+ m.mark_read
44
+ end
45
+
46
+ received = @api.received_messages
47
+ received[0].mark_unread
48
+
49
+ r = @api.unread_messages
50
+ r.size.should == 1
51
+ end
52
+
53
+ Then /^I should be able to mark them as read$/ do
54
+ received = @api.received_messages
55
+ received.each do |m|
56
+ m.mark_unread
57
+ end
58
+ unread = @api.unread_messages
59
+
60
+ unread.size.should be > 0
61
+
62
+ unread.each do |m|
63
+ m.mark_read
64
+ end
65
+
66
+ r = @api.unread_messages
67
+ r.size.should == 0
68
+ end
@@ -1,5 +1,4 @@
1
1
  Given /^I search '([^']+)' with '([^']+)'$/ do |subreddit, terms|
2
- # FIXME searching isnt working for me by default in the reddit vm
3
2
  Reddit::Base.base_uri "reddit.com"
4
3
  Reddit::Api.base_uri "reddit.com"
5
4
  @api = Reddit::Api.new
@@ -9,6 +9,7 @@ require "ruby_reddit_api/version"
9
9
  require "ruby_reddit_api/json_listing"
10
10
  require "ruby_reddit_api/base"
11
11
  require "ruby_reddit_api/thing"
12
+ require "ruby_reddit_api/voteable"
12
13
  require "ruby_reddit_api/api"
13
14
  require "ruby_reddit_api/user"
14
15
  require "ruby_reddit_api/vote"
@@ -61,6 +61,12 @@ module Reddit
61
61
  messages :inbox
62
62
  end
63
63
 
64
+ #Read unread messages
65
+ # @return [Array<Reddit::Message>]
66
+ def unread_messages
67
+ messages :unread
68
+ end
69
+
64
70
  # Read received comments
65
71
  # @return [Array<Reddit::Message>]
66
72
  def comments
@@ -7,7 +7,9 @@ module Reddit
7
7
 
8
8
  attr_reader :last_action, :debug
9
9
  base_uri "www.reddit.com"
10
- class << self; attr_reader :cookie, :modhash, :user_id, :user end
10
+ class << self; attr_reader :cookie, :modhash, :user_id, :user, :throttle_duration end
11
+
12
+ @throttle_duration = 1.0
11
13
 
12
14
  def initialize(options={})
13
15
  @debug = StringIO.new
@@ -108,7 +110,7 @@ module Reddit
108
110
  end
109
111
 
110
112
  def throttled?
111
- @last_action && ( ( Time.now - @last_action ) < 1.0 )
113
+ @last_action && ( ( Time.now - @last_action ) < Reddit::Base.throttle_duration )
112
114
  end
113
115
 
114
116
  def sanitize_subreddit(subreddit)
@@ -1,8 +1,9 @@
1
1
  module Reddit
2
2
  # @author James Cook
3
3
  class Comment < Thing
4
-
4
+ include Voteable
5
5
  include JsonListing
6
+
6
7
  attr_reader :body, :subreddit_id, :name, :created, :downs, :author, :created_utc, :body_html, :link_id, :parent_id, :likes, :num_comments, :subreddit, :ups, :debug, :kind, :replies
7
8
  def initialize(json, options={})
8
9
  mode = options.fetch(:mode){ :json }
@@ -1,6 +1,6 @@
1
1
  # @author James Cook
2
2
  module Reddit
3
- class Message < Base
3
+ class Message < Thing
4
4
  include JsonListing
5
5
 
6
6
  attr_reader :body, :was_comment, :kind, :first_message, :name, :created, :dest, :created_utc, :body_html, :subreddit, :parent_id, :context, :replies, :subject, :debug
@@ -21,6 +21,23 @@ module Reddit
21
21
  @author_data ||= read("/user/#{@author}/about.json", :handler => "User")
22
22
  end
23
23
 
24
+ # Reply to this message
25
+ # @return [true,false]
26
+ def reply(text)
27
+ resp = self.class.post("/api/comment", {:body => {:thing_id => id, :text => text, :uh => modhash, :r => subreddit }, :headers => base_headers, :debug_output => @debug })
28
+ resp.code == 200
29
+ end
30
+
31
+ def mark_unread
32
+ resp = self.class.post("/api/unread_message", {:body => {:id => id, :uh => modhash}, :headers => base_headers, :debug_output => @debug })
33
+ resp.code == 200
34
+ end
35
+
36
+ def mark_read
37
+ resp = self.class.post("/api/read_message", {:body => {:id => id, :uh => modhash }, :headers => base_headers, :debug_output => @debug })
38
+ resp.code == 200
39
+ end
40
+
24
41
  def inspect
25
42
  "<Reddit::Message '#{short_body}'>"
26
43
  end
@@ -2,6 +2,8 @@
2
2
  module Reddit
3
3
  class Submission < Thing
4
4
  include JsonListing
5
+ include Voteable
6
+
5
7
  attr_reader :domain, :media_embed, :subreddit, :selftext_html, :selftext, :likes, :saved, :clicked, :media, :score, :over_18, :hidden, :thumbnail, :subreddit_id, :downs, :is_self, :permalink, :name, :created, :url, :title, :created_utc, :num_comments, :ups, :kind, :last_comment_id
6
8
 
7
9
  def inspect
@@ -21,18 +21,6 @@ module Reddit
21
21
  @author_data ||= response[0] if response
22
22
  end
23
23
 
24
- # Upvote thing
25
- # @return [true,false]
26
- def upvote
27
- Reddit::Vote.new(self).up
28
- end
29
-
30
- # Downvote thing
31
- # @return [true,false]
32
- def downvote
33
- Reddit::Vote.new(self).down
34
- end
35
-
36
24
  # Report thing
37
25
  # @return [true,false]
38
26
  def report
@@ -0,0 +1,22 @@
1
+ module Reddit
2
+ # @author Joe Bauser
3
+ module Voteable
4
+ def self.included(base)
5
+ base.send(:include, InstanceMethods)
6
+ end
7
+
8
+ module InstanceMethods
9
+ # Upvote thing
10
+ # @return [true,false]
11
+ def upvote
12
+ Reddit::Vote.new(self).up
13
+ end
14
+
15
+ # Downvote thing
16
+ # @return [true,false]
17
+ def downvote
18
+ Reddit::Vote.new(self).down
19
+ end
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 4
9
- version: 0.2.4
8
+ - 5
9
+ version: 0.2.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Cook
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-26 00:00:00 -04:00
17
+ date: 2010-11-19 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,34 +66,35 @@ extensions: []
66
66
  extra_rdoc_files: []
67
67
 
68
68
  files:
69
- - lib/ruby_reddit_api.rb
70
- - lib/ruby_reddit_api/thing.rb
71
- - lib/ruby_reddit_api/user.rb
69
+ - lib/ruby_reddit_api/json_listing.rb
72
70
  - lib/ruby_reddit_api/comment.rb
73
- - lib/ruby_reddit_api/message.rb
74
- - lib/ruby_reddit_api/version.rb
71
+ - lib/ruby_reddit_api/voteable.rb
72
+ - lib/ruby_reddit_api/api.rb
75
73
  - lib/ruby_reddit_api/vote.rb
76
74
  - lib/ruby_reddit_api/submission.rb
77
- - lib/ruby_reddit_api/api.rb
78
- - lib/ruby_reddit_api/json_listing.rb
75
+ - lib/ruby_reddit_api/version.rb
76
+ - lib/ruby_reddit_api/user.rb
77
+ - lib/ruby_reddit_api/message.rb
78
+ - lib/ruby_reddit_api/thing.rb
79
79
  - lib/ruby_reddit_api/base.rb
80
+ - lib/ruby_reddit_api.rb
80
81
  - README.rdoc
81
82
  - features/reddit.yml
82
- - features/submission.feature
83
- - features/comment.feature
84
- - features/user.feature
85
- - features/base.feature
86
- - features/message.feature
87
83
  - features/search.feature
88
84
  - features/api.feature
89
- - features/step_definitions/message_steps.rb
90
- - features/step_definitions/submission_steps.rb
85
+ - features/submission.feature
86
+ - features/base.feature
87
+ - features/comment.feature
88
+ - features/step_definitions/user_steps.rb
91
89
  - features/step_definitions/search_steps.rb
92
90
  - features/step_definitions/api_steps.rb
93
- - features/step_definitions/user_steps.rb
91
+ - features/step_definitions/submission_steps.rb
94
92
  - features/step_definitions/comment_steps.rb
93
+ - features/step_definitions/message_steps.rb
95
94
  - features/step_definitions/base_steps.rb
95
+ - features/message.feature
96
96
  - features/support/base_helpers.rb
97
+ - features/user.feature
97
98
  has_rdoc: yard
98
99
  homepage: http://github.com/jamescook/RubyRedditAPI
99
100
  licenses: []
@@ -132,18 +133,18 @@ specification_version: 3
132
133
  summary: Wrapper for reddit API
133
134
  test_files:
134
135
  - features/reddit.yml
135
- - features/submission.feature
136
- - features/comment.feature
137
- - features/user.feature
138
- - features/base.feature
139
- - features/message.feature
140
136
  - features/search.feature
141
137
  - features/api.feature
142
- - features/step_definitions/message_steps.rb
143
- - features/step_definitions/submission_steps.rb
138
+ - features/submission.feature
139
+ - features/base.feature
140
+ - features/comment.feature
141
+ - features/step_definitions/user_steps.rb
144
142
  - features/step_definitions/search_steps.rb
145
143
  - features/step_definitions/api_steps.rb
146
- - features/step_definitions/user_steps.rb
144
+ - features/step_definitions/submission_steps.rb
147
145
  - features/step_definitions/comment_steps.rb
146
+ - features/step_definitions/message_steps.rb
148
147
  - features/step_definitions/base_steps.rb
148
+ - features/message.feature
149
149
  - features/support/base_helpers.rb
150
+ - features/user.feature