amico 1.2.0 → 2.0.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/.rvmrc +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +209 -0
- data/lib/amico/configuration.rb +11 -0
- data/lib/amico/relationships.rb +104 -79
- data/lib/amico/version.rb +1 -1
- data/spec/amico/configuration_spec.rb +1 -0
- data/spec/amico/relationships_spec.rb +46 -31
- metadata +10 -10
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm use --create ruby-1.9.3
|
1
|
+
rvm use --create ruby-1.9.3@amico_gem
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,7 @@ Amico.configure do |configuration|
|
|
28
28
|
configuration.blocked_key = 'blocked'
|
29
29
|
configuration.reciprocated_key = 'reciprocated'
|
30
30
|
configuration.pending_key = 'pending'
|
31
|
+
configuration.default_scope_key = 'default'
|
31
32
|
configuration.pending_follow = false
|
32
33
|
configuration.page_size = 25
|
33
34
|
end
|
@@ -47,6 +48,7 @@ Amico.configure do |configuration|
|
|
47
48
|
configuration.blocked_key = 'blocked'
|
48
49
|
configuration.reciprocated_key = 'reciprocated'
|
49
50
|
configuration.pending_key = 'pending'
|
51
|
+
configuration.default_scope_key = 'default'
|
50
52
|
configuration.pending_follow = false
|
51
53
|
configuration.page_size = 25
|
52
54
|
end
|
@@ -129,6 +131,7 @@ Amico.configure do |configuration|
|
|
129
131
|
configuration.blocked_key = 'blocked'
|
130
132
|
configuration.reciprocated_key = 'reciprocated'
|
131
133
|
configuration.pending_key = 'pending'
|
134
|
+
configuration.default_scope_key = 'default'
|
132
135
|
configuration.pending_follow = true
|
133
136
|
configuration.page_size = 25
|
134
137
|
end
|
@@ -191,11 +194,217 @@ Amico.reciprocated?(1, 11)
|
|
191
194
|
=> true
|
192
195
|
```
|
193
196
|
|
197
|
+
Use amico with nicknames instead of IDs. NOTE: This could cause you much hardship later on if you allow nicknames to change.
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
require 'amico'
|
201
|
+
|
202
|
+
Amico.configure do |configuration|
|
203
|
+
configuration.redis = Redis.new
|
204
|
+
configuration.namespace = 'amico'
|
205
|
+
configuration.following_key = 'following'
|
206
|
+
configuration.followers_key = 'followers'
|
207
|
+
configuration.blocked_key = 'blocked'
|
208
|
+
configuration.reciprocated_key = 'reciprocated'
|
209
|
+
configuration.pending_key = 'pending'
|
210
|
+
configuration.default_scope_key = 'default'
|
211
|
+
configuration.pending_follow = false
|
212
|
+
configuration.page_size = 25
|
213
|
+
end
|
214
|
+
|
215
|
+
Amico.follow('bob', 'jane')
|
216
|
+
|
217
|
+
Amico.following?('bob', 'jane')
|
218
|
+
=> true
|
219
|
+
|
220
|
+
Amico.following?('jane', 'bob')
|
221
|
+
=> false
|
222
|
+
|
223
|
+
Amico.follow('jane', 'bob')
|
224
|
+
|
225
|
+
Amico.following?('jane', 'bob')
|
226
|
+
=> true
|
227
|
+
|
228
|
+
Amico.following_count('bob')
|
229
|
+
=> 1
|
230
|
+
|
231
|
+
Amico.followers_count('bob')
|
232
|
+
=> 1
|
233
|
+
|
234
|
+
Amico.unfollow('jane', 'bob')
|
235
|
+
|
236
|
+
Amico.following_count('jane')
|
237
|
+
=> 0
|
238
|
+
|
239
|
+
Amico.following_count('bob')
|
240
|
+
=> 1
|
241
|
+
|
242
|
+
Amico.follower?('bob', 'jane')
|
243
|
+
=> false
|
244
|
+
|
245
|
+
Amico.follower?('jane', 'bob')
|
246
|
+
=> true
|
247
|
+
|
248
|
+
Amico.following('bob')
|
249
|
+
=> ["jane"]
|
250
|
+
|
251
|
+
Amico.block('bob', 'jane')
|
252
|
+
|
253
|
+
Amico.following?('jane', 'bob')
|
254
|
+
=> false
|
255
|
+
|
256
|
+
Amico.blocked?('bob', 'jane')
|
257
|
+
=> true
|
258
|
+
|
259
|
+
Amico.blocked?('jane', 'bob')
|
260
|
+
=> false
|
261
|
+
|
262
|
+
Amico.unblock('bob', 'jane')
|
263
|
+
=> true
|
264
|
+
|
265
|
+
mico.blocked?('bob', 'jane')
|
266
|
+
=> false
|
267
|
+
|
268
|
+
Amico.following?('jane', 'bob')
|
269
|
+
=> false
|
270
|
+
|
271
|
+
Amico.follow('jane', 'bob')
|
272
|
+
=> nil
|
273
|
+
|
274
|
+
Amico.follow('bob', 'jane')
|
275
|
+
=> [1, 1]
|
276
|
+
|
277
|
+
Amico.reciprocated?('bob', 'jane')
|
278
|
+
=> true
|
279
|
+
|
280
|
+
Amico.reciprocated('bob')
|
281
|
+
=> ["jane"]
|
282
|
+
```
|
283
|
+
|
284
|
+
Use amico with nicknames instead of IDs and pending follows. NOTE: This could cause you much hardship later on if you allow nicknames to change.
|
285
|
+
|
286
|
+
```ruby
|
287
|
+
require 'amico'
|
288
|
+
=> true
|
289
|
+
|
290
|
+
Amico.configure do |configuration|
|
291
|
+
configuration.redis = Redis.new
|
292
|
+
configuration.namespace = 'amico'
|
293
|
+
configuration.following_key = 'following'
|
294
|
+
configuration.followers_key = 'followers'
|
295
|
+
configuration.blocked_key = 'blocked'
|
296
|
+
configuration.reciprocated_key = 'reciprocated'
|
297
|
+
configuration.pending_key = 'pending'
|
298
|
+
configuration.default_scope_key = 'default'
|
299
|
+
configuration.pending_follow = true
|
300
|
+
configuration.page_size = 25
|
301
|
+
end
|
302
|
+
|
303
|
+
Amico.follow('bob', 'jane')
|
304
|
+
|
305
|
+
Amico.follow('jane', 'bob')
|
306
|
+
|
307
|
+
Amico.pending?('bob', 'jane')
|
308
|
+
=> true
|
309
|
+
|
310
|
+
Amico.pending?('jane', 'bob')
|
311
|
+
=> true
|
312
|
+
|
313
|
+
Amico.accept('bob', 'jane')
|
314
|
+
|
315
|
+
Amico.pending?('bob', 'jane')
|
316
|
+
=> false
|
317
|
+
|
318
|
+
Amico.pending?('jane', 'bob')
|
319
|
+
=> true
|
320
|
+
|
321
|
+
Amico.following?('bob', 'jane')
|
322
|
+
=> true
|
323
|
+
|
324
|
+
Amico.following?('jane', 'bob')
|
325
|
+
=> false
|
326
|
+
|
327
|
+
Amico.follower?('jane', 'bob')
|
328
|
+
=> true
|
329
|
+
|
330
|
+
Amico.follower?('bob', 'jane')
|
331
|
+
=> false
|
332
|
+
|
333
|
+
Amico.accept('jane', 'bob')
|
334
|
+
|
335
|
+
Amico.pending?('bob', 'jane')
|
336
|
+
=> false
|
337
|
+
|
338
|
+
Amico.pending?('jane', 'bob')
|
339
|
+
=> false
|
340
|
+
|
341
|
+
Amico.following?('bob', 'jane')
|
342
|
+
=> true
|
343
|
+
|
344
|
+
Amico.following?('jane', 'bob')
|
345
|
+
=> true
|
346
|
+
|
347
|
+
Amico.follower?('jane', 'bob')
|
348
|
+
=> true
|
349
|
+
|
350
|
+
Amico.follower?('bob', 'jane')
|
351
|
+
=> true
|
352
|
+
|
353
|
+
Amico.reciprocated?('bob', 'jane')
|
354
|
+
=> true
|
355
|
+
```
|
356
|
+
|
357
|
+
All of the calls support a `scope` parameter to allow you to scope the calls to express relationships for different types of things. For example:
|
358
|
+
|
359
|
+
```ruby
|
360
|
+
require 'amico'
|
361
|
+
|
362
|
+
Amico.configure do |configuration|
|
363
|
+
configuration.redis = Redis.new
|
364
|
+
configuration.namespace = 'amico'
|
365
|
+
configuration.following_key = 'following'
|
366
|
+
configuration.followers_key = 'followers'
|
367
|
+
configuration.blocked_key = 'blocked'
|
368
|
+
configuration.reciprocated_key = 'reciprocated'
|
369
|
+
configuration.pending_key = 'pending'
|
370
|
+
configuration.default_scope_key = 'user'
|
371
|
+
configuration.pending_follow = false
|
372
|
+
configuration.page_size = 25
|
373
|
+
end
|
374
|
+
|
375
|
+
Amico.follow(1, 11)
|
376
|
+
|
377
|
+
Amico.following?(1, 11)
|
378
|
+
=> true
|
379
|
+
|
380
|
+
Amico.following?(1, 11, 'user')
|
381
|
+
=> true
|
382
|
+
|
383
|
+
Amico.following(1)
|
384
|
+
=> ["11"]
|
385
|
+
|
386
|
+
Amico.following(1, Amico.default_options, 'user')
|
387
|
+
=> ["11"]
|
388
|
+
|
389
|
+
Amico.following?(1, 11, 'project')
|
390
|
+
=> false
|
391
|
+
|
392
|
+
Amico.follow(1, 11, 'project')
|
393
|
+
|
394
|
+
Amico.following?(1, 11, 'project')
|
395
|
+
=> true
|
396
|
+
|
397
|
+
Amico.following(1, Amico.default_options, 'project')
|
398
|
+
=> ["11"]
|
399
|
+
```
|
400
|
+
|
194
401
|
## Documentation
|
195
402
|
|
196
403
|
The source for the [relationships module](https://github.com/agoragames/amico/blob/master/lib/amico/relationships.rb) is well-documented. There are some
|
197
404
|
simple examples in the method documentation. You can also refer to the [online documentation](http://rubydoc.info/github/agoragames/amico/master/frames).
|
198
405
|
|
406
|
+
## Future Plans
|
407
|
+
|
199
408
|
## FAQ?
|
200
409
|
|
201
410
|
### Why use Redis sorted sets and not Redis sets?
|
data/lib/amico/configuration.rb
CHANGED
@@ -25,6 +25,9 @@ module Amico
|
|
25
25
|
# Key used to indicate whether or not a follow should be pending or not.
|
26
26
|
attr_writer :pending_follow
|
27
27
|
|
28
|
+
# Default key used to indicate the scope for the current call
|
29
|
+
attr_writer :default_scope_key
|
30
|
+
|
28
31
|
# Page size to be used when paging through the various types of relationships.
|
29
32
|
attr_writer :page_size
|
30
33
|
|
@@ -40,6 +43,7 @@ module Amico
|
|
40
43
|
# configuration.blocked_key = 'blocked'
|
41
44
|
# configuration.reciprocated_key = 'reciprocated'
|
42
45
|
# configuration.pending_key = 'pending'
|
46
|
+
# configuration.default_scope_key = 'default'
|
43
47
|
# configuration.pending_follow = false
|
44
48
|
# configuration.page_size = 25
|
45
49
|
# end
|
@@ -89,6 +93,13 @@ module Amico
|
|
89
93
|
@pending_key ||= 'pending'
|
90
94
|
end
|
91
95
|
|
96
|
+
# Default key used in Redis for tracking scope for the given relationship calls.
|
97
|
+
#
|
98
|
+
# @return the default key used in Redis for tracking scope for the given relationship calls.
|
99
|
+
def default_scope_key
|
100
|
+
@default_scope_key ||= 'default'
|
101
|
+
end
|
102
|
+
|
92
103
|
# Key used to indicate whether or not a follow should be pending or not.
|
93
104
|
#
|
94
105
|
# @return the key used to indicate whether or not a follow should be pending or not.
|
data/lib/amico/relationships.rb
CHANGED
@@ -5,20 +5,21 @@ module Amico
|
|
5
5
|
# relationship if so.
|
6
6
|
#
|
7
7
|
# @param from_id [String] The ID of the individual establishing the follow relationship.
|
8
|
-
# @param to_id [String] The ID of the individual to be followed.
|
8
|
+
# @param to_id [String] The ID of the individual to be followed.
|
9
|
+
# @param scope [String] Scope for the call
|
9
10
|
#
|
10
11
|
# Examples
|
11
12
|
#
|
12
13
|
# Amico.follow(1, 11)
|
13
|
-
def follow(from_id, to_id)
|
14
|
+
def follow(from_id, to_id, scope = Amico.default_scope_key)
|
14
15
|
return if from_id == to_id
|
15
|
-
return if blocked?(to_id, from_id)
|
16
|
-
return if Amico.pending_follow && pending?(from_id, to_id)
|
16
|
+
return if blocked?(to_id, from_id, scope)
|
17
|
+
return if Amico.pending_follow && pending?(from_id, to_id, scope)
|
17
18
|
|
18
19
|
unless Amico.pending_follow
|
19
|
-
add_following_followers_reciprocated(from_id, to_id)
|
20
|
+
add_following_followers_reciprocated(from_id, to_id, scope)
|
20
21
|
else
|
21
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{to_id}", Time.now.to_i, from_id)
|
22
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
@@ -28,20 +29,21 @@ module Amico
|
|
28
29
|
#
|
29
30
|
# @param from_id [String] The ID of the individual removing the follow relationship.
|
30
31
|
# @param to_id [String] The ID of the individual to be unfollowed.
|
32
|
+
# @param scope [String] Scope for the call
|
31
33
|
#
|
32
34
|
# Examples
|
33
35
|
#
|
34
36
|
# Amico.follow(1, 11)
|
35
37
|
# Amico.unfollow(1, 11)
|
36
|
-
def unfollow(from_id, to_id)
|
38
|
+
def unfollow(from_id, to_id, scope = Amico.default_scope_key)
|
37
39
|
return if from_id == to_id
|
38
40
|
|
39
41
|
Amico.redis.multi do
|
40
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{from_id}", to_id)
|
41
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{to_id}", from_id)
|
42
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{from_id}", to_id)
|
43
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{to_id}", from_id)
|
44
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{to_id}", from_id)
|
42
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
|
43
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
|
44
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
|
45
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
|
46
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
@@ -50,22 +52,23 @@ module Amico
|
|
50
52
|
#
|
51
53
|
# @param from_id [String] The ID of the individual blocking the relationship.
|
52
54
|
# @param to_id [String] The ID of the individual being blocked.
|
55
|
+
# @param scope [String] Scope for the call
|
53
56
|
#
|
54
57
|
# Examples
|
55
58
|
#
|
56
59
|
# Amico.block(1, 11)
|
57
|
-
def block(from_id, to_id)
|
60
|
+
def block(from_id, to_id, scope = Amico.default_scope_key)
|
58
61
|
return if from_id == to_id
|
59
62
|
|
60
63
|
Amico.redis.multi do
|
61
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{from_id}", to_id)
|
62
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{to_id}", from_id)
|
63
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{to_id}", from_id)
|
64
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{from_id}", to_id)
|
65
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{from_id}", to_id)
|
66
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{to_id}", from_id)
|
67
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{from_id}", to_id)
|
68
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{from_id}", Time.now.to_i, to_id)
|
64
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", to_id)
|
65
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{to_id}", from_id)
|
66
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", from_id)
|
67
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{from_id}", to_id)
|
68
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", to_id)
|
69
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", from_id)
|
70
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{from_id}", to_id)
|
71
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
@@ -73,21 +76,23 @@ module Amico
|
|
73
76
|
#
|
74
77
|
# @param from_id [String] The ID of the individual unblocking the relationship.
|
75
78
|
# @param to_id [String] The ID of the blocked individual.
|
79
|
+
# @param scope [String] Scope for the call
|
76
80
|
#
|
77
81
|
# Examples
|
78
82
|
#
|
79
83
|
# Amico.block(1, 11)
|
80
84
|
# Amico.unblock(1, 11)
|
81
|
-
def unblock(from_id, to_id)
|
85
|
+
def unblock(from_id, to_id, scope = Amico.default_scope_key)
|
82
86
|
return if from_id == to_id
|
83
87
|
|
84
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.blocked_key}:#{from_id}", to_id)
|
88
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{from_id}", to_id)
|
85
89
|
end
|
86
90
|
|
87
91
|
# Accept a relationship that is pending between two IDs.
|
88
92
|
#
|
89
93
|
# @param from_id [String] The ID of the individual accepting the relationship.
|
90
94
|
# @param to_id [String] The ID of the individual to be accepted.
|
95
|
+
# @param scope [String] Scope for the call
|
91
96
|
#
|
92
97
|
# Example
|
93
98
|
#
|
@@ -96,15 +101,16 @@ module Amico
|
|
96
101
|
# Amico.accept(1, 11)
|
97
102
|
# Amico.pending?(1, 11) # false
|
98
103
|
# Amico.following?(1, 11) #true
|
99
|
-
def accept(from_id, to_id)
|
104
|
+
def accept(from_id, to_id, scope = Amico.default_scope_key)
|
100
105
|
return if from_id == to_id
|
101
106
|
|
102
|
-
add_following_followers_reciprocated(from_id, to_id)
|
107
|
+
add_following_followers_reciprocated(from_id, to_id, scope)
|
103
108
|
end
|
104
109
|
|
105
110
|
# Count the number of individuals that someone is following.
|
106
111
|
#
|
107
112
|
# @param id [String] ID of the individual to retrieve following count for.
|
113
|
+
# @param scope [String] Scope for the call
|
108
114
|
#
|
109
115
|
# Examples
|
110
116
|
#
|
@@ -112,13 +118,14 @@ module Amico
|
|
112
118
|
# Amico.following_count(1)
|
113
119
|
#
|
114
120
|
# @return the count of the number of individuals that someone is following.
|
115
|
-
def following_count(id)
|
116
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{id}")
|
121
|
+
def following_count(id, scope = Amico.default_scope_key)
|
122
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}")
|
117
123
|
end
|
118
124
|
|
119
125
|
# Count the number of individuals that are following someone.
|
120
126
|
#
|
121
127
|
# @param id [String] ID of the individual to retrieve followers count for.
|
128
|
+
# @param scope [String] Scope for the call
|
122
129
|
#
|
123
130
|
# Examples
|
124
131
|
#
|
@@ -126,13 +133,14 @@ module Amico
|
|
126
133
|
# Amico.followers_count(1)
|
127
134
|
#
|
128
135
|
# @return the count of the number of individuals that are following someone.
|
129
|
-
def followers_count(id)
|
130
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{id}")
|
136
|
+
def followers_count(id, scope = Amico.default_scope_key)
|
137
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}")
|
131
138
|
end
|
132
139
|
|
133
140
|
# Count the number of individuals that someone has blocked.
|
134
141
|
#
|
135
142
|
# @param id [String] ID of the individual to retrieve blocked count for.
|
143
|
+
# @param scope [String] Scope for the call
|
136
144
|
#
|
137
145
|
# Examples
|
138
146
|
#
|
@@ -140,13 +148,14 @@ module Amico
|
|
140
148
|
# Amico.blocked_count(1)
|
141
149
|
#
|
142
150
|
# @return the count of the number of individuals that someone has blocked.
|
143
|
-
def blocked_count(id)
|
144
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{id}")
|
151
|
+
def blocked_count(id, scope = Amico.default_scope_key)
|
152
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}")
|
145
153
|
end
|
146
154
|
|
147
155
|
# Count the number of individuals that have reciprocated a following relationship.
|
148
156
|
#
|
149
157
|
# @param id [String] ID of the individual to retrieve reciprocated following count for.
|
158
|
+
# @param scope [String] Scope for the call
|
150
159
|
#
|
151
160
|
# Examples
|
152
161
|
#
|
@@ -155,13 +164,14 @@ module Amico
|
|
155
164
|
# Amico.reciprocated_count(1)
|
156
165
|
#
|
157
166
|
# @return the count of the number of individuals that have reciprocated a following relationship.
|
158
|
-
def reciprocated_count(id)
|
159
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{id}")
|
167
|
+
def reciprocated_count(id, scope = Amico.default_scope_key)
|
168
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}")
|
160
169
|
end
|
161
170
|
|
162
171
|
# Count the number of relationships pending for an individual.
|
163
172
|
#
|
164
173
|
# @param id [String] ID of the individual to retrieve pending count for.
|
174
|
+
# @param scope [String] Scope for the call
|
165
175
|
#
|
166
176
|
# Examples
|
167
177
|
#
|
@@ -170,14 +180,15 @@ module Amico
|
|
170
180
|
# Amico.pending_count(1) # 2
|
171
181
|
#
|
172
182
|
# @return the count of the number of relationships pending for an individual.
|
173
|
-
def pending_count(id)
|
174
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{id}")
|
183
|
+
def pending_count(id, scope = Amico.default_scope_key)
|
184
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}")
|
175
185
|
end
|
176
186
|
|
177
187
|
# Check to see if one individual is following another individual.
|
178
188
|
#
|
179
189
|
# @param id [String] ID of the individual checking the following status.
|
180
190
|
# @param following_id [String] ID of the individual to see if they are being followed by id.
|
191
|
+
# @param scope [String] Scope for the call
|
181
192
|
#
|
182
193
|
# Examples
|
183
194
|
#
|
@@ -185,14 +196,15 @@ module Amico
|
|
185
196
|
# Amico.following?(1, 11)
|
186
197
|
#
|
187
198
|
# @return true if id is following following_id, false otherwise
|
188
|
-
def following?(id, following_id)
|
189
|
-
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.following_key}:#{id}", following_id).nil?
|
199
|
+
def following?(id, following_id, scope = Amico.default_scope_key)
|
200
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", following_id).nil?
|
190
201
|
end
|
191
202
|
|
192
203
|
# Check to see if one individual is a follower of another individual.
|
193
204
|
#
|
194
205
|
# @param id [String] ID of the individual checking the follower status.
|
195
206
|
# @param following_id [String] ID of the individual to see if they are following id.
|
207
|
+
# @param scope [String] Scope for the call
|
196
208
|
#
|
197
209
|
# Examples
|
198
210
|
#
|
@@ -200,14 +212,15 @@ module Amico
|
|
200
212
|
# Amico.follower?(1, 11)
|
201
213
|
#
|
202
214
|
# @return true if follower_id is following id, false otherwise
|
203
|
-
def follower?(id, follower_id)
|
204
|
-
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.followers_key}:#{id}", follower_id).nil?
|
215
|
+
def follower?(id, follower_id, scope = Amico.default_scope_key)
|
216
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", follower_id).nil?
|
205
217
|
end
|
206
218
|
|
207
219
|
# Check to see if one individual has blocked another individual.
|
208
220
|
#
|
209
221
|
# @param id [String] ID of the individual checking the blocked status.
|
210
222
|
# @param blocked_id [String] ID of the individual to see if they are blocked by id.
|
223
|
+
# @param scope [String] Scope for the call
|
211
224
|
#
|
212
225
|
# Examples
|
213
226
|
#
|
@@ -215,14 +228,15 @@ module Amico
|
|
215
228
|
# Amico.blocked?(1, 11)
|
216
229
|
#
|
217
230
|
# @return true if id has blocked blocked_id, false otherwise
|
218
|
-
def blocked?(id, blocked_id)
|
219
|
-
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{id}", blocked_id).nil?
|
231
|
+
def blocked?(id, blocked_id, scope = Amico.default_scope_key)
|
232
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", blocked_id).nil?
|
220
233
|
end
|
221
234
|
|
222
235
|
# Check to see if one individual has reciprocated in following another individual.
|
223
236
|
#
|
224
237
|
# @param from_id [String] ID of the individual checking the reciprocated relationship.
|
225
238
|
# @param to_id [String] ID of the individual to see if they are following from_id.
|
239
|
+
# @param scope [String] Scope for the call
|
226
240
|
#
|
227
241
|
# Examples
|
228
242
|
#
|
@@ -231,14 +245,15 @@ module Amico
|
|
231
245
|
# Amico.reciprocated?(1, 11)
|
232
246
|
#
|
233
247
|
# @return true if both individuals are following each other, false otherwise
|
234
|
-
def reciprocated?(from_id, to_id)
|
235
|
-
following?(from_id, to_id) && following?(to_id, from_id)
|
248
|
+
def reciprocated?(from_id, to_id, scope = Amico.default_scope_key)
|
249
|
+
following?(from_id, to_id, scope) && following?(to_id, from_id, scope)
|
236
250
|
end
|
237
251
|
|
238
252
|
# Check to see if one individual has a pending relationship in following another individual.
|
239
253
|
#
|
240
254
|
# @param from_id [String] ID of the individual checking the pending relationships.
|
241
255
|
# @param to_id [String] ID of the individual to see if they are pending a follow from from_id.
|
256
|
+
# @param scope [String] Scope for the call
|
242
257
|
#
|
243
258
|
# Examples
|
244
259
|
#
|
@@ -246,14 +261,15 @@ module Amico
|
|
246
261
|
# Amico.pending?(1, 11) # true
|
247
262
|
#
|
248
263
|
# @return true if the relationship is pending, false otherwise
|
249
|
-
def pending?(from_id, to_id)
|
250
|
-
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_key}:#{to_id}", from_id).nil?
|
264
|
+
def pending?(from_id, to_id, scope = Amico.default_scope_key)
|
265
|
+
!Amico.redis.zscore("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id).nil?
|
251
266
|
end
|
252
267
|
|
253
268
|
# Retrieve a page of followed individuals for a given ID.
|
254
269
|
#
|
255
270
|
# @param id [String] ID of the individual.
|
256
271
|
# @param options [Hash] Options to be passed for retrieving a page of followed individuals.
|
272
|
+
# @param scope [String] Scope for the call
|
257
273
|
#
|
258
274
|
# Examples
|
259
275
|
#
|
@@ -262,14 +278,15 @@ module Amico
|
|
262
278
|
# Amico.following(1, :page => 1)
|
263
279
|
#
|
264
280
|
# @return a page of followed individuals for a given ID.
|
265
|
-
def following(id, options = default_options)
|
266
|
-
members("#{Amico.namespace}:#{Amico.following_key}:#{id}", options)
|
281
|
+
def following(id, options = default_options, scope = Amico.default_scope_key)
|
282
|
+
members("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", options)
|
267
283
|
end
|
268
284
|
|
269
285
|
# Retrieve a page of followers for a given ID.
|
270
286
|
#
|
271
287
|
# @param id [String] ID of the individual.
|
272
288
|
# @param options [Hash] Options to be passed for retrieving a page of followers.
|
289
|
+
# @param scope [String] Scope for the call
|
273
290
|
#
|
274
291
|
# Examples
|
275
292
|
#
|
@@ -278,14 +295,15 @@ module Amico
|
|
278
295
|
# Amico.followers(1, :page => 1)
|
279
296
|
#
|
280
297
|
# @return a page of followers for a given ID.
|
281
|
-
def followers(id, options = default_options)
|
282
|
-
members("#{Amico.namespace}:#{Amico.followers_key}:#{id}", options)
|
298
|
+
def followers(id, options = default_options, scope = Amico.default_scope_key)
|
299
|
+
members("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", options)
|
283
300
|
end
|
284
301
|
|
285
302
|
# Retrieve a page of blocked individuals for a given ID.
|
286
303
|
#
|
287
304
|
# @param id [String] ID of the individual.
|
288
305
|
# @param options [Hash] Options to be passed for retrieving a page of blocked individuals.
|
306
|
+
# @param scope [String] Scope for the call
|
289
307
|
#
|
290
308
|
# Examples
|
291
309
|
#
|
@@ -294,14 +312,15 @@ module Amico
|
|
294
312
|
# Amico.blocked(1, :page => 1)
|
295
313
|
#
|
296
314
|
# @return a page of blocked individuals for a given ID.
|
297
|
-
def blocked(id, options = default_options)
|
298
|
-
members("#{Amico.namespace}:#{Amico.blocked_key}:#{id}", options)
|
315
|
+
def blocked(id, options = default_options, scope = Amico.default_scope_key)
|
316
|
+
members("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", options)
|
299
317
|
end
|
300
318
|
|
301
319
|
# Retrieve a page of individuals that have reciprocated a follow for a given ID.
|
302
320
|
#
|
303
321
|
# @param id [String] ID of the individual.
|
304
322
|
# @param options [Hash] Options to be passed for retrieving a page of individuals that have reciprocated a follow.
|
323
|
+
# @param scope [String] Scope for the call
|
305
324
|
#
|
306
325
|
# Examples
|
307
326
|
#
|
@@ -312,14 +331,15 @@ module Amico
|
|
312
331
|
# Amico.reciprocated(1, :page => 1)
|
313
332
|
#
|
314
333
|
# @return a page of individuals that have reciprocated a follow for a given ID.
|
315
|
-
def reciprocated(id, options = default_options)
|
316
|
-
members("#{Amico.namespace}:#{Amico.reciprocated_key}:#{id}", options)
|
334
|
+
def reciprocated(id, options = default_options, scope = Amico.default_scope_key)
|
335
|
+
members("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", options)
|
317
336
|
end
|
318
337
|
|
319
338
|
# Retrieve a page of pending relationships for a given ID.
|
320
339
|
#
|
321
340
|
# @param id [String] ID of the individual.
|
322
341
|
# @param options [Hash] Options to be passed for retrieving a page of pending relationships.
|
342
|
+
# @param scope [String] Scope for the call
|
323
343
|
#
|
324
344
|
# Examples
|
325
345
|
#
|
@@ -328,14 +348,15 @@ module Amico
|
|
328
348
|
# Amico.pending(1, :page => 1)
|
329
349
|
#
|
330
350
|
# @return a page of pending relationships for a given ID.
|
331
|
-
def pending(id, options = default_options)
|
332
|
-
members("#{Amico.namespace}:#{Amico.pending_key}:#{id}", options)
|
351
|
+
def pending(id, options = default_options, scope = Amico.default_scope_key)
|
352
|
+
members("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", options)
|
333
353
|
end
|
334
354
|
|
335
355
|
# Count the number of pages of following relationships for an individual.
|
336
356
|
#
|
337
357
|
# @param id [String] ID of the individual.
|
338
358
|
# @param page_size [int] Page size.
|
359
|
+
# @param scope [String] Scope for the call
|
339
360
|
#
|
340
361
|
# Examples
|
341
362
|
#
|
@@ -344,14 +365,15 @@ module Amico
|
|
344
365
|
# Amico.following_page_count(1)
|
345
366
|
#
|
346
367
|
# @return the number of pages of following relationships for an individual.
|
347
|
-
def following_page_count(id, page_size = Amico.page_size)
|
348
|
-
total_pages("#{Amico.namespace}:#{Amico.following_key}:#{id}", page_size)
|
368
|
+
def following_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
369
|
+
total_pages("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{id}", page_size)
|
349
370
|
end
|
350
371
|
|
351
372
|
# Count the number of pages of follower relationships for an individual.
|
352
373
|
#
|
353
374
|
# @param id [String] ID of the individual.
|
354
375
|
# @param page_size [int] Page size (default: Amico.page_size).
|
376
|
+
# @param scope [String] Scope for the call
|
355
377
|
#
|
356
378
|
# Examples
|
357
379
|
#
|
@@ -360,14 +382,15 @@ module Amico
|
|
360
382
|
# Amico.followers_page_count(1)
|
361
383
|
#
|
362
384
|
# @return the number of pages of follower relationships for an individual.
|
363
|
-
def followers_page_count(id, page_size = Amico.page_size)
|
364
|
-
total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{id}", page_size)
|
385
|
+
def followers_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
386
|
+
total_pages("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{id}", page_size)
|
365
387
|
end
|
366
388
|
|
367
389
|
# Count the number of pages of blocked relationships for an individual.
|
368
390
|
#
|
369
391
|
# @param id [String] ID of the individual.
|
370
392
|
# @param page_size [int] Page size (default: Amico.page_size).
|
393
|
+
# @param scope [String] Scope for the call
|
371
394
|
#
|
372
395
|
# Examples
|
373
396
|
#
|
@@ -376,14 +399,15 @@ module Amico
|
|
376
399
|
# Amico.blocked_page_count(1)
|
377
400
|
#
|
378
401
|
# @return the number of pages of blocked relationships for an individual.
|
379
|
-
def blocked_page_count(id, page_size = Amico.page_size)
|
380
|
-
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{id}", page_size)
|
402
|
+
def blocked_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
403
|
+
total_pages("#{Amico.namespace}:#{Amico.blocked_key}:#{scope}:#{id}", page_size)
|
381
404
|
end
|
382
405
|
|
383
406
|
# Count the number of pages of reciprocated relationships for an individual.
|
384
407
|
#
|
385
408
|
# @param id [String] ID of the individual.
|
386
409
|
# @param page_size [int] Page size (default: Amico.page_size).
|
410
|
+
# @param scope [String] Scope for the call
|
387
411
|
#
|
388
412
|
# Examples
|
389
413
|
#
|
@@ -394,14 +418,15 @@ module Amico
|
|
394
418
|
# Amico.reciprocated_page_count(1)
|
395
419
|
#
|
396
420
|
# @return the number of pages of reciprocated relationships for an individual.
|
397
|
-
def reciprocated_page_count(id, page_size = Amico.page_size)
|
398
|
-
total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{id}", page_size)
|
421
|
+
def reciprocated_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
422
|
+
total_pages("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{id}", page_size)
|
399
423
|
end
|
400
424
|
|
401
425
|
# Count the number of pages of pending relationships for an individual.
|
402
426
|
#
|
403
427
|
# @param id [String] ID of the individual.
|
404
428
|
# @param page_size [int] Page size (default: Amico.page_size).
|
429
|
+
# @param scope [String] Scope for the call
|
405
430
|
#
|
406
431
|
# Examples
|
407
432
|
#
|
@@ -410,39 +435,39 @@ module Amico
|
|
410
435
|
# Amico.pending_page_count(1) # 1
|
411
436
|
#
|
412
437
|
# @return the number of pages of pending relationships for an individual.
|
413
|
-
def pending_page_count(id, page_size = Amico.page_size)
|
414
|
-
total_pages("#{Amico.namespace}:#{Amico.pending_key}:#{id}", page_size)
|
415
|
-
end
|
438
|
+
def pending_page_count(id, page_size = Amico.page_size, scope = Amico.default_scope_key)
|
439
|
+
total_pages("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{id}", page_size)
|
440
|
+
end
|
416
441
|
|
417
442
|
private
|
418
443
|
|
444
|
+
# Default options for doing, for example, paging.
|
445
|
+
#
|
446
|
+
# @return a hash of the default options.
|
447
|
+
def default_options
|
448
|
+
{:page_size => Amico.page_size, :page => 1}
|
449
|
+
end
|
450
|
+
|
419
451
|
# Add the following, followers and check for a reciprocated relationship. To be used from the
|
420
452
|
# +follow++ and ++accept++ methods.
|
421
453
|
#
|
422
454
|
# @param from_id [String] The ID of the individual establishing the follow relationship.
|
423
455
|
# @param to_id [String] The ID of the individual to be followed.
|
424
|
-
def add_following_followers_reciprocated(from_id, to_id)
|
456
|
+
def add_following_followers_reciprocated(from_id, to_id, scope)
|
425
457
|
Amico.redis.multi do
|
426
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{from_id}", Time.now.to_i, to_id)
|
427
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.followers_key}:#{to_id}", Time.now.to_i, from_id)
|
428
|
-
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{to_id}", from_id)
|
458
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.following_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
459
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.followers_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
460
|
+
Amico.redis.zrem("#{Amico.namespace}:#{Amico.pending_key}:#{scope}:#{to_id}", from_id)
|
429
461
|
end
|
430
462
|
|
431
463
|
if reciprocated?(from_id, to_id)
|
432
464
|
Amico.redis.multi do
|
433
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{from_id}", Time.now.to_i, to_id)
|
434
|
-
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{to_id}", Time.now.to_i, from_id)
|
465
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{from_id}", Time.now.to_i, to_id)
|
466
|
+
Amico.redis.zadd("#{Amico.namespace}:#{Amico.reciprocated_key}:#{scope}:#{to_id}", Time.now.to_i, from_id)
|
435
467
|
end
|
436
468
|
end
|
437
469
|
end
|
438
470
|
|
439
|
-
# Default options for doing, for example, paging.
|
440
|
-
#
|
441
|
-
# @return a hash of the default options.
|
442
|
-
def default_options
|
443
|
-
{:page_size => Amico.page_size, :page => 1}
|
444
|
-
end
|
445
|
-
|
446
471
|
# Count the total number of pages for a given key in a Redis sorted set.
|
447
472
|
#
|
448
473
|
# @param key [String] Redis key.
|
data/lib/amico/version.rb
CHANGED
@@ -10,6 +10,7 @@ describe Amico::Configuration do
|
|
10
10
|
configuration.blocked_key.should eql('blocked')
|
11
11
|
configuration.reciprocated_key.should eql('reciprocated')
|
12
12
|
configuration.pending_key.should eql('pending')
|
13
|
+
configuration.default_scope_key.should eql('default')
|
13
14
|
configuration.pending_follow.should be_false
|
14
15
|
configuration.page_size.should be(25)
|
15
16
|
end
|
@@ -5,23 +5,23 @@ describe Amico::Relationships do
|
|
5
5
|
it 'should allow you to follow' do
|
6
6
|
Amico.follow(1, 11)
|
7
7
|
|
8
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(1)
|
9
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(1)
|
8
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(1)
|
9
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(1)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should not allow you to follow yourself' do
|
13
13
|
Amico.follow(1, 1)
|
14
14
|
|
15
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(0)
|
16
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:1").should be(0)
|
15
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
16
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:1").should be(0)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should add each individual to the reciprocated set if you both follow each other' do
|
20
20
|
Amico.follow(1, 11)
|
21
21
|
Amico.follow(11, 1)
|
22
22
|
|
23
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:1").should be(1)
|
24
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:11").should be(1)
|
23
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:1").should be(1)
|
24
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:11").should be(1)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -29,15 +29,15 @@ describe Amico::Relationships do
|
|
29
29
|
it 'should allow you to unfollow' do
|
30
30
|
Amico.follow(1, 11)
|
31
31
|
|
32
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(1)
|
33
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(1)
|
32
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(1)
|
33
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(1)
|
34
34
|
|
35
35
|
Amico.unfollow(1, 11)
|
36
36
|
|
37
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(0)
|
38
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(0)
|
39
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:1").should be(0)
|
40
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:11").should be(0)
|
37
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
38
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
39
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:1").should be(0)
|
40
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:11").should be(0)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -46,29 +46,29 @@ 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}:11").should be(0)
|
50
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:1").should be(1)
|
51
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:1").should be(0)
|
52
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:11").should be(0)
|
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.reciprocated_key}:#{Amico.default_scope_key}:1").should be(0)
|
52
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.reciprocated_key}:#{Amico.default_scope_key}:11").should be(0)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'should allow you to block someone who is not following you' do
|
56
56
|
Amico.block(1, 11)
|
57
57
|
|
58
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:11").should be(0)
|
59
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:1").should be(1)
|
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)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should not allow someone you have blocked to follow you' do
|
63
63
|
Amico.block(1, 11)
|
64
64
|
|
65
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:11").should be(0)
|
66
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:1").should be(1)
|
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
67
|
|
68
68
|
Amico.follow(11, 1)
|
69
69
|
|
70
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:11").should be(0)
|
71
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.blocked_key}:1").should be(1)
|
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
72
|
end
|
73
73
|
|
74
74
|
it 'should not allow you to block yourself' do
|
@@ -282,23 +282,23 @@ describe Amico::Relationships do
|
|
282
282
|
it 'should allow you to follow but the relationship is initially pending' do
|
283
283
|
Amico.follow(1, 11)
|
284
284
|
|
285
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(0)
|
286
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(0)
|
287
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:11").should be(1)
|
285
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
286
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
287
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(1)
|
288
288
|
end
|
289
289
|
|
290
290
|
it 'should remove the pending relationship if you have a pending follow, but you unfollow' do
|
291
291
|
Amico.follow(1, 11)
|
292
292
|
|
293
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(0)
|
294
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(0)
|
295
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:11").should be(1)
|
293
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
294
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
295
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(1)
|
296
296
|
|
297
297
|
Amico.unfollow(1, 11)
|
298
298
|
|
299
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:1").should be(0)
|
300
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:11").should be(0)
|
301
|
-
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:11").should be(0)
|
299
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.following_key}:#{Amico.default_scope_key}:1").should be(0)
|
300
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.followers_key}:#{Amico.default_scope_key}:11").should be(0)
|
301
|
+
Amico.redis.zcard("#{Amico.namespace}:#{Amico.pending_key}:#{Amico.default_scope_key}:11").should be(0)
|
302
302
|
end
|
303
303
|
|
304
304
|
it 'should remove the pending relationship and add to following and followers if #accept is called' do
|
@@ -390,6 +390,21 @@ describe Amico::Relationships do
|
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
+
describe 'scope' do
|
394
|
+
it 'should allow you to scope a call to follow a different thing' do
|
395
|
+
Amico.default_scope_key = 'user'
|
396
|
+
Amico.follow(1, 11, 'user')
|
397
|
+
Amico.following?(1, 11).should be_true
|
398
|
+
Amico.following?(1, 11, 'user').should be_true
|
399
|
+
Amico.following(1).should eql(["11"])
|
400
|
+
Amico.following(1, {:page_size => Amico.page_size, :page => 1}, 'user').should eql(["11"])
|
401
|
+
Amico.following?(1, 11, 'project').should be_false
|
402
|
+
Amico.follow(1, 11, 'project')
|
403
|
+
Amico.following?(1, 11, 'project').should be_true
|
404
|
+
Amico.following(1, {:page_size => Amico.page_size, :page => 1}, 'project').should eql(["11"])
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
393
408
|
private
|
394
409
|
|
395
410
|
def add_reciprocal_followers(count = 26, block_relationship = false)
|
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:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153496040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153496040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153495620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153495620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153495200 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153495200
|
47
47
|
description: Relationships (e.g. friendships) backed by Redis
|
48
48
|
email:
|
49
49
|
- dczarnecki@agoragames.com
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
segments:
|
83
83
|
- 0
|
84
|
-
hash:
|
84
|
+
hash: 1543039261316922594
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: 1543039261316922594
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project: amico
|
96
96
|
rubygems_version: 1.8.10
|