Module: Neography::Rest::NodeRelationships

Includes:
Helpers
Included in:
Neography::Rest
Defined in:
lib/neography/rest/node_relationships.rb

Instance Method Summary collapse

Methods included from Helpers

#encode, #escape, #get_id, #json_content_type, #parse_depth, #parse_direction, #parse_order, #parse_type, #parse_uniqueness

Instance Method Details

#create_relationship(type, from, to, properties = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/neography/rest/node_relationships.rb', line 6

def create_relationship(type, from, to, properties = nil)
  options = {
    :body => {
      :to => @connection.configuration + "/node/#{get_id(to)}",
      :data => properties,
      :type => type
    }.to_json,
    :headers => json_content_type }

  @connection.post("/node/%{id}/relationships" % {:id => get_id(from)}, options)
end

#get_node_relationships(id, direction = nil, types = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/neography/rest/node_relationships.rb', line 18

def get_node_relationships(id, direction = nil, types = nil)
  direction = parse_direction(direction)

  if types.nil?
    node_relationships = @connection.get("/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction}) || []
  else
    node_relationships = @connection.get("/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => encode(Array(types).join('&'))}) || []
  end

  return [] if node_relationships.empty?
  node_relationships
end