Sha256: 7044a22a309b751fcbd2e34e7a7c2b0d0913f37b6bf71a9f386838ccae09a6b2

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

# neo4jr-social start -p8988

require 'rubygems'
require 'json'
require 'rest_client'

def create_person(name)
  JSON.parse RestClient.post( "http://localhost:8988/neo4jr-social/nodes", :name => name  )
end

def make_mutual_friends(node1, node2)
  RestClient.post "http://localhost:8988/neo4jr-social/nodes/#{node1['node_id']}/relationships", :to => node2['node_id'], :type => 'friends'
  RestClient.post "http://localhost:8988/neo4jr-social/nodes/#{node2['node_id']}/relationships", :to => node1['node_id'], :type => 'friends'
end

def suggestions_for(start_node)
  JSON.parse RestClient.get("http://localhost:8988/neo4jr-social/nodes/#{start_node['node_id']}/recommendations?type=friends")
end

johnathan = create_person('Johnathan')
mark      = create_person('Mark')
phill     = create_person('Phill')
mary      = create_person('Mary')
luke      = create_person('Luke')

make_mutual_friends(johnathan, mark)
make_mutual_friends(mark, mary)
make_mutual_friends(mark, phill)
make_mutual_friends(phill, mary)
make_mutual_friends(phill, luke)

puts "Johnathan should become friends with #{suggestions_for(johnathan).map{|n| n['name']}.join(', ')}"
#=> Johnathan should become friends with Mary, Phill

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
neo4jr-social-0.1.1 examples/facebook.rb
neo4jr-social-0.1.0 examples/facebook.rb