Skip to content

tijmenb/graffy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graffy

Abstraction layer for a small social network graph built on top of Redis.

Note that we use 'friends' here, but it could just as easily be any other type of node. Graffy uses strings for node identifiers.

Usage

Graffy::Connection

Use Graffy::Connection to create connections.

# Create a connection between two people:
Graffy::Connection.new(user_id, friend_id).create

# And destroy it:
Graffy::Connection.new(user_id, friend_id).destroy

Use it to explore connections:

# how are the users connected?
# returns nil, :first_degree, :second_degree or :third_degree
Graffy::Connection.new(user_id, other_user_id).degree

# are the users connected at all?
Graffy::Connection.new(user_id, other_user_id).exists?

# array of mutual friends
Graffy::Connection.new(user_id, other_user_id).mutual_friends

Graffy::NetworkUpdater

If you'd like to work with second- and third-degree connections, we first have to cache those by running the network updater:

Graffy::NetworkUpdater.new.update

Do this in a background or cron job. After that you can use:

Graffy::Network

# get all the friends of the user
Graffy::Network.new(user_id).first_degree_connections

# get all the friends-of-friends of the user
Graffy::Network.new(user_id).second_degree_connections

# get all the friends-of-friends-of-friends of the user
Graffy::Network.new(user_id).third_degree_connections

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages