-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a9b24a
commit ef9f673
Showing
6 changed files
with
168 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Neography | ||
class Rest | ||
include HTTParty | ||
base_uri 'http://localhost:9999' | ||
format :json | ||
|
||
class << self | ||
|
||
def get_root | ||
rescue_404(get('/')) | ||
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_404(post("/node", options)) | ||
else | ||
rescue_404(post("/node")) | ||
end | ||
end | ||
|
||
|
||
private | ||
|
||
def rescue_404(response) | ||
begin | ||
response = response.parsed_response | ||
rescue | ||
response = nil | ||
end | ||
response | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Neography::Rest do | ||
|
||
describe "get_root" do | ||
it "can get the root node" do | ||
root_node = Neography::Rest.get_root | ||
root_node.should have_key("reference_node") | ||
end | ||
end | ||
|
||
describe "create_node" do | ||
it "can create an empty node" do | ||
new_node = Neography::Rest.create_node | ||
new_node.should_not be_nil | ||
end | ||
|
||
it "can create a node with one property" do | ||
new_node = Neography::Rest.create_node("name" => "Max") | ||
new_node["data"]["name"].should == "Max" | ||
end | ||
|
||
it "can create a node with more than one property" do | ||
new_node = Neography::Rest.create_node("age" => 31, "name" => "Max") | ||
new_node["data"]["name"].should == "Max" | ||
new_node["data"]["age"].should == 31 | ||
end | ||
end | ||
|
||
end |