-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
292304c
commit c9da4c1
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Neography | ||
class Rest | ||
class Spatial | ||
extend Neography::Rest::Paths | ||
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" | ||
|
||
def initialize(connection) | ||
@connection = connection | ||
end | ||
|
||
def index | ||
@connection.get(index_path) | ||
end | ||
|
||
def add_point_layer(layer, lat, lon) | ||
options = { | ||
:body => { | ||
:layer => layer, | ||
:lat => lat || "lat", | ||
:lon => lon || "lon" | ||
}.to_json, | ||
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) | ||
} | ||
|
||
@connection.post(add_simple_point_layer_path, options) | ||
end | ||
|
||
def add_editable_layer(layer, format = "WKT", node_property_name = "wkt") | ||
options = { | ||
:body => { | ||
:layer => name, | ||
:format => format, | ||
:nodePropertyName => node_property_name | ||
}.to_json, | ||
:headers => json_content_type.merge({'Accept' => 'application/json;charset=UTF-8'}) | ||
} | ||
|
||
@connection.post(add_editable_layer_path, options) | ||
end | ||
|
||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'spec_helper' | ||
|
||
describe Neography::Rest do | ||
before(:each) do | ||
@neo = Neography::Rest.new | ||
end | ||
|
||
describe "find the spatial plugin" do | ||
it "can get a description of the spatial plugin" do | ||
si = @neo.get_spatial | ||
si.should_not be_nil | ||
si["graphdb"]["addEditableLayer"].should_not be_nil | ||
end | ||
end | ||
|
||
describe "add a point layer" do | ||
it "can add a simple point layer" do | ||
pl = @neo.add_point_layer("restaurants") | ||
pl.should_not be_nil | ||
pl.first["data"]["layer"].should == "restaurants" | ||
pl.first["data"]["geomencoder_config"].should == "lon:lat" | ||
end | ||
|
||
it "can add a simple point layer with lat and long" do | ||
pl = @neo.add_point_layer("coffee_shops", "latitude", "longitude") | ||
pl.should_not be_nil | ||
pl.first["data"]["layer"].should == "coffee_shops" | ||
pl.first["data"]["geomencoder_config"].should == "longitude:latitude" | ||
end | ||
|
||
end | ||
|
||
end |