Skip to content

Commit

Permalink
starting with basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Nov 14, 2010
1 parent 1ef9209 commit bc1f9fc
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
log/*
36 changes: 36 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
PATH
remote: .
specs:
neography (0.0.1)
httparty (~> 0.6.1)
json

GEM
remote: http://rubygems.org/
specs:
crack (0.1.8)
diff-lcs (1.1.2)
httparty (0.6.1)
crack (= 0.1.8)
json (1.4.6-java)
net-http-spy (0.2.1)
rspec (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)
rspec-mocks (~> 2.0.1)
rspec-core (2.0.1)
rspec-expectations (2.0.1)
diff-lcs (>= 1.1.2)
rspec-mocks (2.0.1)
rspec-core (~> 2.0.1)
rspec-expectations (~> 2.0.1)

PLATFORMS
java

DEPENDENCIES
httparty (~> 0.6.1)
json
neography!
net-http-spy (~> 0.2.1)
rspec (~> 2.0.0.beta.22)
52 changes: 50 additions & 2 deletions lib/neography.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
module Neography
# Your code goes here...
def find_and_require_user_defined_code
extensions_path = ENV['neography_extensions'] || "~/.neography"
extensions_path = File.expand_path(extensions_path)
if File.exists?(extensions_path)
Dir.open extensions_path do |dir|
dir.entries.each do |file|
if file.split('.').size > 1 && file.split('.').last == 'rb'
extension = File.join(File.expand_path(extensions_path), file)
require(extension) && puts("Loaded Extension: #{extension}")
end
end
end
else
puts "No Extensions Found: #{extensions_path}"
end
end

def evaluate_response(response)
logger = Logger.new('log/neography.log')

code = response.code
body = response.body

case code
when 200
logger.debug "OK"
when 201
logger.debug "OK, created"
when 204
logger.debug "OK, no content returned"
when 400
logger.error "Invalid data sent"
when 404
logger.error "#{body}"
end

end

require 'httparty'
require 'json'
require 'logger'
#require 'net-http-spy'

#Net::HTTP.http_logger_options = {:verbose => true}
#Net::HTTP.http_logger_options = {:body => true}

require 'neography/neo'
require 'neography/node'


find_and_require_user_defined_code
12 changes: 12 additions & 0 deletions lib/neography/neo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Neography
class Neo
include HTTParty

base_uri 'http://localhost:9999'

def self.root_node
get('/')
end

end
end
48 changes: 48 additions & 0 deletions lib/neography/node.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Neography
class Node
include HTTParty
base_uri 'http://localhost:9999'
format :json

class << self

def new(*args)
if args[0].respond_to?(:each_pair) && args[0]
headers 'Content-Type' => 'application/json'
response = post("/node", :body => args[0].to_json)
evaluate_response(response)
response.parsed_response
else
response = post("/node")
evaluate_response(response)
response.parsed_response
end
end

def get_node(id)
begin
response = get("/node/#{id}")
evaluate_response(response)
response.parsed_response
rescue
nil
end
end

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

def set_properties(id, properties)
begin
response = put("/node/#{id}/properties", :body => properties.to_json)
evaluate_response(response)
response.parsed_response
rescue
nil
end
end

end
end
end
13 changes: 9 additions & 4 deletions neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ Gem::Specification.new do |s|
s.name = "neography"
s.version = Neography::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["TODO: Write your name"]
s.email = ["TODO: Write your email address"]
s.authors = "Max De Marzi"
s.email = "[email protected]"
s.homepage = "http://rubygems.org/gems/neography"
s.summary = %q{TODO: Write a gem summary}
s.description = %q{TODO: Write a gem description}
s.summary = "ruby wrapper to Neo4j Rest Interface"
s.description = "A Ruby wrapper to the Neo4j Rest Client Interface see http://components.neo4j.org/neo4j-rest/ for more details."

s.rubyforge_project = "neography"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_development_dependency "rspec", "~> 2.0.0.beta.22"
s.add_development_dependency "net-http-spy", "~> 0.2.1"
s.add_dependency "httparty", "~> 0.6.1"
s.add_dependency "json"
end
50 changes: 50 additions & 0 deletions spec/neography_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'neography'

describe Neography::Neo do
# it "has a root node" do
# Neography::Neo.root_node.should include("reference_node")
# end
end

describe Neography::Node do
it "can create an empty node" do
Neography::Node.new.should include("data"=>{})
end

it "can create a node with one property" do
Neography::Node.new(:name => "Max").should include("data"=>{"name"=>"Max"})
end

it "can create a node with more than one property" do
Neography::Node.new(:age => 31, :name => "Max").should include("data"=>{"age"=>31, "name"=>"Max"})
end

it "can find a node by its id" do
Neography::Node.get_node(2).should include("self"=>"http://localhost:9999/node/2")
end

it "fails to find a node that does not exist" do
Neography::Node.get_node(999).should be_nil
end

it "can get a node's properties" do
Neography::Node.set_properties(3, {:age => 31, :name => "Max"} ).should be_nil
Neography::Node.properties(3).should include("age"=>31, "name"=>"Max")
end

it "returns nil if a node has no properties" do
Neography::Node.properties(1).should be_nil
end

it "can set a node's properties" do
Neography::Node.set_properties(2, {:age => 32, :name => "Tom"} ).should be_nil
Neography::Node.properties(2).should include("age"=>32, "name"=>"Tom")
end

it "returns nil if it fails to set properties on a node that does not exist" do
Neography::Node.set_properties(999,{:age => 33, :name => "Harry"}).should be_nil
end



end

0 comments on commit bc1f9fc

Please sign in to comment.