Sha256: 97f25da6449ca415d0c92f787a1e4cec317d658db83a18dcabde798311b7e6fa

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# neo4jr-social start -p8988

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

def create_person(name)
  response = RestClient.post "http://localhost:8988/neo4jr-social/nodes", :name => name  
  JSON.parse(response)
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 degrees_of_seperation(start_node, destination_node)
  url = "http://localhost:8988/neo4jr-social/nodes/#{start_node['node_id']}/paths?to=#{destination_node['node_id']}&type=friends&depth=3&direction=outgoing"
  response = RestClient.get(url)
  JSON.parse(response)
end

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

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

degrees_of_seperation(johnathan, mary).each do |path|
  puts path.map{|node| node['name'] || node['type']}.join(' => ') 
end

# RESULT
# Johnathan => friends => Mark => friends => Phill => friends => Mary
# Johnathan => friends => Mark => friends => Mary

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
neo4jr-social-0.3.1 examples/linkedin.rb
neo4jr-social-0.2.0 examples/linkedin.rb
neo4jr-social-0.1.2 examples/linkedin.rb