Skip to content

Commit

Permalink
get some properties
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 17, 2010
1 parent 60e0b4c commit d92c2a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and
Neography::Rest.get_node(id) # Get a node and its properties
Neography::Rest.reset_node_properties(id, {"age" => 31}) # Reset a node's properties
Neography::Rest.set_node_properties(id, {"weight" => 200}) # Set a node's properties
Neography::Rest.get_node_properties(id) # Get just the properties
Neography::Rest.get_node_properties(id) # Get just the node properties
Neography::Rest.get_node_properties(id, ["weight","age"]) # Get some of the node properties
Neography::Rest.remove_node_properties(id) # Remove all properties of a node
Neography::Rest.remove_node_properties(id, "weight") # Remove one property of a node
Neography::Rest.remove_node_properties(id, ["weight","age"]) # Remove multiple properties of a node
Expand Down
14 changes: 12 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,18 @@ def reset_node_properties(id, properties)
rescue_ij { put("/node/#{id}/properties", options) }
end

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

def remove_node_properties(id, properties = nil)
Expand Down
19 changes: 17 additions & 2 deletions spec/integration/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,33 @@
end

describe "get_node_properties" do
it "can get a node's properties" do
it "can get all a node's properties" do
new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown")
new_node[:id] = new_node["self"].split('/').last
node_properties = Neography::Rest.get_node_properties(new_node[:id])
node_properties["weight"].should == 200
node_properties["eyes"].should == "brown"
end

it "can get some of a node's properties" do
new_node = Neography::Rest.create_node("weight" => 200, "eyes" => "brown", "height" => "2m")
new_node[:id] = new_node["self"].split('/').last
node_properties = Neography::Rest.get_node_properties(new_node[:id], ["weight", "height"])
node_properties["weight"].should == 200
node_properties["height"].should == "2m"
node_properties["eyes"].should be_nil
end

it "returns nil if it gets the properties on a node that does not have any" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.get_node_properties(new_node[:id].to_i + 10000).should be_nil
Neography::Rest.get_node_properties(new_node[:id]).should be_nil
end

it "returns nil if it tries to get some of the properties on a node that does not have any" do
new_node = Neography::Rest.create_node
new_node[:id] = new_node["self"].split('/').last
Neography::Rest.get_node_properties(new_node[:id], ["weight", "height"]).should be_nil
end

it "returns nil if it fails to get properties on a node that does not exist" do
Expand Down

0 comments on commit d92c2a6

Please sign in to comment.