Skip to content

Commit

Permalink
started working on unmanaged extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jan 18, 2013
1 parent 210f494 commit e94ea2e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
require 'neography/rest/relationship_auto_indexes'
require 'neography/rest/cypher'
require 'neography/rest/gremlin'
require 'neography/rest/extensions'
require 'neography/rest/batch'
require 'neography/rest/clean'

Expand Down Expand Up @@ -56,6 +57,7 @@ def initialize(options = ENV['NEO4J_URL'] || {})

@cypher = Cypher.new(@connection)
@gremlin = Gremlin.new(@connection)
@extensions = Extensions.new(@connection)
@batch = Batch.new(@connection)
@clean = Clean.new(@connection)
end
Expand Down Expand Up @@ -334,6 +336,16 @@ def execute_script(script, params = {})
@gremlin.execute(script, params)
end

# unmanaged extensions

def post_extension(path, params = {})
@extensions.post(path, params)
end

def get_extension(path)
@extensions.get(path)
end

# batch

def batch(*args)
Expand Down
25 changes: 25 additions & 0 deletions lib/neography/rest/extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Neography
class Rest
class Extensions
include Neography::Rest::Helpers

def initialize(connection)
@connection = connection
end

def get(path)
@connection.get(path)
end

def post(path, body = {})
options = {
:body => body.to_json,
:headers => json_content_type.merge({'Accept' => 'application/json;stream=true'})
}

@connection.post(path, options)
end

end
end
end
29 changes: 29 additions & 0 deletions spec/unit/rest/extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

module Neography
class Rest
describe Extensions do

let(:connection) { stub }
subject { Extensions.new(connection) }

it "executes an extensions get query" do
path = "/unmanaged_extension/test"

connection.should_receive(:get).with(path)
subject.get("/unmanaged_extension/test")
end

it "executes an extensions post query" do
path = "/unmanaged_extension/test"
options = {
:body=>"{\"foo\":\"bar\",\"baz\":\"qux\"}",
:headers=>{"Content-Type"=>"application/json", "Accept"=>"application/json;stream=true"}
}
connection.should_receive(:post).with(path, options)
subject.post("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" })
end

end
end
end

1 comment on commit e94ea2e

@rdvdijk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff, Max!

Please sign in to comment.