Skip to content

Commit

Permalink
Merge branch 'master' of github.com:maxdemarzi/neography
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 19, 2012
2 parents a3ae832 + c7b3c3c commit 2d82421
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 81 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
script: "bundle exec rake neo4j:install neo4j:start spec --trace"
script: "bundle exec rake neo4j:install['enterprise','1.8.M03'] neo4j:start spec --trace"
language: ruby
rvm:
- 1.9.3
39 changes: 20 additions & 19 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
PATH
remote: .
specs:
neography (0.0.20)
crack (= 0.1.8)
httparty (= 0.8.1)
neography (0.0.26)
httparty (>= 0.8.1)
json
oj
os
rake (>= 0.8.7)
rubyzip

GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
diff-lcs (1.1.3)
httparty (0.8.1)
multi_json
httparty (0.8.3)
multi_json (~> 1.0)
multi_xml
json (1.6.4)
multi_json (1.0.4)
multi_xml (0.4.1)
json (1.7.3)
json (1.7.3-java)
multi_json (1.3.6)
multi_xml (0.5.1)
net-http-spy (0.2.1)
os (0.9.5)
oj (1.2.9)
os (0.9.6)
rake (0.8.7)
rspec (2.7.0)
rspec-core (~> 2.7.0)
rspec-expectations (~> 2.7.0)
rspec-mocks (~> 2.7.0)
rspec-core (2.7.1)
rspec-expectations (2.7.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.7.0)
rubyzip (0.9.5)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rubyzip (0.9.8)

PLATFORMS
java
Expand Down
99 changes: 53 additions & 46 deletions README.rdoc

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ def find_and_require_user_defined_code
DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"]

require 'cgi'
require 'crack'
require 'httparty'
require 'json'
require 'oj'
require 'logger'
require 'ostruct'
require 'os'
require 'zip/zipfilesystem'

require 'neography/crack_parser'
require 'neography/oj_parser'

require 'neography/config'
require 'neography/rest'
require 'neography/neography'
Expand Down
2 changes: 1 addition & 1 deletion lib/neography/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path
@authentication = {}
@username = nil
@password = nil
@parser = {:parser => CrackParser}
@parser = {:parser => OjParser}
end
end
7 changes: 0 additions & 7 deletions lib/neography/crack_parser.rb

This file was deleted.

8 changes: 8 additions & 0 deletions lib/neography/oj_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class OjParser < HTTParty::Parser

protected
def json
#Oj::Doc.parse(body)
Oj.load(body)
end
end
45 changes: 43 additions & 2 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ def get_node_index(index, key, value)
index
end

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

def find_node_auto_index(query)
index = get("/index/auto/node/?query=#{query}") || Array.new
return nil if index.empty?
index
end

def find_node_index(*args)
case args.size
when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
Expand Down Expand Up @@ -342,6 +354,18 @@ def find_relationship_index(*args)
index
end

def get_relationship_auto_index(key, value)
index = get("/index/auto/relationship/#{key}/#{value}") || Array.new
return nil if index.empty?
index
end

def find_relationship_auto_index(query)
index = get("/index/auto/relationship/?query=#{query}") || Array.new
return nil if index.empty?
index
end

def traverse(id, return_type, description)
options = { :body => {"order" => get_order(description["order"]),
"uniqueness" => get_uniqueness(description["uniqueness"]),
Expand All @@ -368,7 +392,7 @@ def get_shortest_weighted_path(from, to, relationships, weight_attr='weight', de
end

def execute_query(query, params = {})
options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} }
options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json;stream=true'} }
result = post(@cypher_path, options)
end

Expand All @@ -383,10 +407,19 @@ def batch(*args)
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json', 'Accept' => 'application/json;stream=true'} }
post("/batch", options)
end

def batch_not_streaming(*args)
batch = []
Array(args).each_with_index do |c,i|
batch << {:id => i}.merge(get_batch(c))
end
options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
post("/batch", options)
end

# For testing (use a separate neo4j instance)
# call this before each test or spec
def clean_database(sanity_check = "not_really")
Expand Down Expand Up @@ -432,6 +465,14 @@ def get_batch(args)
{:method => "GET", :to => "/index/relationship/#{args[1]}/#{args[2]}/#{args[3]}"}
when :get_node_relationships
{:method => "GET", :to => "/node/#{get_id(args[1])}/relationships/#{args[2] || 'all'}"}
when :execute_script
{:method => "POST", :to => @gremlin_path, :body => {:script => args[1], :params => args[2]}}
when :execute_query
if args[2]
{:method => "POST", :to => @cypher_path, :body => {:query => args[1], :params => args[2]}}
else
{:method => "POST", :to => @cypher_path, :body => {:query => args[1]}}
end
else
raise "Unknown option #{args[0]}"
end
Expand Down
4 changes: 2 additions & 2 deletions neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec"
s.add_development_dependency "net-http-spy", "0.2.1"
s.add_development_dependency "rake", "~> 0.8.7"
s.add_dependency "crack", "0.1.8"
s.add_dependency "httparty", "0.8.1"
s.add_dependency "httparty", ">= 0.8.1"
s.add_dependency "rake", ">= 0.8.7"
s.add_dependency "json"
s.add_dependency "os"
s.add_dependency "rubyzip"
s.add_dependency "oj"
end
36 changes: 35 additions & 1 deletion spec/integration/rest_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@
existing_index.first["self"].should == new_node["self"]
@neo.remove_node_from_index(index_name, key, value, new_node)
end
end

it "can get a node index" do
index_name = generate_text(6)
Expand Down Expand Up @@ -235,6 +234,41 @@
batch_result.first["body"].first["end"].split('/').last.should == node2["self"].split('/').last
end

it "can batch gremlin" do
batch_result = @neo.batch [:execute_script, "g.v(0)"]
batch_result.first.should have_key("id")
batch_result.first.should have_key("from")
batch_result.first["body"]["self"].split('/').last.should == "0"
end

it "can batch gremlin with parameters" do
new_node = @neo.create_node
id = new_node["self"].split('/').last
batch_result = @neo.batch [:execute_script, "g.v(id)", {:id => id.to_i}]
batch_result.first.should have_key("id")
batch_result.first.should have_key("from")
batch_result.first["body"]["self"].split('/').last.should == id
end

it "can batch cypher" do
batch_result = @neo.batch [:execute_query, "start n=node(0) return n"]
batch_result.first.should have_key("id")
batch_result.first.should have_key("from")
batch_result.first["body"]["data"][0][0]["self"].split('/').last.should == "0"
end

it "can batch cypher with parameters" do
new_node = @neo.create_node
id = new_node["self"].split('/').last
batch_result = @neo.batch [:execute_query, "start n=node({id}) return n", {:id => id.to_i}]
batch_result.first.should have_key("id")
batch_result.first.should have_key("from")
batch_result.first["body"]["data"][0][0]["self"].split('/').last.should == id
end


end

describe "referenced batch" do
it "can create a relationship from two newly created nodes" do
batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}]
Expand Down
19 changes: 19 additions & 0 deletions spec/integration/rest_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,24 @@

end

describe "auto indexes" do

it "can get a node from an automatic index" do
pending
end

it "can query a node from an automatic index" do
pending
end

it "can get a relationship from an automatic index" do
pending
end

it "can query a relationship from an automatic index" do
pending
end

end

end

0 comments on commit 2d82421

Please sign in to comment.