Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 436 lines (306 sloc) 8.895 kb
10177dc @czarneckid Documentation
czarneckid authored
1 # amico
2
fff5d4b @czarneckid Removing in ruby. Duh.
czarneckid authored
3 Relationships (e.g. friendships) backed by Redis.
10177dc @czarneckid Documentation
czarneckid authored
4
5 ## Installation
6
7 `gem install amico`
8
9 or in your `Gemfile`
10
11 ```ruby
12 gem 'amico'
13 ```
14
15 Make sure your redis server is running! Redis configuration is outside the scope of this README, but
16 check out the Redis documentation, http://redis.io/documentation.
17
18 ## Usage
19
20 Configure amico:
21
22 ```ruby
23 Amico.configure do |configuration|
24 configuration.redis = Redis.new
25 configuration.namespace = 'amico'
26 configuration.following_key = 'following'
27 configuration.followers_key = 'followers'
909e0d5 @czarneckid Recpirocated
czarneckid authored
28 configuration.blocked_key = 'blocked'
29 configuration.reciprocated_key = 'reciprocated'
0754c24 @czarneckid Pending relationships
czarneckid authored
30 configuration.pending_key = 'pending'
0a7c8fd @czarneckid Scoping
czarneckid authored
31 configuration.default_scope_key = 'default'
0754c24 @czarneckid Pending relationships
czarneckid authored
32 configuration.pending_follow = false
645bb98 @czarneckid Updating README
czarneckid authored
33 configuration.page_size = 25
10177dc @czarneckid Documentation
czarneckid authored
34 end
35 ```
36
e02f89c @czarneckid Updating README
czarneckid authored
37 Use amico:
38
10177dc @czarneckid Documentation
czarneckid authored
39 ```ruby
40 require 'amico'
41 => true
e02f89c @czarneckid Updating README
czarneckid authored
42
10177dc @czarneckid Documentation
czarneckid authored
43 Amico.configure do |configuration|
44 configuration.redis = Redis.new
45 configuration.namespace = 'amico'
46 configuration.following_key = 'following'
47 configuration.followers_key = 'followers'
909e0d5 @czarneckid Recpirocated
czarneckid authored
48 configuration.blocked_key = 'blocked'
49 configuration.reciprocated_key = 'reciprocated'
0754c24 @czarneckid Pending relationships
czarneckid authored
50 configuration.pending_key = 'pending'
0a7c8fd @czarneckid Scoping
czarneckid authored
51 configuration.default_scope_key = 'default'
0754c24 @czarneckid Pending relationships
czarneckid authored
52 configuration.pending_follow = false
00259be @czarneckid Updating README
czarneckid authored
53 configuration.page_size = 25
10177dc @czarneckid Documentation
czarneckid authored
54 end
55
56 Amico.follow(1, 11)
57 => [1, 1]
58
59 Amico.following?(1, 11)
60 => true
61
62 Amico.following?(11, 1)
63 => false
64
65 Amico.follow(11, 1)
66 => [1, 1]
67
68 Amico.following?(11, 1)
69 => true
70
71 Amico.following_count(1)
72 => 1
73
74 Amico.followers_count(1)
75 => 1
76
77 Amico.unfollow(11, 1)
78 => [1, 1]
79
80 Amico.following_count(11)
81 => 0
82
83 Amico.following_count(1)
84 => 1
85
86 Amico.follower?(1, 11)
00259be @czarneckid Updating README
czarneckid authored
87 => false
88
89 Amico.following(1)
90 => ["11"]
8a511c9 @czarneckid Blocking
czarneckid authored
91
92 Amico.block(1, 11)
93 => [1, 1, 1, 1, 1]
94
95 Amico.following?(11, 1)
96 => false
97
98 Amico.blocked?(1, 11)
99 => true
909e0d5 @czarneckid Recpirocated
czarneckid authored
100
101 Amico.unblock(1, 11)
102 => true
103
104 Amico.blocked?(1, 11)
105 => false
106
107 Amico.follow(11, 1)
108 => nil
109
110 Amico.follow(1, 11)
111 => [1, 1]
112
113 Amico.reciprocated?(1, 11)
114 => true
115
116 Amico.reciprocated(1)
117 => ["11"]
10177dc @czarneckid Documentation
czarneckid authored
118 ```
2198d80 @czarneckid Page count
czarneckid authored
119
0754c24 @czarneckid Pending relationships
czarneckid authored
120 Use amico (with pending relationships for follow):
121
122 ```ruby
123 require 'amico'
124 => true
125
126 Amico.configure do |configuration|
127 configuration.redis = Redis.new
128 configuration.namespace = 'amico'
129 configuration.following_key = 'following'
130 configuration.followers_key = 'followers'
131 configuration.blocked_key = 'blocked'
132 configuration.reciprocated_key = 'reciprocated'
133 configuration.pending_key = 'pending'
0a7c8fd @czarneckid Scoping
czarneckid authored
134 configuration.default_scope_key = 'default'
0754c24 @czarneckid Pending relationships
czarneckid authored
135 configuration.pending_follow = true
136 configuration.page_size = 25
137 end
138
139 Amico.follow(1, 11)
140 => true
141
142 Amico.follow(11, 1)
143 => true
144
145 Amico.pending?(1, 11)
146 => true
147
148 Amico.pending?(11, 1)
149 => true
150
151 Amico.accept(1, 11)
152 => nil
153
154 Amico.pending?(1, 11)
155 => false
156
157 Amico.pending?(11, 1)
158 => true
159
160 Amico.following?(1, 11)
161 => true
162
163 Amico.following?(11, 1)
164 => false
165
166 Amico.follower?(11, 1)
167 => true
168
169 Amico.follower?(1, 11)
170 => false
171
172 Amico.accept(11, 1)
173 => [1, 1]
174
175 Amico.pending?(1, 11)
176 => false
177
178 Amico.pending?(11, 1)
179 => false
180
181 Amico.following?(1, 11)
182 => true
183
184 Amico.following?(11, 1)
185 => true
186
187 Amico.follower?(11, 1)
188 => true
189
190 Amico.follower?(1, 11)
191 => true
192
193 Amico.reciprocated?(1, 11)
194 => true
195 ```
196
6dcbcca @czarneckid More documentation
czarneckid authored
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'
0a7c8fd @czarneckid Scoping
czarneckid authored
210 configuration.default_scope_key = 'default'
6dcbcca @czarneckid More documentation
czarneckid authored
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'
0a7c8fd @czarneckid Scoping
czarneckid authored
298 configuration.default_scope_key = 'default'
6dcbcca @czarneckid More documentation
czarneckid authored
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
0a7c8fd @czarneckid Scoping
czarneckid authored
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
d77ba2c @czarneckid Updating README
czarneckid authored
401 ## Documentation
402
403 The source for the [relationships module](https://github.com/agoragames/amico/blob/master/lib/amico/relationships.rb) is well-documented. There are some
383dc59 @czarneckid Update online documentation link
czarneckid authored
404 simple examples in the method documentation. You can also refer to the [online documentation](http://rubydoc.info/github/agoragames/amico/master/frames).
68aa5f3 @czarneckid Updating README
czarneckid authored
405
50ecb4b @czarneckid Adding future plans
czarneckid authored
406 ## Future Plans
407
408 * Add :scope to various calls to allow you to use amico for different contexts
409
68aa5f3 @czarneckid Updating README
czarneckid authored
410 ## FAQ?
411
412 ### Why use Redis sorted sets and not Redis sets?
413
414 Based on the work I did in developing [leaderboard](https://github.com/agoragames/leaderboard),
415 leaderboards backed by Redis, I know I wanted to be able to page through the various relationships.
416 This does not seem to be possible given the current set of commands for Redis sets.
417
418 Also, by using the "score" in Redis sorted sets that is based on the time of when a relationship
419 is established, we can get our "recent friends". It is possible that the scoring function may be
420 user-defined in the future to allow for some specific ordering.
10177dc @czarneckid Documentation
czarneckid authored
421
422 ## Contributing to amico
423
424 * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
425 * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
426 * Fork the project
427 * Start a feature/bugfix branch
428 * Commit and push until you are happy with your contribution
429 * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
430 * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
431
432 ## Copyright
433
434 Copyright (c) 2012 David Czarnecki. See LICENSE.txt for further details.
435
Something went wrong with that request. Please try again.