activity_feed 2.1.0 → 2.2.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/CHANGELOG.markdown CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.2.0 (2012-08-20)
4
+
5
+ * Added `expire_feed(user_id, seconds, aggregate = ActivityFeed.aggregate)` and `expire_feed_at(user_id, timestamp, aggregate = ActivityFeed.aggregate)` methods to expire an activity feed after a given number of seconds or at a given time stamp, respectively.
6
+
3
7
  ## 2.1.0 (2012-08-13)
4
8
 
5
9
  * Added `full_feed(user_id, aggregate = ActivityFeed.aggregate)` method to be able to retrieve an entire activity feed
data/README.markdown CHANGED
@@ -293,6 +293,8 @@ ActivityFeed.feed_between_timestamps(user_id, starting_timestamp, ending_timesta
293
293
  ActivityFeed.total_pages_in_feed(user_id, aggregate = ActivityFeed.aggregate, page_size = ActivityFeed.page_size)
294
294
  ActivityFeed.total_items_in_feed(user_id, aggregate = ActivityFeed.aggregate)
295
295
  ActivityFeed.trim_feed(user_id, starting_timestamp, ending_timestamp, aggregate = ActivityFeed.aggregate)
296
+ ActivityFeed.expire_feed(user_id, seconds, aggregate = ActivityFeed.aggregate)
297
+ ActivityFeed.expire_feed_at(user_id, timestamp, aggregate = ActivityFeed.aggregate)
296
298
  ActivityFeed.remove_feeds(user_id)
297
299
  ```
298
300
 
@@ -119,5 +119,23 @@ module ActivityFeed
119
119
  def trim_feed(user_id, starting_timestamp, ending_timestamp, aggregate = ActivityFeed.aggregate)
120
120
  ActivityFeed.feederboard_for(user_id, aggregate).remove_members_in_score_range(starting_timestamp, ending_timestamp)
121
121
  end
122
+
123
+ # Expire an activity feed after a set number of seconds.
124
+ #
125
+ # @param user_id [String] User ID.
126
+ # @param seconds [int] Number of seconds after which the activity feed will be expired.
127
+ # @param aggregate [boolean, false] Whether or not to expire the aggregate activity feed or not.
128
+ def expire_feed(user_id, seconds, aggregate = ActivityFeed.aggregate)
129
+ ActivityFeed.redis.expire(ActivityFeed.feed_key(user_id, aggregate), seconds)
130
+ end
131
+
132
+ # Expire an activity feed at a given timestamp.
133
+ #
134
+ # @param user_id [String] User ID.
135
+ # @param timestamp [int] Timestamp after which the activity feed will be expired.
136
+ # @param aggregate [boolean, false] Whether or not to expire the aggregate activity feed or not.
137
+ def expire_feed_at(user_id, timestamp, aggregate = ActivityFeed.aggregate)
138
+ ActivityFeed.redis.expireat(ActivityFeed.feed_key(user_id, aggregate), timestamp)
139
+ end
122
140
  end
123
141
  end
@@ -1,3 +1,3 @@
1
1
  module ActivityFeed
2
- VERSION = "2.1.0"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -242,52 +242,28 @@ describe ActivityFeed::Feed do
242
242
  feed[0].should == item
243
243
  end
244
244
  end
245
+ end
245
246
 
246
- describe 'item_loader exception handling' do
247
- it 'should call the item_loader_exception_handler if it is set and there is an exception loading an activity feed item' do
248
- ActivityFeed.item_loader = Proc.new do |id|
249
- begin
250
- ActivityFeed::Mongoid::Item.find(id)
251
- rescue Mongoid::Errors::DocumentNotFound
252
- end
253
- end
247
+ describe '#expire_feed' do
248
+ it 'should set an expiration on an activity feed' do
249
+ add_items_to_feed('david', Leaderboard::DEFAULT_PAGE_SIZE)
254
250
 
255
- ActivityFeed.update_item('david', '4fe4c5f3421aa9b89c000001', Time.now.to_i, false)
256
- feed = ActivityFeed.feed('david', 1)
257
- feed.length.should == 0
251
+ ActivityFeed.expire_feed('david', 10)
252
+ ActivityFeed.redis.ttl(ActivityFeed.feed_key('david')).tap do |ttl|
253
+ ttl.should be > 1
254
+ ttl.should be <= 10
258
255
  end
256
+ end
257
+ end
259
258
 
260
- it 'should still load an activity feed, but call the item_loader_exception_handler if it is set and there is an exception loading an activity feed item' do
261
- ActivityFeed.item_loader = Proc.new do |id|
262
- begin
263
- ActivityFeed::Mongoid::Item.find(id)
264
- rescue Mongoid::Errors::DocumentNotFound
265
- end
266
- end
267
-
268
- item = ActivityFeed::Mongoid::Item.create(
269
- :user_id => 'david',
270
- :nickname => 'David Czarnecki',
271
- :type => 'some_activity',
272
- :title => 'Great activity',
273
- :text => 'This is text for the feed item',
274
- :url => 'http://url.com'
275
- )
276
-
277
- ActivityFeed.update_item('david', '4fe4c5f3421aa9b89c000001', DateTime.now.to_i)
278
-
279
- another_item = ActivityFeed::Mongoid::Item.create(
280
- :user_id => 'david',
281
- :nickname => 'David Czarnecki',
282
- :type => 'some_activity',
283
- :title => 'Great activity',
284
- :text => 'This is more text for the feed item',
285
- :url => 'http://url.com'
286
- )
287
-
288
- feed = ActivityFeed.feed('david', 1)
259
+ describe '#expire_feed_at' do
260
+ it 'should set an expiration timestamp on an activity feed' do
261
+ add_items_to_feed('david', Leaderboard::DEFAULT_PAGE_SIZE)
289
262
 
290
- feed.length.should == 2
263
+ ActivityFeed.expire_feed_at('david', (Time.now + 10).to_i)
264
+ ActivityFeed.redis.ttl(ActivityFeed.feed_key('david')).tap do |ttl|
265
+ ttl.should be > 1
266
+ ttl.should be <= 10
291
267
  end
292
268
  end
293
269
  end
data/spec/version_spec.rb CHANGED
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'ActivityFeed::VERSION' do
4
4
  it "should be the correct version" do
5
- ActivityFeed::VERSION.should == '2.1.0'
5
+ ActivityFeed::VERSION.should == '2.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activity_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-13 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -215,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
215
  version: '0'
216
216
  segments:
217
217
  - 0
218
- hash: -2201344879016856649
218
+ hash: -3462149266482733398
219
219
  required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  none: false
221
221
  requirements:
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  version: '0'
225
225
  segments:
226
226
  - 0
227
- hash: -2201344879016856649
227
+ hash: -3462149266482733398
228
228
  requirements: []
229
229
  rubyforge_project: activity_feed
230
230
  rubygems_version: 1.8.24