diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index 982a7eb..60a1212 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -56,6 +56,7 @@ class Rest include Cypher include Gremlin include Clean + include Extensions extend Forwardable attr_reader :connection @@ -65,7 +66,6 @@ class Rest def initialize(options = ENV['NEO4J_URL'] || {}) @connection = Connection.new(options) - @extensions ||= Extensions.new(@connection) @batch ||= Batch.new(@connection) @spatial ||= Spatial.new(@connection) end @@ -101,16 +101,6 @@ def get_relationship_end_node(rel) get_node(rel["end"]) end - # unmanaged extensions - - def post_extension(path, params = {}, headers = nil) - @extensions.post(path, params, headers) - end - - def get_extension(path) - @extensions.get(path) - end - # batch def batch(*args) diff --git a/lib/neography/rest/extensions.rb b/lib/neography/rest/extensions.rb index 48a64c6..10f5b76 100644 --- a/lib/neography/rest/extensions.rb +++ b/lib/neography/rest/extensions.rb @@ -1,17 +1,13 @@ module Neography class Rest - class Extensions + module Extensions include Neography::Rest::Helpers - - def initialize(connection) - @connection ||= connection - end - - def get(path) + + def get_extension(path) @connection.get(path) end - def post(path, body = {}, headers = nil) + def post_extension(path, body = {}, headers = nil) options = { :body => headers.nil? ? body.to_json : body, :headers => headers || json_content_type.merge({'Accept' => 'application/json;stream=true'}) diff --git a/spec/unit/rest/extensions_spec.rb b/spec/unit/rest/extensions_spec.rb index 2e93445..085f134 100644 --- a/spec/unit/rest/extensions_spec.rb +++ b/spec/unit/rest/extensions_spec.rb @@ -4,14 +4,13 @@ module Neography class Rest describe Extensions do - let(:connection) { double } - subject { Extensions.new(connection) } + subject { Neography::Rest.new } it "executes an extensions get query" do path = "/unmanaged_extension/test" - connection.should_receive(:get).with(path) - subject.get("/unmanaged_extension/test") + subject.connection.should_receive(:get).with(path) + subject.get_extension("/unmanaged_extension/test") end it "executes an extensions post query" do @@ -20,8 +19,8 @@ class Rest :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" }) + subject.connection.should_receive(:post).with(path, options) + subject.post_extension("/unmanaged_extension/test", { :foo => "bar", :baz => "qux" }) end end