Skip to content

Commit

Permalink
added get node properties
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 17, 2010
1 parent 7f57fcb commit 3bd4035
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
10 changes: 6 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ There are two ways to use Neography:

A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil:

Neography::Rest.get_root # Get the root node
Neography::Rest.create_node # Create an empty node
Neography::Rest.create_node("age" => 31, "name" => "Max") # Create a node with some properties
Neography::Rest.get_node(id) # Get a node and its properties
Neography::Rest.get_root # Get the root node
Neography::Rest.create_node # Create an empty node
Neography::Rest.create_node("age" => 31, "name" => "Max") # Create a node with some properties
Neography::Rest.get_node(id) # Get a node and its properties
Neography::Rest.set_node_properties(id, {"weight" => 200}) # Set a node's properties
Neography::Rest.get_node_properties(id) # Get just the properties

... and a work in progress more rubyish layer that's not quite ready for use yet.

Expand Down
10 changes: 7 additions & 3 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ def create_node(*args)
end
end

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

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

def get_node_properties(id)
rescue_ij { get("/node/#{id}/properties") }
end

private

# Rescue from Invalid JSON error thrown by Crack Gem
Expand Down
22 changes: 22 additions & 0 deletions spec/integration/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,27 @@
end
end

describe "get_node_properties" do
it "can get 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 "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 + 1).should be_nil
end

it "returns nil if it fails to get properties on a node that does not exist" 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 + 1).should be_nil
end
end


end

0 comments on commit 3bd4035

Please sign in to comment.