amico 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.3.0 (2012-08-29)
4
+
5
+ * Added `deny(from_id, to_id, scope = Amico.default_scope_key)` to remove a relationship that is pending between two IDs.
6
+
7
+ Again, thanks to [Skip Baney](https://github.com/twelvelabs) for the pull request with this functionality.
8
+
3
9
  ## 2.2.0 (2012-08-27)
4
10
 
5
11
  * Added `clear(id, scope = Amico.default_scope_key)` method to clear all relationships (in either direction) stored for an individual.
data/README.md CHANGED
@@ -13,7 +13,7 @@ gem 'amico'
13
13
  ```
14
14
 
15
15
  Make sure your redis server is running! Redis configuration is outside the scope of this README, but
16
- check out the Redis documentation, http://redis.io/documentation.
16
+ check out the [Redis documentation](http://redis.io/documentation).
17
17
 
18
18
  ## Usage
19
19
 
@@ -222,6 +222,25 @@ Amico.follower?(1, 11)
222
222
 
223
223
  Amico.reciprocated?(1, 11)
224
224
  => true
225
+
226
+ Amico.follow(1, 12)
227
+ => true
228
+
229
+ Amico.following?(1, 12)
230
+ => false
231
+
232
+ Amico.pending?(1, 12)
233
+ => true
234
+
235
+ Amico.deny(1, 12)
236
+ => true
237
+
238
+ Amico.following?(1, 12)
239
+ => false
240
+
241
+ Amico.pending?(1, 12)
242
+ => false
243
+
225
244
  ```
226
245
 
227
246
  Use amico with nicknames instead of IDs. NOTE: This could cause you much hardship later on if you allow nicknames to change.
@@ -482,6 +501,8 @@ block(from_id, to_id, scope = Amico.default_scope_key)
482
501
  unblock(from_id, to_id, scope = Amico.default_scope_key)
483
502
  # Accept a relationship that is pending between two IDs.
484
503
  accept(from_id, to_id, scope = Amico.default_scope_key)
504
+ # Deny a relationship that is pending between two IDs.
505
+ deny(from_id, to_id, scope = Amico.default_scope_key)
485
506
  # Clear all relationships (in either direction) for a given ID.
486
507
  clear(id, scope = Amico.default_scope_key)
487
508
 
@@ -114,6 +114,25 @@ module Amico
114
114
  add_following_followers_reciprocated(from_id, to_id, scope)
115
115
  end
116
116
 
117
+ # Deny a relationship that is pending between two IDs.
118
+ #
119
+ # @param from_id [String] The ID of the individual denying the relationship.
120
+ # @param to_id [String] The ID of the individual to be denied.
121
+ # @param scope [String] Scope for the call.
122
+ #
123
+ # Example
124
+ #
125
+ # Amico.follow(1, 11)
126
+ # Amico.pending?(1, 11) # true
127
+ # Amico.deny(1, 11)
128
+ # Amico.pending?(1, 11) # false
129
+ # Amico.following?(1, 11) #false
130
+ def deny(from_id, to_id, scope = Amico.default_scope_key)
131
+ return if from_id == to_id
132
+ Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
133
+ Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
134
+ end
135
+
117
136
  # Clears all relationships (in either direction) stored for an individual.
118
137
  # Helpful to prevent orphaned associations when deleting users.
119
138
  #
@@ -1,3 +1,3 @@
1
1
  module Amico
2
- VERSION = '2.2.0'
2
+ VERSION = '2.3.0'
3
3
  end
@@ -383,6 +383,21 @@ describe Amico::Relationships do
383
383
  end
384
384
  end
385
385
 
386
+ describe '#deny' do
387
+ it 'should remove the pending relationship without following or blocking' do
388
+ Amico.follow(1, 11)
389
+ Amico.pending?(1, 11).should be_true
390
+ Amico.pending_with?(11, 1).should be_true
391
+
392
+ Amico.deny(1, 11)
393
+
394
+ Amico.following?(1, 11).should be_false
395
+ Amico.pending?(1, 11).should be_false
396
+ Amico.pending_with?(11, 1).should be_false
397
+ Amico.blocked?(1, 11).should be_false
398
+ end
399
+ end
400
+
386
401
  describe '#block' do
387
402
  it 'should remove the pending relationship if you block someone' do
388
403
  Amico.follow(11, 1)
@@ -635,11 +650,13 @@ describe Amico::Relationships do
635
650
  Amico.reciprocated_count(11).should be(0)
636
651
  end
637
652
  it 'should clear pending/pending_with relationships' do
653
+ previous_pending_value = Amico.pending_follow
638
654
  Amico.pending_follow = true
639
655
  Amico.follow(1, 11)
640
656
  Amico.pending_count(11).should be(1)
641
657
  Amico.clear(1)
642
658
  Amico.pending_count(11).should be(0)
659
+ Amico.pending_follow = previous_pending_value
643
660
  end
644
661
  it 'should clear blocked/blocked_by relationships' do
645
662
  Amico.block(1, 11)
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  describe 'Amico::VERSION' do
4
4
  it 'should be the correct version' do
5
- Amico::VERSION.should == '2.2.0'
5
+ Amico::VERSION.should == '2.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amico
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.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-27 00:00:00.000000000 Z
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
@@ -95,18 +95,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
95
  - - ! '>='
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
- segments:
99
- - 0
100
- hash: 1949101995631561364
101
98
  required_rubygems_version: !ruby/object:Gem::Requirement
102
99
  none: false
103
100
  requirements:
104
101
  - - ! '>='
105
102
  - !ruby/object:Gem::Version
106
103
  version: '0'
107
- segments:
108
- - 0
109
- hash: 1949101995631561364
110
104
  requirements: []
111
105
  rubyforge_project: amico
112
106
  rubygems_version: 1.8.24