amico 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +20 -0
- data/README.md +73 -0
- data/lib/amico/configuration.rb +22 -0
- data/lib/amico/relationships.rb +198 -8
- data/lib/amico/version.rb +1 -1
- data/spec/amico/configuration_spec.rb +2 -0
- data/spec/amico/relationships_spec.rb +150 -22
- data/spec/amico/version_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +8 -2
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 2.2.0 (2012-08-27)
|
4
|
+
|
5
|
+
* Added `clear(id, scope = Amico.default_scope_key)` method to clear all relationships (in either direction) stored for an individual.
|
6
|
+
|
7
|
+
Added the following methods for the blocked by relationship:
|
8
|
+
|
9
|
+
* `blocked_by?(id, blocked_by_id, scope = Amico.default_scope_key)`
|
10
|
+
* `blocked_by(id, page_options = default_paging_options, scope = Amico.default_scope_key)`
|
11
|
+
* `blocked_by_count(id, scope = Amico.default_scope_key)`
|
12
|
+
* `blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)`
|
13
|
+
|
14
|
+
Added the following methods for the pending with relationship:
|
15
|
+
|
16
|
+
* `pending_with?(id, blocked_by_id, scope = Amico.default_scope_key)`
|
17
|
+
* `pending_with(id, page_options = default_paging_options, scope = Amico.default_scope_key)`
|
18
|
+
* `pending_with_count(id, scope = Amico.default_scope_key)`
|
19
|
+
* `pending_with_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)`
|
20
|
+
|
21
|
+
Thanks to [Skip Baney](https://github.com/twelvelabs) for all the work on this release.
|
22
|
+
|
3
23
|
## 2.1.0 (2012-08-20)
|
4
24
|
|
5
25
|
* Added `count(id, type, scope = Amico.default_scope_key)` and `page_count(id, type, page_size = Amico.page_size, scope = Amico.default_scope_key)` as convenience methods for retrieving the count or the page count for the various types of relationships.
|
data/README.md
CHANGED
@@ -26,8 +26,10 @@ Amico.configure do |configuration|
|
|
26
26
|
configuration.following_key = 'following'
|
27
27
|
configuration.followers_key = 'followers'
|
28
28
|
configuration.blocked_key = 'blocked'
|
29
|
+
configuration.blocked_by_key = 'blocked_by'
|
29
30
|
configuration.reciprocated_key = 'reciprocated'
|
30
31
|
configuration.pending_key = 'pending'
|
32
|
+
configuration.pending_with_key = 'pending_with'
|
31
33
|
configuration.default_scope_key = 'default'
|
32
34
|
configuration.pending_follow = false
|
33
35
|
configuration.page_size = 25
|
@@ -46,8 +48,10 @@ Amico.configure do |configuration|
|
|
46
48
|
configuration.following_key = 'following'
|
47
49
|
configuration.followers_key = 'followers'
|
48
50
|
configuration.blocked_key = 'blocked'
|
51
|
+
configuration.blocked_by_key = 'blocked_by'
|
49
52
|
configuration.reciprocated_key = 'reciprocated'
|
50
53
|
configuration.pending_key = 'pending'
|
54
|
+
configuration.pending_with_key = 'pending_with'
|
51
55
|
configuration.default_scope_key = 'default'
|
52
56
|
configuration.pending_follow = false
|
53
57
|
configuration.page_size = 25
|
@@ -98,12 +102,18 @@ Amico.following?(11, 1)
|
|
98
102
|
Amico.blocked?(1, 11)
|
99
103
|
=> true
|
100
104
|
|
105
|
+
Amico.blocked_by?(11, 1)
|
106
|
+
=> true
|
107
|
+
|
101
108
|
Amico.unblock(1, 11)
|
102
109
|
=> true
|
103
110
|
|
104
111
|
Amico.blocked?(1, 11)
|
105
112
|
=> false
|
106
113
|
|
114
|
+
Amico.blocked_by?(11, 1)
|
115
|
+
=> false
|
116
|
+
|
107
117
|
Amico.follow(11, 1)
|
108
118
|
=> nil
|
109
119
|
|
@@ -129,8 +139,10 @@ Amico.configure do |configuration|
|
|
129
139
|
configuration.following_key = 'following'
|
130
140
|
configuration.followers_key = 'followers'
|
131
141
|
configuration.blocked_key = 'blocked'
|
142
|
+
configuration.blocked_by_key = 'blocked_by'
|
132
143
|
configuration.reciprocated_key = 'reciprocated'
|
133
144
|
configuration.pending_key = 'pending'
|
145
|
+
configuration.pending_with_key = 'pending_with'
|
134
146
|
configuration.default_scope_key = 'default'
|
135
147
|
configuration.pending_follow = true
|
136
148
|
configuration.page_size = 25
|
@@ -145,18 +157,30 @@ Amico.follow(11, 1)
|
|
145
157
|
Amico.pending?(1, 11)
|
146
158
|
=> true
|
147
159
|
|
160
|
+
Amico.pending_with?(11, 1)
|
161
|
+
=> true
|
162
|
+
|
148
163
|
Amico.pending?(11, 1)
|
149
164
|
=> true
|
150
165
|
|
166
|
+
Amico.pending_with?(1, 11)
|
167
|
+
=> true
|
168
|
+
|
151
169
|
Amico.accept(1, 11)
|
152
170
|
=> nil
|
153
171
|
|
154
172
|
Amico.pending?(1, 11)
|
155
173
|
=> false
|
156
174
|
|
175
|
+
Amico.pending_with?(11, 1)
|
176
|
+
=> false
|
177
|
+
|
157
178
|
Amico.pending?(11, 1)
|
158
179
|
=> true
|
159
180
|
|
181
|
+
Amico.pending_with?(1, 11)
|
182
|
+
=> true
|
183
|
+
|
160
184
|
Amico.following?(1, 11)
|
161
185
|
=> true
|
162
186
|
|
@@ -175,9 +199,15 @@ Amico.accept(11, 1)
|
|
175
199
|
Amico.pending?(1, 11)
|
176
200
|
=> false
|
177
201
|
|
202
|
+
Amico.pending_with?(11, 1)
|
203
|
+
=> false
|
204
|
+
|
178
205
|
Amico.pending?(11, 1)
|
179
206
|
=> false
|
180
207
|
|
208
|
+
Amico.pending_with?(1, 11)
|
209
|
+
=> false
|
210
|
+
|
181
211
|
Amico.following?(1, 11)
|
182
212
|
=> true
|
183
213
|
|
@@ -205,8 +235,10 @@ Amico.configure do |configuration|
|
|
205
235
|
configuration.following_key = 'following'
|
206
236
|
configuration.followers_key = 'followers'
|
207
237
|
configuration.blocked_key = 'blocked'
|
238
|
+
configuration.blocked_by_key = 'blocked_by'
|
208
239
|
configuration.reciprocated_key = 'reciprocated'
|
209
240
|
configuration.pending_key = 'pending'
|
241
|
+
configuration.pending_with_key = 'pending_with'
|
210
242
|
configuration.default_scope_key = 'default'
|
211
243
|
configuration.pending_follow = false
|
212
244
|
configuration.page_size = 25
|
@@ -293,8 +325,10 @@ Amico.configure do |configuration|
|
|
293
325
|
configuration.following_key = 'following'
|
294
326
|
configuration.followers_key = 'followers'
|
295
327
|
configuration.blocked_key = 'blocked'
|
328
|
+
configuration.blocked_by_key = 'blocked_by'
|
296
329
|
configuration.reciprocated_key = 'reciprocated'
|
297
330
|
configuration.pending_key = 'pending'
|
331
|
+
configuration.pending_with_key = 'pending_with'
|
298
332
|
configuration.default_scope_key = 'default'
|
299
333
|
configuration.pending_follow = true
|
300
334
|
configuration.page_size = 25
|
@@ -365,8 +399,10 @@ Amico.configure do |configuration|
|
|
365
399
|
configuration.following_key = 'following'
|
366
400
|
configuration.followers_key = 'followers'
|
367
401
|
configuration.blocked_key = 'blocked'
|
402
|
+
configuration.blocked_by_key = 'blocked_by'
|
368
403
|
configuration.reciprocated_key = 'reciprocated'
|
369
404
|
configuration.pending_key = 'pending'
|
405
|
+
configuration.pending_with_key = 'pending_with'
|
370
406
|
configuration.default_scope_key = 'user'
|
371
407
|
configuration.pending_follow = false
|
372
408
|
configuration.page_size = 25
|
@@ -412,6 +448,25 @@ Amico.all(1, :following)
|
|
412
448
|
`type` can be one of :following, :followers, :blocked, :reciprocated, :pending. Use this with caution
|
413
449
|
as there may potentially be a large number of items that could be returned from this call.
|
414
450
|
|
451
|
+
You can clear all relationships that have been set for an ID by calling `clear(id, scope)`. You may wish to do this if you allow records to be deleted and you wish to prevent orphaned IDs and inaccurate follower/following counts. Note that this clears *all* relationships in either direction - including blocked and pending. An example:
|
452
|
+
|
453
|
+
```ruby
|
454
|
+
Amico.follow(11, 1)
|
455
|
+
=> nil
|
456
|
+
Amico.block(12, 1)
|
457
|
+
=> nil
|
458
|
+
Amico.following(11)
|
459
|
+
=> ["1"]
|
460
|
+
Amico.blocked(12)
|
461
|
+
=> ["1"]
|
462
|
+
Amico.clear(1)
|
463
|
+
=> nil
|
464
|
+
Amico.following(11)
|
465
|
+
=> []
|
466
|
+
Amico.blocked(12)
|
467
|
+
=> []
|
468
|
+
```
|
469
|
+
|
415
470
|
## Method Summary
|
416
471
|
|
417
472
|
```ruby
|
@@ -427,6 +482,8 @@ block(from_id, to_id, scope = Amico.default_scope_key)
|
|
427
482
|
unblock(from_id, to_id, scope = Amico.default_scope_key)
|
428
483
|
# Accept a relationship that is pending between two IDs.
|
429
484
|
accept(from_id, to_id, scope = Amico.default_scope_key)
|
485
|
+
# Clear all relationships (in either direction) for a given ID.
|
486
|
+
clear(id, scope = Amico.default_scope_key)
|
430
487
|
|
431
488
|
# Retrieval
|
432
489
|
|
@@ -436,10 +493,14 @@ following(id, page_options = default_paging_options, scope = Amico.default_scope
|
|
436
493
|
followers(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
437
494
|
# Retrieve a page of blocked individuals for a given ID.
|
438
495
|
blocked(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
496
|
+
# Retrieve a page of individuals who have blocked a given ID.
|
497
|
+
blocked_by(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
439
498
|
# Retrieve a page of individuals that have reciprocated a follow for a given ID.
|
440
499
|
reciprocated(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
441
500
|
# Retrieve a page of pending relationships for a given ID.
|
442
501
|
pending(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
502
|
+
# Retrieve a page of individuals that are waiting to approve the given ID.
|
503
|
+
pending_with(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
443
504
|
|
444
505
|
# Retrieve all of the individuals for a given id, type (e.g. following) and scope.
|
445
506
|
all(id, type, scope = Amico.default_scope_key)
|
@@ -452,10 +513,14 @@ following_count(id, scope = Amico.default_scope_key)
|
|
452
513
|
followers_count(id, scope = Amico.default_scope_key)
|
453
514
|
# Count the number of individuals that someone has blocked.
|
454
515
|
blocked_count(id, scope = Amico.default_scope_key)
|
516
|
+
# Count the number of individuals blocking another.
|
517
|
+
blocked_by_count(id, scope = Amico.default_scope_key)
|
455
518
|
# Count the number of individuals that have reciprocated a following relationship.
|
456
519
|
reciprocated_count(id, scope = Amico.default_scope_key)
|
457
520
|
# Count the number of relationships pending for an individual.
|
458
521
|
pending_count(id, scope = Amico.default_scope_key)
|
522
|
+
# Count the number of relationships an individual has pending with another.
|
523
|
+
pending_with_count(id, scope = Amico.default_scope_key)
|
459
524
|
|
460
525
|
# Count the number of pages of following relationships for an individual.
|
461
526
|
following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
@@ -463,10 +528,14 @@ following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scop
|
|
463
528
|
followers_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
464
529
|
# Count the number of pages of blocked relationships for an individual.
|
465
530
|
blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
531
|
+
# Count the number of pages of blocked_by relationships for an individual.
|
532
|
+
blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
466
533
|
# Count the number of pages of reciprocated relationships for an individual.
|
467
534
|
reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
468
535
|
# Count the number of pages of pending relationships for an individual.
|
469
536
|
pending_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
537
|
+
# Count the number of pages of individuals waiting to approve another individual.
|
538
|
+
pending_with_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
470
539
|
|
471
540
|
# Checks
|
472
541
|
|
@@ -476,10 +545,14 @@ following?(id, following_id, scope = Amico.default_scope_key)
|
|
476
545
|
follower?(id, follower_id, scope = Amico.default_scope_key)
|
477
546
|
# Check to see if one individual has blocked another individual.
|
478
547
|
blocked?(id, blocked_id, scope = Amico.default_scope_key)
|
548
|
+
# Check to see if one individual is blocked by another individual.
|
549
|
+
blocked_by?(id, blocked_id, scope = Amico.default_scope_key)
|
479
550
|
# Check to see if one individual has reciprocated in following another individual.
|
480
551
|
reciprocated?(from_id, to_id, scope = Amico.default_scope_key)
|
481
552
|
# Check to see if one individual has a pending relationship in following another individual.
|
482
553
|
pending?(from_id, to_id, scope = Amico.default_scope_key)
|
554
|
+
# Check to see if one individual has a pending relationship with another.
|
555
|
+
pending_with?(from_id, to_id, scope = Amico.default_scope_key)
|
483
556
|
```
|
484
557
|
|
485
558
|
## Documentation
|
data/lib/amico/configuration.rb
CHANGED
@@ -16,12 +16,18 @@ module Amico
|
|
16
16
|
# Key used in Redis for tracking who an individual blocks.
|
17
17
|
attr_writer :blocked_key
|
18
18
|
|
19
|
+
# Key used in Redis for tracking who has blocked an individual.
|
20
|
+
attr_writer :blocked_by_key
|
21
|
+
|
19
22
|
# Key used in Redis for tracking who has reciprocated a follow for an individual.
|
20
23
|
attr_writer :reciprocated_key
|
21
24
|
|
22
25
|
# Key used in Redis for tracking pending follow relationships for an individual.
|
23
26
|
attr_writer :pending_key
|
24
27
|
|
28
|
+
# Key used in Redis for tracking who an individual is awaiting approval from.
|
29
|
+
attr_writer :pending_with_key
|
30
|
+
|
25
31
|
# Key used to indicate whether or not a follow should be pending or not.
|
26
32
|
attr_writer :pending_follow
|
27
33
|
|
@@ -41,8 +47,10 @@ module Amico
|
|
41
47
|
# configuration.following_key = 'following'
|
42
48
|
# configuration.followers_key = 'followers'
|
43
49
|
# configuration.blocked_key = 'blocked'
|
50
|
+
# configuration.blocked_by_key = 'blocked_by'
|
44
51
|
# configuration.reciprocated_key = 'reciprocated'
|
45
52
|
# configuration.pending_key = 'pending'
|
53
|
+
# configuration.pending_with_key = 'pending_with'
|
46
54
|
# configuration.default_scope_key = 'default'
|
47
55
|
# configuration.pending_follow = false
|
48
56
|
# configuration.page_size = 25
|
@@ -79,6 +87,13 @@ module Amico
|
|
79
87
|
@blocked_key ||= 'blocked'
|
80
88
|
end
|
81
89
|
|
90
|
+
# Key used in Redis for tracking who has blocked an individual.
|
91
|
+
#
|
92
|
+
# @return the key used in Redis for tracking who has blocked an individual or the default of 'blocked_by' if not set.
|
93
|
+
def blocked_by_key
|
94
|
+
@blocked_by_key ||= 'blocked_by'
|
95
|
+
end
|
96
|
+
|
82
97
|
# Key used in Redis for tracking who has reciprocated a follow for an individual.
|
83
98
|
#
|
84
99
|
# @return the key used in Redis for tracking who has reciprocated a follow for an individual or the default of 'reciprocated' if not set.
|
@@ -93,6 +108,13 @@ module Amico
|
|
93
108
|
@pending_key ||= 'pending'
|
94
109
|
end
|
95
110
|
|
111
|
+
# Key used in Redis for tracking who an individual is awaiting approval from.
|
112
|
+
#
|
113
|
+
# @return the key used in Redis for tracking who an individual is awaiting approval from or the default of 'pending_with' if not set.
|
114
|
+
def pending_with_key
|
115
|
+
@pending_with_key ||= 'pending_with'
|
116
|
+
end
|
117
|
+
|
96
118
|
# Default key used in Redis for tracking scope for the given relationship calls.
|
97
119
|
#
|
98
120
|
# @return the default key used in Redis for tracking scope for the given relationship calls.
|
data/lib/amico/relationships.rb
CHANGED
@@ -20,6 +20,7 @@ module Amico
|
|
20
20
|
add_following_followers_reciprocated(from_id, to_id, scope)
|
21
21
|
else
|
22
22
|
Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
23
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
23
24
|
end
|
24
25
|
end
|
25
26
|
|
@@ -44,6 +45,7 @@ module Amico
|
|
44
45
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
|
45
46
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
|
46
47
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
|
48
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
|
47
49
|
end
|
48
50
|
end
|
49
51
|
|
@@ -68,7 +70,9 @@ module Amico
|
|
68
70
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
|
69
71
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
|
70
72
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}", to_id)
|
73
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id)
|
71
74
|
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
75
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
72
76
|
end
|
73
77
|
end
|
74
78
|
|
@@ -85,7 +89,10 @@ module Amico
|
|
85
89
|
def unblock(from_id, to_id, scope = Amico.default_scope_key)
|
86
90
|
return if from_id == to_id
|
87
91
|
|
88
|
-
|
92
|
+
Amico.redis.multi do
|
93
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", to_id)
|
94
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{to_id}", from_id)
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
# Accept a relationship that is pending between two IDs.
|
@@ -107,6 +114,31 @@ module Amico
|
|
107
114
|
add_following_followers_reciprocated(from_id, to_id, scope)
|
108
115
|
end
|
109
116
|
|
117
|
+
# Clears all relationships (in either direction) stored for an individual.
|
118
|
+
# Helpful to prevent orphaned associations when deleting users.
|
119
|
+
#
|
120
|
+
# @param id [String] ID of the individual to clear info for.
|
121
|
+
# @param scope [String] Scope for the call.
|
122
|
+
#
|
123
|
+
# Examples
|
124
|
+
#
|
125
|
+
# Amico.follow(1, 11)
|
126
|
+
# Amico.followers_count(11) => 1
|
127
|
+
# Amico.clear(1)
|
128
|
+
# Amico.followers_count(11) => 0
|
129
|
+
def clear(id, scope = Amico.default_scope_key)
|
130
|
+
# no longer following (or followed by) anyone
|
131
|
+
clear_bidirectional_sets_for_id(id, Amico.following_key, Amico.followers_key, scope)
|
132
|
+
clear_bidirectional_sets_for_id(id, Amico.followers_key, Amico.following_key, scope)
|
133
|
+
clear_bidirectional_sets_for_id(id, Amico.reciprocated_key, Amico.reciprocated_key, scope)
|
134
|
+
# no longer blocked by (or blocking) anyone
|
135
|
+
clear_bidirectional_sets_for_id(id, Amico.blocked_by_key, Amico.blocked_key, scope)
|
136
|
+
clear_bidirectional_sets_for_id(id, Amico.blocked_key, Amico.blocked_by_key, scope)
|
137
|
+
# no longer pending with anyone (or have any pending followers)
|
138
|
+
clear_bidirectional_sets_for_id(id, Amico.pending_with_key, Amico.pending_key, scope)
|
139
|
+
clear_bidirectional_sets_for_id(id, Amico.pending_key, Amico.pending_with_key, scope)
|
140
|
+
end
|
141
|
+
|
110
142
|
# Count the number of individuals that someone is following.
|
111
143
|
#
|
112
144
|
# @param id [String] ID of the individual to retrieve following count for.
|
@@ -152,6 +184,21 @@ module Amico
|
|
152
184
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}")
|
153
185
|
end
|
154
186
|
|
187
|
+
# Count the number of individuals blocking another.
|
188
|
+
#
|
189
|
+
# @param id [String] ID of the individual to retrieve blocked_by count for.
|
190
|
+
# @param scope [String] Scope for the call.
|
191
|
+
#
|
192
|
+
# Examples
|
193
|
+
#
|
194
|
+
# Amico.block(1, 11)
|
195
|
+
# Amico.blocked_by_count(11)
|
196
|
+
#
|
197
|
+
# @return the count of the number of individuals blocking someone.
|
198
|
+
def blocked_by_count(id, scope = Amico.default_scope_key)
|
199
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}")
|
200
|
+
end
|
201
|
+
|
155
202
|
# Count the number of individuals that have reciprocated a following relationship.
|
156
203
|
#
|
157
204
|
# @param id [String] ID of the individual to retrieve reciprocated following count for.
|
@@ -184,6 +231,22 @@ module Amico
|
|
184
231
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}")
|
185
232
|
end
|
186
233
|
|
234
|
+
# Count the number of relationships an individual has pending with another.
|
235
|
+
#
|
236
|
+
# @param id [String] ID of the individual to retrieve pending count for.
|
237
|
+
# @param scope [String] Scope for the call.
|
238
|
+
#
|
239
|
+
# Examples
|
240
|
+
#
|
241
|
+
# Amico.follow(1, 11)
|
242
|
+
# Amico.follow(1, 12)
|
243
|
+
# Amico.pending_count(1) # 2
|
244
|
+
#
|
245
|
+
# @return the count of the number of relationships an individual has pending with another.
|
246
|
+
def pending_with_count(id, scope = Amico.default_scope_key)
|
247
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{id}")
|
248
|
+
end
|
249
|
+
|
187
250
|
# Check to see if one individual is following another individual.
|
188
251
|
#
|
189
252
|
# @param id [String] ID of the individual checking the following status.
|
@@ -232,6 +295,22 @@ module Amico
|
|
232
295
|
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", blocked_id).nil?
|
233
296
|
end
|
234
297
|
|
298
|
+
# Check to see if one individual is blocked by another individual.
|
299
|
+
#
|
300
|
+
# @param id [String] ID of the individual checking the blocked by status.
|
301
|
+
# @param blocked_id [String] ID of the individual to see if they have blocked id.
|
302
|
+
# @param scope [String] Scope for the call.
|
303
|
+
#
|
304
|
+
# Examples
|
305
|
+
#
|
306
|
+
# Amico.block(1, 11)
|
307
|
+
# Amico.blocked_by?(11, 1)
|
308
|
+
#
|
309
|
+
# @return true if id is blocked by blocked_by_id, false otherwise
|
310
|
+
def blocked_by?(id, blocked_by_id, scope = Amico.default_scope_key)
|
311
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", blocked_by_id).nil?
|
312
|
+
end
|
313
|
+
|
235
314
|
# Check to see if one individual has reciprocated in following another individual.
|
236
315
|
#
|
237
316
|
# @param from_id [String] ID of the individual checking the reciprocated relationship.
|
@@ -265,6 +344,22 @@ module Amico
|
|
265
344
|
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id).nil?
|
266
345
|
end
|
267
346
|
|
347
|
+
# Check to see if one individual has a pending relationship with another.
|
348
|
+
#
|
349
|
+
# @param from_id [String] ID of the individual checking the pending relationships.
|
350
|
+
# @param to_id [String] ID of the individual to see if they are pending an approval from from_id.
|
351
|
+
# @param scope [String] Scope for the call.
|
352
|
+
#
|
353
|
+
# Examples
|
354
|
+
#
|
355
|
+
# Amico.follow(1, 11)
|
356
|
+
# Amico.pending_with?(11, 1) # true
|
357
|
+
#
|
358
|
+
# @return true if the relationship is pending, false otherwise
|
359
|
+
def pending_with?(from_id, to_id, scope = Amico.default_scope_key)
|
360
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{to_id}", from_id).nil?
|
361
|
+
end
|
362
|
+
|
268
363
|
# Retrieve a page of followed individuals for a given ID.
|
269
364
|
#
|
270
365
|
# @param id [String] ID of the individual.
|
@@ -316,6 +411,23 @@ module Amico
|
|
316
411
|
members("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_options)
|
317
412
|
end
|
318
413
|
|
414
|
+
# Retrieve a page of individuals who have blocked a given ID.
|
415
|
+
#
|
416
|
+
# @param id [String] ID of the individual.
|
417
|
+
# @param page_options [Hash] Options to be passed for retrieving a page of blocking individuals.
|
418
|
+
# @param scope [String] Scope for the call.
|
419
|
+
#
|
420
|
+
# Examples
|
421
|
+
#
|
422
|
+
# Amico.block(11, 1)
|
423
|
+
# Amico.block(12, 1)
|
424
|
+
# Amico.blocked_by(1, :page => 1)
|
425
|
+
#
|
426
|
+
# @return a page of individuals who have blocked a given ID.
|
427
|
+
def blocked_by(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
428
|
+
members("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_options)
|
429
|
+
end
|
430
|
+
|
319
431
|
# Retrieve a page of individuals that have reciprocated a follow for a given ID.
|
320
432
|
#
|
321
433
|
# @param id [String] ID of the individual.
|
@@ -343,8 +455,8 @@ module Amico
|
|
343
455
|
#
|
344
456
|
# Examples
|
345
457
|
#
|
346
|
-
# Amico.follow(
|
347
|
-
# Amico.follow(
|
458
|
+
# Amico.follow(11, 1)
|
459
|
+
# Amico.follow(12, 1)
|
348
460
|
# Amico.pending(1, :page => 1)
|
349
461
|
#
|
350
462
|
# @return a page of pending relationships for a given ID.
|
@@ -352,6 +464,23 @@ module Amico
|
|
352
464
|
members("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", page_options)
|
353
465
|
end
|
354
466
|
|
467
|
+
# Retrieve a page of individuals that are waiting to approve the given ID.
|
468
|
+
#
|
469
|
+
# @param id [String] ID of the individual.
|
470
|
+
# @param page_options [Hash] Options to be passed for retrieving a page of pending relationships.
|
471
|
+
# @param scope [String] Scope for the call.
|
472
|
+
#
|
473
|
+
# Examples
|
474
|
+
#
|
475
|
+
# Amico.follow(1, 11)
|
476
|
+
# Amico.follow(1, 12)
|
477
|
+
# Amico.pending_with(1, :page => 1)
|
478
|
+
#
|
479
|
+
# @return a page of individuals that are waiting to approve the given ID.
|
480
|
+
def pending_with(id, page_options = default_paging_options, scope = Amico.default_scope_key)
|
481
|
+
members("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{id}", page_options)
|
482
|
+
end
|
483
|
+
|
355
484
|
# Count the number of pages of following relationships for an individual.
|
356
485
|
#
|
357
486
|
# @param id [String] ID of the individual.
|
@@ -403,6 +532,23 @@ module Amico
|
|
403
532
|
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
|
404
533
|
end
|
405
534
|
|
535
|
+
# Count the number of pages of blocked_by relationships for an individual.
|
536
|
+
#
|
537
|
+
# @param id [String] ID of the individual.
|
538
|
+
# @param page_size [int] Page size (default: Amico.page_size).
|
539
|
+
# @param scope [String] Scope for the call.
|
540
|
+
#
|
541
|
+
# Examples
|
542
|
+
#
|
543
|
+
# Amico.block(11, 1)
|
544
|
+
# Amico.block(12, 1)
|
545
|
+
# Amico.blocked_by_page_count(1)
|
546
|
+
#
|
547
|
+
# @return the number of pages of blocked_by relationships for an individual.
|
548
|
+
def blocked_by_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
549
|
+
total_pages("#{Amico.namespace}:#{Amico.blocked_by_key}:#{scope}:#{id}", page_size)
|
550
|
+
end
|
551
|
+
|
406
552
|
# Count the number of pages of reciprocated relationships for an individual.
|
407
553
|
#
|
408
554
|
# @param id [String] ID of the individual.
|
@@ -439,14 +585,30 @@ module Amico
|
|
439
585
|
total_pages("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", page_size)
|
440
586
|
end
|
441
587
|
|
588
|
+
# Count the number of pages of individuals waiting to approve another individual.
|
589
|
+
#
|
590
|
+
# @param id [String] ID of the individual.
|
591
|
+
# @param page_size [int] Page size (default: Amico.page_size).
|
592
|
+
# @param scope [String] Scope for the call.
|
593
|
+
#
|
594
|
+
# Examples
|
595
|
+
#
|
596
|
+
# Amico.follow(1, 11)
|
597
|
+
# Amico.follow(1, 12)
|
598
|
+
# Amico.pending_with_page_count(1) # 1
|
599
|
+
#
|
600
|
+
# @return the number of pages of individuals waiting to approve another individual.
|
601
|
+
def pending_with_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
602
|
+
total_pages("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{id}", page_size)
|
603
|
+
end
|
604
|
+
|
442
605
|
# Retrieve all of the individuals for a given id, type (e.g. following) and scope
|
443
606
|
#
|
444
607
|
# @param id [String] ID of the individual.
|
445
|
-
# @param type [Symbol] One of :following, :followers, :blocked, :
|
608
|
+
# @param type [Symbol] One of :following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with.
|
446
609
|
# @param scope [String] Scope for the call.
|
447
610
|
def all(id, type, scope = Amico.default_scope_key)
|
448
|
-
|
449
|
-
raise "Must be one of #{valid_types.to_s}" if !valid_types.include?(type)
|
611
|
+
validate_relationship_type(type)
|
450
612
|
count = self.send("#{type.to_s}_count".to_sym, id, scope)
|
451
613
|
count > 0 ? self.send("#{type}", id, {:page_size => count}, scope) : []
|
452
614
|
end
|
@@ -454,28 +616,41 @@ module Amico
|
|
454
616
|
# Retrieve a count of all of a given type of relationship for the specified id.
|
455
617
|
#
|
456
618
|
# @param id [String] ID of the individual.
|
457
|
-
|
619
|
+
# @param type [Symbol] One of :following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with.
|
458
620
|
# @param scope [String] Scope for the call.
|
459
621
|
#
|
460
622
|
# @return Count of all of a given type of relationship for the specified id.
|
461
623
|
def count(id, type, scope = Amico.default_scope_key)
|
624
|
+
validate_relationship_type(type)
|
462
625
|
self.send("#{type.to_s}_count".to_sym, id, scope)
|
463
626
|
end
|
464
627
|
|
465
628
|
# Retrieve a page count of a given type of relationship for the specified id.
|
466
629
|
#
|
467
630
|
# @param id [String] ID of the individual.
|
468
|
-
|
631
|
+
# @param type [Symbol] One of :following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with.
|
469
632
|
# @param page_size [int] Page size (default: Amico.page_size).
|
470
633
|
# @param scope [String] Scope for the call.
|
471
634
|
#
|
472
635
|
# @return Page count of a given type of relationship for the specified id.
|
473
636
|
def page_count(id, type, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
637
|
+
validate_relationship_type(type)
|
474
638
|
self.send("#{type.to_s}_page_count".to_sym, id, page_size, scope)
|
475
639
|
end
|
476
640
|
|
477
641
|
private
|
478
642
|
|
643
|
+
# Valid relationtionships that can be used in #all, #count, #page_count, etc...
|
644
|
+
VALID_RELATIONSHIPS = [:following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with]
|
645
|
+
|
646
|
+
# Ensure that a relationship type is valid.
|
647
|
+
#
|
648
|
+
# @param type [Symbol] One of :following, :followers, :reciprocated, :blocked, :blocked_by, :pending, :pending_with.
|
649
|
+
# @raise [StandardError] if the type is not included in VALID_RELATIONSHIPS
|
650
|
+
def validate_relationship_type(type)
|
651
|
+
raise "Must be one of #{VALID_RELATIONSHIPS.to_s}" if !VALID_RELATIONSHIPS.include?(type)
|
652
|
+
end
|
653
|
+
|
479
654
|
# Default paging options.
|
480
655
|
#
|
481
656
|
# @return a hash of the default paging options.
|
@@ -493,6 +668,7 @@ module Amico
|
|
493
668
|
Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
494
669
|
Amico.redis.zadd("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
495
670
|
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
|
671
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_with_key}:#{scope}:#{from_id}", to_id)
|
496
672
|
end
|
497
673
|
|
498
674
|
if reciprocated?(from_id, to_id)
|
@@ -503,6 +679,20 @@ module Amico
|
|
503
679
|
end
|
504
680
|
end
|
505
681
|
|
682
|
+
# Removes references to an individual in sets that are named with other individual's keys.
|
683
|
+
# Assumes two set keys that are used together such as followers/following, blocked/blocked_by, etc...
|
684
|
+
#
|
685
|
+
# @param id [String] The ID of the individual to clear info for.
|
686
|
+
# @param source_set_key [String] The key identifying the souce set to iterate over.
|
687
|
+
# @param related_set_key [String] The key identifying the sets that the idividual needs to be removed from.
|
688
|
+
# @param scope [String] Scope for the call.
|
689
|
+
def clear_bidirectional_sets_for_id(id, source_set_key, related_set_key, scope = Amico.default_scope_key)
|
690
|
+
Amico.redis.zrange("#{Amico.namespace}:#{source_set_key}:#{scope}:#{id}", 0, -1).each do |related_id|
|
691
|
+
Amico.redis.zrem("#{Amico.namespace}:#{related_set_key}:#{scope}:#{related_id}", id)
|
692
|
+
end
|
693
|
+
Amico.redis.del("#{Amico.namespace}:#{source_set_key}:#{scope}:#{id}")
|
694
|
+
end
|
695
|
+
|
506
696
|
# Count the total number of pages for a given key in a Redis sorted set.
|
507
697
|
#
|
508
698
|
# @param key [String] Redis key.
|
data/lib/amico/version.rb
CHANGED
@@ -8,8 +8,10 @@ describe Amico::Configuration do
|
|
8
8
|
configuration.following_key.should eql('following')
|
9
9
|
configuration.followers_key.should eql('followers')
|
10
10
|
configuration.blocked_key.should eql('blocked')
|
11
|
+
configuration.blocked_by_key.should eql('blocked_by')
|
11
12
|
configuration.reciprocated_key.should eql('reciprocated')
|
12
13
|
configuration.pending_key.should eql('pending')
|
14
|
+
configuration.pending_with_key.should eql('pending_with')
|
13
15
|
configuration.default_scope_key.should eql('default')
|
14
16
|
configuration.pending_follow.should be_false
|
15
17
|
configuration.page_size.should be(25)
|
@@ -46,8 +46,9 @@ describe Amico::Relationships do
|
|
46
46
|
Amico.follow(11, 1)
|
47
47
|
Amico.block(1, 11)
|
48
48
|
|
49
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
50
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
49
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
50
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
51
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_by_key}:#{Amico.default_scope_key}:11").should be(1)
|
51
52
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:1").should be(0)
|
52
53
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:11").should be(0)
|
53
54
|
end
|
@@ -55,20 +56,21 @@ describe Amico::Relationships do
|
|
55
56
|
it 'should allow you to block someone who is not following you' do
|
56
57
|
Amico.block(1, 11)
|
57
58
|
|
58
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
59
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
59
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
60
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
61
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_by_key}:#{Amico.default_scope_key}:11").should be(1)
|
60
62
|
end
|
61
63
|
|
62
64
|
it 'should not allow someone you have blocked to follow you' do
|
63
65
|
Amico.block(1, 11)
|
64
66
|
|
65
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
66
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
67
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
68
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
67
69
|
|
68
70
|
Amico.follow(11, 1)
|
69
71
|
|
70
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
71
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
72
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:11").should be(0)
|
73
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{Amico.default_scope_key}:1").should be(1)
|
72
74
|
end
|
73
75
|
|
74
76
|
it 'should not allow you to block yourself' do
|
@@ -81,8 +83,10 @@ describe Amico::Relationships do
|
|
81
83
|
it 'should allow you to unblock someone you have blocked' do
|
82
84
|
Amico.block(1, 11)
|
83
85
|
Amico.blocked?(1, 11).should be_true
|
86
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_by_key}:#{Amico.default_scope_key}:11").should be(1)
|
84
87
|
Amico.unblock(1, 11)
|
85
|
-
Amico.blocked?(1, 11).should be_false
|
88
|
+
Amico.blocked?(1, 11).should be_false
|
89
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_by_key}:#{Amico.default_scope_key}:11").should be(0)
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
@@ -116,6 +120,13 @@ describe Amico::Relationships do
|
|
116
120
|
end
|
117
121
|
end
|
118
122
|
|
123
|
+
describe '#blocked_by?' do
|
124
|
+
it 'should return that someone is blocking you' do
|
125
|
+
Amico.block(1, 11)
|
126
|
+
Amico.blocked_by?(11, 1).should be_true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
119
130
|
describe '#reciprocated?' do
|
120
131
|
it 'should return true if both individuals are following each other' do
|
121
132
|
Amico.follow(1, 11)
|
@@ -139,7 +150,7 @@ describe Amico::Relationships do
|
|
139
150
|
|
140
151
|
it 'should page correctly' do
|
141
152
|
add_reciprocal_followers
|
142
|
-
|
153
|
+
|
143
154
|
Amico.following(1, :page => 1, :page_size => 5).size.should be(5)
|
144
155
|
Amico.following(1, :page => 1, :page_size => 10).size.should be(10)
|
145
156
|
Amico.following(1, :page => 1, :page_size => 26).size.should be(25)
|
@@ -180,6 +191,15 @@ describe Amico::Relationships do
|
|
180
191
|
end
|
181
192
|
end
|
182
193
|
|
194
|
+
describe '#blocked_by' do
|
195
|
+
it 'should return the correct list' do
|
196
|
+
Amico.block(11, 1)
|
197
|
+
Amico.block(12, 1)
|
198
|
+
Amico.blocked_by(1).should eql(["12", "11"])
|
199
|
+
Amico.blocked_by(1, :page => 5).should eql(["12", "11"])
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
183
203
|
describe '#reciprocated' do
|
184
204
|
it 'should return the correct list' do
|
185
205
|
Amico.follow(1, 11)
|
@@ -218,6 +238,13 @@ describe Amico::Relationships do
|
|
218
238
|
end
|
219
239
|
end
|
220
240
|
|
241
|
+
describe '#blocked_by_count' do
|
242
|
+
it 'should return the correct count' do
|
243
|
+
Amico.block(1, 11)
|
244
|
+
Amico.blocked_by_count(11).should be(1)
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
221
248
|
describe '#reciprocated_count' do
|
222
249
|
it 'should return the correct count' do
|
223
250
|
Amico.follow(1, 11)
|
@@ -259,6 +286,16 @@ describe Amico::Relationships do
|
|
259
286
|
end
|
260
287
|
end
|
261
288
|
|
289
|
+
describe '#blocked_by_page_count' do
|
290
|
+
it 'should return the correct count' do
|
291
|
+
add_reciprocal_followers(26, true)
|
292
|
+
|
293
|
+
Amico.blocked_by_page_count(1).should be(1)
|
294
|
+
Amico.blocked_by_page_count(1, 10).should be(3)
|
295
|
+
Amico.blocked_by_page_count(1, 5).should be(5)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
262
299
|
describe '#reciprocated_page_count' do
|
263
300
|
it 'should return the correct count' do
|
264
301
|
add_reciprocal_followers
|
@@ -285,6 +322,7 @@ describe Amico::Relationships do
|
|
285
322
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
286
323
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
287
324
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(1)
|
325
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_with_key}:#{Amico.default_scope_key}:1").should be(1)
|
288
326
|
end
|
289
327
|
|
290
328
|
it 'should remove the pending relationship if you have a pending follow, but you unfollow' do
|
@@ -293,21 +331,25 @@ describe Amico::Relationships do
|
|
293
331
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
294
332
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
295
333
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(1)
|
334
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_with_key}:#{Amico.default_scope_key}:1").should be(1)
|
296
335
|
|
297
336
|
Amico.unfollow(1, 11)
|
298
337
|
|
299
338
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
300
339
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
301
340
|
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(0)
|
341
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_with_key}:#{Amico.default_scope_key}:1").should be(0)
|
302
342
|
end
|
303
343
|
|
304
344
|
it 'should remove the pending relationship and add to following and followers if #accept is called' do
|
305
345
|
Amico.follow(1, 11)
|
306
346
|
Amico.pending?(1, 11).should be_true
|
347
|
+
Amico.pending_with?(11, 1).should be_true
|
307
348
|
|
308
349
|
Amico.accept(1, 11)
|
309
350
|
|
310
351
|
Amico.pending?(1, 11).should be_false
|
352
|
+
Amico.pending_with?(11, 1).should be_false
|
311
353
|
Amico.following?(1, 11).should be_true
|
312
354
|
Amico.following?(11, 1).should be_false
|
313
355
|
Amico.follower?(11, 1).should be_true
|
@@ -345,8 +387,10 @@ describe Amico::Relationships do
|
|
345
387
|
it 'should remove the pending relationship if you block someone' do
|
346
388
|
Amico.follow(11, 1)
|
347
389
|
Amico.pending?(11, 1).should be_true
|
390
|
+
Amico.pending_with?(1, 11).should be_true
|
348
391
|
Amico.block(1, 11)
|
349
392
|
Amico.pending?(11, 1).should be_false
|
393
|
+
Amico.pending_with?(1, 11).should be_false
|
350
394
|
Amico.blocked?(1, 11).should be_true
|
351
395
|
end
|
352
396
|
end
|
@@ -368,6 +412,23 @@ describe Amico::Relationships do
|
|
368
412
|
end
|
369
413
|
end
|
370
414
|
|
415
|
+
describe '#pending_with' do
|
416
|
+
it 'should return the correct list' do
|
417
|
+
Amico.follow(1, 11)
|
418
|
+
Amico.follow(11, 1)
|
419
|
+
Amico.pending_with(1).should eql(["11"])
|
420
|
+
Amico.pending_with(11).should eql(["1"])
|
421
|
+
end
|
422
|
+
|
423
|
+
it 'should page correctly' do
|
424
|
+
add_reciprocal_followers
|
425
|
+
|
426
|
+
Amico.pending_with(1, :page => 1, :page_size => 5).size.should be(5)
|
427
|
+
Amico.pending_with(1, :page => 1, :page_size => 10).size.should be(10)
|
428
|
+
Amico.pending_with(1, :page => 1, :page_size => 26).size.should be(25)
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
371
432
|
describe '#pending_count' do
|
372
433
|
it 'should return the correct count' do
|
373
434
|
Amico.follow(1, 11)
|
@@ -379,6 +440,17 @@ describe Amico::Relationships do
|
|
379
440
|
end
|
380
441
|
end
|
381
442
|
|
443
|
+
describe '#pending_with_count' do
|
444
|
+
it 'should return the correct count' do
|
445
|
+
Amico.follow(1, 11)
|
446
|
+
Amico.follow(11, 1)
|
447
|
+
Amico.follow(1, 12)
|
448
|
+
Amico.follow(12, 1)
|
449
|
+
Amico.follow(1, 13)
|
450
|
+
Amico.pending_with_count(1).should be(3)
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
382
454
|
describe '#pending_page_count' do
|
383
455
|
it 'should return the correct count' do
|
384
456
|
add_reciprocal_followers
|
@@ -388,6 +460,16 @@ describe Amico::Relationships do
|
|
388
460
|
Amico.pending_page_count(1, 5).should be(5)
|
389
461
|
end
|
390
462
|
end
|
463
|
+
|
464
|
+
describe '#pending_with_page_count' do
|
465
|
+
it 'should return the correct count' do
|
466
|
+
add_reciprocal_followers
|
467
|
+
|
468
|
+
Amico.pending_with_page_count(1).should be(1)
|
469
|
+
Amico.pending_with_page_count(1, 10).should be(3)
|
470
|
+
Amico.pending_with_page_count(1, 5).should be(5)
|
471
|
+
end
|
472
|
+
end
|
391
473
|
end
|
392
474
|
|
393
475
|
describe 'scope' do
|
@@ -407,7 +489,7 @@ describe Amico::Relationships do
|
|
407
489
|
|
408
490
|
describe '#all' do
|
409
491
|
it 'should raise an exception if passing an invalid type' do
|
410
|
-
lambda {Amico.all(1, :unknown)}.should raise_error
|
492
|
+
lambda {Amico.all(1, :unknown)}.should raise_error
|
411
493
|
end
|
412
494
|
|
413
495
|
it 'should return the correct list when calling all for various types' do
|
@@ -445,6 +527,9 @@ describe Amico::Relationships do
|
|
445
527
|
|
446
528
|
blocked_list = Amico.all(1, :blocked)
|
447
529
|
blocked_list.length.should be(4)
|
530
|
+
|
531
|
+
blocked_by_list = Amico.all(1, :blocked_by)
|
532
|
+
blocked_by_list.length.should be(4)
|
448
533
|
end
|
449
534
|
end
|
450
535
|
|
@@ -486,44 +571,87 @@ describe Amico::Relationships do
|
|
486
571
|
it 'should return the correct count for the various types of relationships' do
|
487
572
|
add_reciprocal_followers(5)
|
488
573
|
|
489
|
-
Amico.count(1, :following).should
|
490
|
-
Amico.count(1, :followers).should
|
491
|
-
Amico.count(1, :reciprocated).should
|
574
|
+
Amico.count(1, :following).should eql(4)
|
575
|
+
Amico.count(1, :followers).should eql(4)
|
576
|
+
Amico.count(1, :reciprocated).should eql(4)
|
492
577
|
|
493
578
|
Amico.redis.flushdb
|
494
579
|
add_reciprocal_followers(5, true)
|
495
580
|
|
496
|
-
Amico.count(1, :blocked).should
|
581
|
+
Amico.count(1, :blocked).should eql(4)
|
582
|
+
Amico.count(1, :blocked_by).should eql(4)
|
497
583
|
|
498
584
|
Amico.redis.flushdb
|
499
585
|
Amico.pending_follow = true
|
500
586
|
add_reciprocal_followers(5)
|
501
587
|
|
502
|
-
Amico.count(1, :pending).should
|
588
|
+
Amico.count(1, :pending).should eql(4)
|
503
589
|
end
|
504
590
|
end
|
505
591
|
|
506
592
|
describe '#page_count' do
|
507
|
-
it 'should return the correct page count for the various types of relationships' do
|
593
|
+
it 'should return the correct page count for the various types of relationships' do
|
508
594
|
add_reciprocal_followers(5)
|
509
595
|
|
510
|
-
Amico.page_count(1, :following).should
|
511
|
-
Amico.page_count(1, :followers).should
|
512
|
-
Amico.page_count(1, :reciprocated).should
|
596
|
+
Amico.page_count(1, :following).should eql(1)
|
597
|
+
Amico.page_count(1, :followers).should eql(1)
|
598
|
+
Amico.page_count(1, :reciprocated).should eql(1)
|
513
599
|
|
514
600
|
Amico.redis.flushdb
|
515
601
|
add_reciprocal_followers(5, true)
|
516
602
|
|
517
|
-
Amico.page_count(1, :blocked).should
|
603
|
+
Amico.page_count(1, :blocked).should eql(1)
|
604
|
+
Amico.page_count(1, :blocked_by).should eql(1)
|
518
605
|
|
519
606
|
Amico.redis.flushdb
|
520
607
|
Amico.pending_follow = true
|
521
608
|
add_reciprocal_followers(5)
|
522
609
|
|
523
|
-
Amico.page_count(1, :pending).should
|
610
|
+
Amico.page_count(1, :pending).should eql(1)
|
524
611
|
end
|
525
612
|
end
|
526
613
|
|
614
|
+
|
615
|
+
|
616
|
+
describe '#clear' do
|
617
|
+
it 'should remove follower/following relationships' do
|
618
|
+
Amico.follow(1, 11)
|
619
|
+
Amico.follow(11, 1)
|
620
|
+
|
621
|
+
Amico.following_count(1).should be(1)
|
622
|
+
Amico.followers_count(1).should be(1)
|
623
|
+
Amico.reciprocated_count(1).should be(1)
|
624
|
+
Amico.following_count(11).should be(1)
|
625
|
+
Amico.followers_count(11).should be(1)
|
626
|
+
Amico.reciprocated_count(11).should be(1)
|
627
|
+
|
628
|
+
Amico.clear(1)
|
629
|
+
|
630
|
+
Amico.following_count(1).should be(0)
|
631
|
+
Amico.followers_count(1).should be(0)
|
632
|
+
Amico.reciprocated_count(1).should be(0)
|
633
|
+
Amico.following_count(11).should be(0)
|
634
|
+
Amico.followers_count(11).should be(0)
|
635
|
+
Amico.reciprocated_count(11).should be(0)
|
636
|
+
end
|
637
|
+
it 'should clear pending/pending_with relationships' do
|
638
|
+
Amico.pending_follow = true
|
639
|
+
Amico.follow(1, 11)
|
640
|
+
Amico.pending_count(11).should be(1)
|
641
|
+
Amico.clear(1)
|
642
|
+
Amico.pending_count(11).should be(0)
|
643
|
+
end
|
644
|
+
it 'should clear blocked/blocked_by relationships' do
|
645
|
+
Amico.block(1, 11)
|
646
|
+
Amico.blocked_count(1).should be(1)
|
647
|
+
Amico.blocked_by_count(11).should be(1)
|
648
|
+
Amico.clear(11)
|
649
|
+
Amico.blocked_count(1).should be(0)
|
650
|
+
Amico.blocked_by_count(11).should be(0)
|
651
|
+
end
|
652
|
+
end
|
653
|
+
|
654
|
+
|
527
655
|
private
|
528
656
|
|
529
657
|
def add_reciprocal_followers(count = 26, block_relationship = false)
|
data/spec/amico/version_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -15,8 +15,10 @@ RSpec.configure do |config|
|
|
15
15
|
configuration.following_key = 'following'
|
16
16
|
configuration.followers_key = 'followers'
|
17
17
|
configuration.blocked_key = 'blocked'
|
18
|
+
configuration.blocked_by_key = 'blocked_by'
|
18
19
|
configuration.reciprocated_key = 'reciprocated'
|
19
20
|
configuration.pending_key = 'pending'
|
21
|
+
configuration.pending_with_key = 'pending_with'
|
20
22
|
configuration.default_scope_key = 'default'
|
21
23
|
configuration.pending_follow = false
|
22
24
|
configuration.page_size = 25
|
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.
|
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-
|
12
|
+
date: 2012-08-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
@@ -95,12 +95,18 @@ 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
|
98
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
102
|
none: false
|
100
103
|
requirements:
|
101
104
|
- - ! '>='
|
102
105
|
- !ruby/object:Gem::Version
|
103
106
|
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 1949101995631561364
|
104
110
|
requirements: []
|
105
111
|
rubyforge_project: amico
|
106
112
|
rubygems_version: 1.8.24
|