Skip to content
Browse files

update the spec with more methods, and add some examples in the perl …

…script
  • Loading branch information...
1 parent a7a7740 commit 4dd9c6581b9e822af73a44aded54256fd41b444c @franckcuny committed Oct 27, 2011
Showing with 169 additions and 10 deletions.
  1. +128 −6 neo4j.json
  2. +41 −4 neo4j.pl
View
134 neo4j.json
@@ -2,21 +2,143 @@
"base_url": "http://127.0.0.1:7474/db/data",
"version": "0.1",
"methods": {
+ "root": {
+ "path": "/",
+ "method": "GET",
+ "expected_status": [200]
+ },
"get_node": {
- "optional_params": [
- ],
"required_params": [
"node"
],
"path": "/node/:node",
- "method": "GET"
+ "method": "GET",
+ "expected_status": [200]
},
"create_node": {
+ "path": "/node/",
+ "method": "POST",
+ "expected_status": [201]
+ },
+ "set_node_properties": {
"required_params": [
+ "id"
],
- "required_payload": true,
- "path": "/node/",
- "method": "POST"
+ "path": "/node/:id/properties",
+ "method": "PUT",
+ "expected_status": [204]
+ },
+ "node_properties": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/node/:id/properties",
+ "method": "GET",
+ "expected_status": [200, 204]
+ },
+ "delete_node_properties": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/node/:id/properties",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "node_property": {
+ "required_params": [
+ "id", "property"
+ ],
+ "path": "/node/:id/properties/:property",
+ "method": "GET",
+ "expected_status": [200]
+ },
+ "delete_node_property": {
+ "required_params": [
+ "id", "property"
+ ],
+ "path": "/node/:id/properties/:property",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "delete_node": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/node/:id",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "add_edge": {
+ "required_params": [
+ "id", "to", "data", "type"
+ ],
+ "path": "/node/:id/relationships",
+ "method": "POST",
+ "expected_status": [201]
+ },
+ "set_edge_properties": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/relationship/:id/properties",
+ "method": "PUT",
+ "expected_status": [204]
+ },
+ "edge_properties": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/relationship/:id/properties",
+ "method": "GET",
+ "expected_status": [200]
+ },
+ "delete_edge_properties": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/relationship/:id/properties",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "set_edge_property": {
+ "required_params": [
+ "id", "property"
+ ],
+ "path": "/relationship/:id/properties/:property",
+ "method": "PUT",
+ "expected_status": [204]
+ },
+ "edge_property": {
+ "required_params": [
+ "id", "property"
+ ],
+ "path": "/relationship/:id/properties/:property",
+ "method": "GET",
+ "expected_status": [200]
+ },
+ "delete_edge_property": {
+ "required_params": [
+ "id", "property"
+ ],
+ "path": "/relationship/:id/properties/:property",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "delete_edge": {
+ "required_params": [
+ "id"
+ ],
+ "path": "/relationship/:id",
+ "method": "DELETE",
+ "expected_status": [204]
+ },
+ "get_edges": {
+ "required_params": [
+ "id", "dir", "types"
+ ],
+ "path": "/node/:id/relationships/:dir/:types",
+ "method": "GET",
+ "expected_status": [200]
}
},
"formats": [
View
45 neo4j.pl
@@ -2,18 +2,55 @@
use strict;
use Net::HTTP::Spore;
use Data::Dumper;
+use Try::Tiny;
# Create a Neo4j client
my $client = Net::HTTP::Spore->new_from_spec('neo4j.json', trace => '1=log.txt');
+$client->enable('Format::JSON');
+
+# test the root method
+my $root = $client->root();
+print Dumper $root->body;
# Create a new node
-my $node = $client->create_node();
-my $body = $node->body;
-print Dumper $body;
+create_node();
+
+# Create a new node with some properties
+create_node({name => 'foo'});
+
+# Set properties on node 1
+$client->set_node_properties(id => 1, payload => {name => 'baz'});
+
+# Get the properties now
+my $node = $client->node_properties(id => 1);
+print Dumper $node->body;
+
+# Let's delete the properties
+$node = $client->delete_node_properties(id => 1);
+$node = $client->node_properties(id => 1);
+print Dumper $node->body;
# Get an existing node
-my $existing_node = $client->get_node( node => 8 );
+my $existing_node = $client->get_node( node => 1 );
my $node_body = $existing_node->body;
print Dumper $node_body;
+# Get the property 'name' on the second node
+$node = $client->node_property(id => 2, property => 'name');
+print Dumper $node->body;
+
+sub create_node {
+ my $properties = shift || {};
+ my ($node, $body);
+ # it's better to try/catch spore's method call
+ # if there is an error, the client throw an exception
+ try {
+ $node = $client->create_node(payload => $properties);
+ $body = $node->body;
+ print Dumper $body;
+ }catch{
+ print Dumper $_;
+ };
+}
+

0 comments on commit 4dd9c65

Please sign in to comment.
Something went wrong with that request. Please try again.