Skip to content

Commit

Permalink
forgot to add the new db path to some delete actions, splitting test …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
maxdemarzi committed Nov 19, 2010
1 parent e01369f commit 611af01
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 550 deletions.
58 changes: 29 additions & 29 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
module Neography
class Rest
include HTTParty
base_uri 'http://localhost:9999'
base_uri Neography::Config.to_s
format :json

class << self

def get_root
rescue_ij { get('/') }
rescue_ij { get('/db/data/') }
end

def create_node(*args)
if args[0].respond_to?(:each_pair) && args[0]
options = { :body => args[0].to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { post("/node", options) }
rescue_ij { post("/db/data/node", options) }
else
rescue_ij { post("/node") }
rescue_ij { post("/db/data/node") }
end
end

def get_node(id)
rescue_ij { get("/node/#{id}") }
rescue_ij { get("/db/data/node/#{id}") }
end

def reset_node_properties(id, properties)
options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/node/#{id}/properties", options) }
rescue_ij { put("/db/data/node/#{id}/properties", options) }
end

def get_node_properties(id, properties = nil)
if properties.nil?
rescue_ij { get("/node/#{id}/properties") }
rescue_ij { get("/db/data/node/#{id}/properties") }
else
node_properties = Hash.new
properties.to_a.each do |property|
value = rescue_ij { get("/node/#{id}/properties/#{property}") }
value = rescue_ij { get("/db/data/node/#{id}/properties/#{property}") }
node_properties[property] = value unless value.nil?
end
return nil if node_properties.empty?
Expand All @@ -44,42 +44,42 @@ def get_node_properties(id, properties = nil)

def remove_node_properties(id, properties = nil)
if properties.nil?
rescue_ij { delete("/node/#{id}/properties") }
rescue_ij { delete("/db/data/node/#{id}/properties") }
else
properties.to_a.each do |property|
rescue_ij { delete("/node/#{id}/properties/#{property}") }
rescue_ij { delete("/db/data/node/#{id}/properties/#{property}") }
end
end
end

def set_node_properties(id, properties)
properties.each do |key, value|
options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/node/#{id}/properties/#{key}", options) }
rescue_ij { put("/db/data/node/#{id}/properties/#{key}", options) }
end
end

def delete_node(id)
rescue_ij { delete("/node/#{id}") }
rescue_ij { delete("/db/data/node/#{id}") }
end

def create_relationship(type, from, to, props = nil)
options = { :body => {:to => Neography::Config.to_s + "/node/#{to}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { post("/node/#{from}/relationships", options) }
rescue_ij { post("/db/data/node/#{from}/relationships", options) }
end

def reset_relationship_properties(id, properties)
options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/relationship/#{id}/properties", options) }
rescue_ij { put("/db/data/relationship/#{id}/properties", options) }
end

def get_relationship_properties(id, properties = nil)
if properties.nil?
rescue_ij { get("/relationship/#{id}/properties") }
rescue_ij { get("/db/data/relationship/#{id}/properties") }
else
relationship_properties = Hash.new
properties.to_a.each do |property|
value = rescue_ij { get("/relationship/#{id}/properties/#{property}") }
value = rescue_ij { get("/db/data/relationship/#{id}/properties/#{property}") }
relationship_properties[property] = value unless value.nil?
end
return nil if relationship_properties.empty?
Expand All @@ -89,32 +89,32 @@ def get_relationship_properties(id, properties = nil)

def remove_relationship_properties(id, properties = nil)
if properties.nil?
rescue_ij { delete("/relationship/#{id}/properties") }
rescue_ij { delete("/db/data/relationship/#{id}/properties") }
else
properties.to_a.each do |property|
rescue_ij { delete("/relationship/#{id}/properties/#{property}") }
rescue_ij { delete("/db/data/relationship/#{id}/properties/#{property}") }
end
end
end

def set_relationship_properties(id, properties)
properties.each do |key, value|
options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { put("/relationship/#{id}/properties/#{key}", options) }
rescue_ij { put("/db/data/relationship/#{id}/properties/#{key}", options) }
end
end

def delete_relationship(id)
rescue_ij { delete("/relationship/#{id}") }
rescue_ij { delete("/db/data/relationship/#{id}") }
end

def get_node_relationships(id, dir=nil, types=nil)
dir = get_dir(dir)

if types.nil?
node_relationships = rescue_ij { get("/node/#{id}/relationships/#{dir}") } || Array.new
node_relationships = rescue_ij { get("/db/data/node/#{id}/relationships/#{dir}") } || Array.new
else
node_relationships = rescue_ij { get("/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") } || Array.new
node_relationships = rescue_ij { get("/db/data/node/#{id}/relationships/#{dir}/#{types.to_a.join('&')}") } || Array.new
end
return nil if node_relationships.empty?
node_relationships
Expand All @@ -123,36 +123,36 @@ def get_node_relationships(id, dir=nil, types=nil)
def delete_node!(id)
relationships = get_node_relationships(id)
relationships.each { |r| delete_relationship(r["self"].split('/').last) } unless relationships.nil?
rescue_ij { delete("/node/#{id}") }
rescue_ij { delete("/db/data/node/#{id}") }
end

def list_indexes
rescue_ij { get("/index") }
rescue_ij { get("/db/data/index") }
end

def add_to_index(key, value, id)
options = { :body => (Neography::Config.to_s + "/node/#{id}").to_json, :headers => {'Content-Type' => 'application/json'} }
rescue_ij { post("/index/node/#{key}/#{value}", options) }
rescue_ij { post("/db/data/index/node/#{key}/#{value}", options) }
end

def remove_from_index(key, value, id)
rescue_ij { delete("/index/node/#{key}/#{value}/#{id}") }
rescue_ij { delete("/db/data/index/node/#{key}/#{value}/#{id}") }
end

def get_index(key, value)
index = rescue_ij { get("/index/node/#{key}/#{value}") } || Array.new
index = rescue_ij { get("/db/data/index/node/#{key}/#{value}") } || Array.new
return nil if index.empty?
index
end

def get_path(from, to, relationships, depth=1, algorithm="allPaths")
options = { :body => {"to" => Neography::Config.to_s + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
path = rescue_ij { post("/node/#{from}/path", options) } || Hash.new
path = rescue_ij { post("/db/data/node/#{from}/path", options) } || Hash.new
end

def get_paths(from, to, relationships, depth=1, algorithm="allPaths")
options = { :body => {"to" => Neography::Config.to_s + "/node/#{to}", "relationships" => relationships, "max depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
paths = rescue_ij { post("/node/#{from}/paths", options) } || Array.new
paths = rescue_ij { post("/db/data/node/#{from}/paths", options) } || Array.new
end

private
Expand Down
120 changes: 0 additions & 120 deletions spec/integration/node_spec.rb

This file was deleted.

60 changes: 0 additions & 60 deletions spec/integration/relationship_spec.rb

This file was deleted.

0 comments on commit 611af01

Please sign in to comment.