Class: Neography::Rest::NodeRelationships

Inherits:
Object
  • Object
show all
Extended by:
Paths
Includes:
Helpers
Defined in:
lib/neography/rest/node_relationships.rb

Instance Method Summary collapse

Methods included from Paths

add_path, build_path, encode

Methods included from Helpers

#get_id, #json_content_type, #parse_direction

Constructor Details

#initialize(connection) ⇒ NodeRelationships

Returns a new instance of NodeRelationships.



11
12
13
# File 'lib/neography/rest/node_relationships.rb', line 11

def initialize(connection)
  @connection = connection
end

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/neography/rest/node_relationships.rb', line 15

def create(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(base_path(:id => get_id(from)), options)
end

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



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/neography/rest/node_relationships.rb', line 27

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

  if types.nil?
    node_relationships = @connection.get(direction_path(:id => get_id(id), :direction => direction)) || []
  else
    node_relationships = @connection.get(type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || []
  end

  return nil if node_relationships.empty?
  node_relationships
end