diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index f699065..e371efa 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -57,6 +57,7 @@ class Rest include Gremlin include Batch include Extensions + include Spatial include Clean extend Forwardable @@ -66,8 +67,6 @@ class Rest def initialize(options = ENV['NEO4J_URL'] || {}) @connection = Connection.new(options) - - @spatial ||= Spatial.new(@connection) end alias_method :list_indexes, :list_node_indexes @@ -99,53 +98,7 @@ def get_relationship_start_node(rel) def get_relationship_end_node(rel) get_node(rel["end"]) - end - - # spatial - - def get_spatial - @spatial.index - end - - def add_point_layer(layer, lat = nil, lon = nil) - @spatial.add_point_layer(layer, lat, lon) - end - - def add_editable_layer(layer, format, node_property_name) - @spatial.add_editable_layer(layer, format, node_property_name) - end - - def get_layer(layer) - @spatial.get_layer(layer) - end - - def add_geometry_to_layer(layer, geometry) - @spatial.add_geometry_to_layer(layer, geometry) - end - - def edit_geometry_from_layer(layer, geometry, node) - @spatial.edit_geometry_from_layer(layer, geometry, node) - end - - def add_node_to_layer(layer, node) - @spatial.add_node_to_layer(layer, node) - end - - def find_geometries_in_bbox(layer, minx, maxx, miny, maxy) - @spatial.find_geometries_in_bbox(layer, minx, maxx, miny, maxy) - end - - def find_geometries_within_distance(layer, pointx, pointy, distance) - @spatial.find_geometries_within_distance(layer, pointx, pointy, distance) - end - - def create_spatial_index(name, type = nil, lat = nil, lon = nil) - @spatial.create_spatial_index(name, type, lat, lon) - end - - def add_node_to_spatial_index(index, id) - @spatial.add_node_to_spatial_index(index, id) - end + end end end diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index 0475c3c..71c7113 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -236,11 +236,11 @@ def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil) # Spatial def batch_get_spatial - get Spatial.index_path + get "/ext/SpatialPlugin" end def batch_add_point_layer(layer, lat = nil, lon = nil) - post Spatial.add_simple_point_layer_path do + post "/ext/SpatialPlugin/graphdb/addSimplePointLayer" do { :layer => layer, :lat => lat || "lat", @@ -250,7 +250,7 @@ def batch_add_point_layer(layer, lat = nil, lon = nil) end def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt") - post Spatial.add_editable_layer_path do + post "/ext/SpatialPlugin/graphdb/addEditableLayer" do { :layer => layer, :format => format, @@ -260,7 +260,7 @@ def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt") end def batch_get_layer(layer) - post Spatial.get_layer_path do + post "/ext/SpatialPlugin/graphdb/getLayer" do { :layer => layer } @@ -268,7 +268,7 @@ def batch_get_layer(layer) end def batch_add_geometry_to_layer(layer, geometry) - post Spatial.add_geometry_to_layer_path do + post "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" do { :layer => layer, :geometry => geometry @@ -277,7 +277,7 @@ def batch_add_geometry_to_layer(layer, geometry) end def batch_edit_geometry_from_layer(layer, geometry, node) - post Spatial.edit_geometry_from_layer_path do + post "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" do { :layer => layer, :geometry => geometry, @@ -287,7 +287,7 @@ def batch_edit_geometry_from_layer(layer, geometry, node) end def batch_add_node_to_layer(layer, node) - post Spatial.add_node_to_layer_path do + post "/ext/SpatialPlugin/graphdb/addNodeToLayer" do { :layer => layer, :node => get_id(node) @@ -296,7 +296,7 @@ def batch_add_node_to_layer(layer, node) end def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy) - post Spatial.find_geometries_in_bbox_path do + post "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" do { :layer => layer, :minx => minx, @@ -308,7 +308,7 @@ def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy) end def batch_find_geometries_within_distance(layer, pointx, pointy, distance) - post Spatial.find_geometries_within_distance_path do + post "/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" do { :layer => layer, :pointX => pointx, diff --git a/lib/neography/rest/spatial.rb b/lib/neography/rest/spatial.rb index 8933e62..b40dbf2 100644 --- a/lib/neography/rest/spatial.rb +++ b/lib/neography/rest/spatial.rb @@ -1,30 +1,13 @@ module Neography class Rest - class Spatial - extend Neography::Rest::Paths + module Spatial include Neography::Rest::Helpers - - add_path :index, "/ext/SpatialPlugin" - add_path :add_simple_point_layer, "/ext/SpatialPlugin/graphdb/addSimplePointLayer" - add_path :add_editable_layer, "/ext/SpatialPlugin/graphdb/addEditableLayer" - add_path :get_layer, "/ext/SpatialPlugin/graphdb/getLayer" - add_path :add_geometry_to_layer, "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" - add_path :edit_geometry_from_layer, "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" - add_path :add_node_to_layer, "/ext/SpatialPlugin/graphdb/addNodeToLayer" - add_path :find_geometries_in_bbox, "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" - add_path :find_geometries_within_distance,"/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" - add_path :create_index, "/index/node" - add_path :add_to_index, "/index/node/:index" - - def initialize(connection) - @connection ||= connection - end - - def index - @connection.get(index_path) + + def get_spatial + @connection.get("/ext/SpatialPlugin") end - def add_point_layer(layer, lat, lon) + def add_point_layer(layer, lat = nil, lon = nil) options = { :body => { :layer => layer, @@ -34,7 +17,7 @@ def add_point_layer(layer, lat, lon) :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(add_simple_point_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/addSimplePointLayer", options) end def add_editable_layer(layer, format = "WKT", node_property_name = "wkt") @@ -47,7 +30,7 @@ def add_editable_layer(layer, format = "WKT", node_property_name = "wkt") :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(add_editable_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/addEditableLayer", options) end def get_layer(layer) @@ -57,7 +40,7 @@ def get_layer(layer) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(get_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/getLayer", options) end def add_geometry_to_layer(layer, geometry) @@ -68,7 +51,7 @@ def add_geometry_to_layer(layer, geometry) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(add_geometry_to_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer", options) end def edit_geometry_from_layer(layer, geometry, node) @@ -80,7 +63,7 @@ def edit_geometry_from_layer(layer, geometry, node) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(edit_geometry_from_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/updateGeometryFromWKT", options) end def add_node_to_layer(layer, node) @@ -91,7 +74,7 @@ def add_node_to_layer(layer, node) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(add_node_to_layer_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/addNodeToLayer", options) end def find_geometries_in_bbox(layer, minx, maxx, miny, maxy) @@ -105,7 +88,7 @@ def find_geometries_in_bbox(layer, minx, maxx, miny, maxy) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(find_geometries_in_bbox_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/findGeometriesInBBox", options) end def find_geometries_within_distance(layer, pointx, pointy, distance) @@ -118,10 +101,10 @@ def find_geometries_within_distance(layer, pointx, pointy, distance) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(find_geometries_within_distance_path, options) + @connection.post("/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance", options) end - def create_spatial_index(name, type, lat, lon) + def create_spatial_index(name, type = nil, lat = nil, lon = nil) options = { :body => { :name => name, @@ -134,7 +117,7 @@ def create_spatial_index(name, type, lat, lon) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(create_index_path, options) + @connection.post("/index/node", options) end def add_node_to_spatial_index(index, id) @@ -146,7 +129,7 @@ def add_node_to_spatial_index(index, id) }.to_json, :headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) } - @connection.post(add_to_index_path(:index => index), options) + @connection.post("/index/node/%{index}" % {:index => index}, options) end end