module Neography::Rest::Batch

Public Instance Methods

batch(*args) click to toggle source
# File lib/neography/rest/batch.rb, line 6
def batch(*args)
  do_batch(*args)
end
batch_no_streaming(*args) click to toggle source
# File lib/neography/rest/batch.rb, line 10
def batch_no_streaming(*args)
  do_batch_no_streaming(*args)
end

Private Instance Methods

batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt") click to toggle source
# File lib/neography/rest/batch.rb, line 272
def batch_add_editable_layer(layer, format = "WKT", node_property_name = "wkt")
  post "/ext/SpatialPlugin/graphdb/addEditableLayer" do 
    {
        :layer => layer,
        :format => format,
        :nodePropertyName => node_property_name
      }
  end
end
batch_add_geometry_to_layer(layer, geometry) click to toggle source
# File lib/neography/rest/batch.rb, line 290
def batch_add_geometry_to_layer(layer, geometry)
  post "/ext/SpatialPlugin/graphdb/addGeometryWKTToLayer" do 
    {
        :layer => layer,
        :geometry => geometry
      }
  end
end
batch_add_label(id, body) click to toggle source

NodeLabel

# File lib/neography/rest/batch.rb, line 136
def batch_add_label(id, body)
  post build_node_uri(id) + "/labels" do
    body
  end
end
batch_add_node_to_index(index, key, value, id, unique = false) click to toggle source
# File lib/neography/rest/batch.rb, line 97
def batch_add_node_to_index(index, key, value, id, unique = false)
  path = unique ? "/index/node/%{index}?unique" % {:index => index} : "/index/node/%{index}" % {:index => index}
  post path do
    {
      :uri   => build_node_uri(id),
      :key   => key,
      :value => value
    }
  end
end
batch_add_node_to_layer(layer, node) click to toggle source
# File lib/neography/rest/batch.rb, line 309
def batch_add_node_to_layer(layer, node)
  post "/ext/SpatialPlugin/graphdb/addNodeToLayer" do 
    {
        :layer => layer,
        :node => get_id(node)
      }
  end
end
batch_add_node_to_spatial_index(index, id) click to toggle source
# File lib/neography/rest/batch.rb, line 355
def batch_add_node_to_spatial_index(index, id)
  post "/index/node/%{index}" % {:index => index} do
    {
      :uri   => build_node_uri(id),
      :key   => "k",
      :value => "v"
    }
  end
end
batch_add_point_layer(layer, lat = nil, lon = nil) click to toggle source
# File lib/neography/rest/batch.rb, line 262
def batch_add_point_layer(layer, lat = nil, lon = nil)
   post "/ext/SpatialPlugin/graphdb/addSimplePointLayer" do
    {
        :layer => layer,
        :lat => lat || "lat",
        :lon => lon || "lon"
      }
    end
end
batch_add_relationship_to_index(index, key, value, id) click to toggle source
# File lib/neography/rest/batch.rb, line 187
def batch_add_relationship_to_index(index, key, value, id)
  post "/index/relationship/%{index}" % {:index => index} do
    {
      :uri   => build_relationship_uri(id),
      :key   => key,
      :value => value
    }
  end
end
batch_create_node(body) click to toggle source
# File lib/neography/rest/batch.rb, line 52
def batch_create_node(body)
  post "/node" do
    body
  end
end
batch_create_node_index(name, type = "exact", provider = "lucene", extra_config = nil) click to toggle source

NodeIndexes

# File lib/neography/rest/batch.rb, line 60
def batch_create_node_index(name, type = "exact", provider = "lucene", extra_config = nil)
  config = {
    :type => type,
    :provider => provider
  }
  config.merge!(extra_config) unless extra_config.nil?
  post "/index/node" do
    { :name => name,
      :config => config
    }
  end
end
batch_create_or_fail_unique_node(index, key, value, properties = {}) click to toggle source
# File lib/neography/rest/batch.rb, line 87
def batch_create_or_fail_unique_node(index, key, value, properties = {})
  post "/index/node/%{index}?uniqueness=%{function}" %  {:index => index, :function => 'create_or_fail'} do
    {
      :key        => key,
      :value      => value,
      :properties => properties
    }
  end
end
batch_create_relationship(type, from, to, data = nil) click to toggle source
# File lib/neography/rest/batch.rb, line 162
def batch_create_relationship(type, from, to, data = nil)
  post build_node_uri(from) + "/relationships" do
    {
      :to   => build_node_uri(to),
      :type => type,
      :data => data
    }
  end
end
batch_create_spatial_index(name, type, lat, lon) click to toggle source
# File lib/neography/rest/batch.rb, line 341
def batch_create_spatial_index(name, type, lat, lon)
  post "/index/node" do
    {
      :name => name,
      :config => {
        :provider => "spatial",
        :geometry_type => type || "point",
        :lat => lat || "lat",
        :lon => lon || "lon"
        }
    }
  end
end
batch_create_unique_node(index, key, value, properties) click to toggle source
# File lib/neography/rest/batch.rb, line 77
def batch_create_unique_node(index, key, value, properties)
  post "/index/node/%{index}?unique" % {:index => index} do
    {
      :key        => key,
      :value      => value,
      :properties => properties
    }
  end
end
batch_create_unique_relationship(index, key, value, type, from, to, props = nil) click to toggle source

RelationshipIndexes

# File lib/neography/rest/batch.rb, line 174
def batch_create_unique_relationship(index, key, value, type, from, to, props = nil)
  post "/index/relationship/%{index}?unique" % {:index => index} do
    {
      :key   => key,
      :value => value,
      :type  => type,
      :start => build_node_uri(from),
      :end   => build_node_uri(to),
      :properties => props
    }
  end
end
batch_delete_node(id) click to toggle source
# File lib/neography/rest/batch.rb, line 48
def batch_delete_node(id)
  delete "/node/%{id}" % {:id => get_id(id)}
end
batch_delete_relationship(id) click to toggle source
# File lib/neography/rest/batch.rb, line 158
def batch_delete_relationship(id)
  delete "/relationship/%{id}" % {:id => get_id(id)}
end
batch_drop_node_index(index) click to toggle source
# File lib/neography/rest/batch.rb, line 73
def batch_drop_node_index(index)
  delete "/index/node/%{index}?unique" % {:index => index}
end
batch_edit_geometry_from_layer(layer, geometry, node) click to toggle source
# File lib/neography/rest/batch.rb, line 299
def batch_edit_geometry_from_layer(layer, geometry, node)
  post "/ext/SpatialPlugin/graphdb/updateGeometryFromWKT" do 
    {
        :layer => layer,
        :geometry => geometry,
        :geometryNodeId => get_id(node)
      }
  end
end
batch_execute_query(query, params = nil) click to toggle source

Cypher

# File lib/neography/rest/batch.rb, line 221
def batch_execute_query(query, params = nil)
  request = post @connection.cypher_path do
    {
      :query => query
    }
  end

  request[:body].merge!({ :params => params }) if params

  request
end
batch_execute_script(script, params = nil) click to toggle source

Gremlin

# File lib/neography/rest/batch.rb, line 235
def batch_execute_script(script, params = nil)
  post @connection.gremlin_path do
    {
      :script => script,
      :params => params
    }
  end
end
batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy) click to toggle source
# File lib/neography/rest/batch.rb, line 318
def batch_find_geometries_in_bbox(layer, minx, maxx, miny, maxy)
  post "/ext/SpatialPlugin/graphdb/findGeometriesInBBox" do 
    {
        :layer => layer,
        :minx => minx,
        :maxx => maxx,
        :miny => miny,
        :maxy => maxy
      }
  end
end
batch_find_geometries_within_distance(layer, pointx, pointy, distance) click to toggle source
# File lib/neography/rest/batch.rb, line 330
def batch_find_geometries_within_distance(layer, pointx, pointy, distance)
  post "/ext/SpatialPlugin/graphdb/findGeometriesWithinDistance" do 
    {
        :layer => layer,
        :pointX => pointx,
        :pointY => pointy,
        :distanceInKm => distance
      }
  end
end
batch_get_layer(layer) click to toggle source
# File lib/neography/rest/batch.rb, line 282
def batch_get_layer(layer)
  post "/ext/SpatialPlugin/graphdb/getLayer" do
    {
        :layer => layer
      }
  end
end
batch_get_node(id) click to toggle source

Nodes

# File lib/neography/rest/batch.rb, line 44
def batch_get_node(id)
  get "/node/%{id}" % {:id => get_id(id)}
end
batch_get_node_index(index, key, value) click to toggle source
# File lib/neography/rest/batch.rb, line 108
def batch_get_node_index(index, key, value)
  get "/index/node/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
end
batch_get_node_relationships(id, direction = nil, types = nil) click to toggle source

NodeRelationships

# File lib/neography/rest/batch.rb, line 144
def batch_get_node_relationships(id, direction = nil, types = nil)
  if types.nil?
    get "/node/%{id}/relationships/%{direction}" % {:id => get_id(id), :direction => direction || 'all'}
  else
    get "/node/%{id}/relationships/%{direction}/%{types}" % {:id => get_id(id), :direction => direction, :types => Array(types).join('&')}
  end
end
batch_get_relationship(id) click to toggle source

Relationships

# File lib/neography/rest/batch.rb, line 154
def batch_get_relationship(id)
  get "/relationship/%{id}" % {:id => get_id(id)}
end
batch_get_relationship_index(index, key, value) click to toggle source
# File lib/neography/rest/batch.rb, line 197
def batch_get_relationship_index(index, key, value)
  get "/index/relationship/%{index}/%{key}/%{value}" % {:index => index, :key => key, :value => encode(value)}
end
batch_get_spatial() click to toggle source

Spatial

# File lib/neography/rest/batch.rb, line 258
def batch_get_spatial
  get "/ext/SpatialPlugin"
end
batch_remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil) click to toggle source
# File lib/neography/rest/batch.rb, line 112
def batch_remove_node_from_index(index, key_or_id, value_or_id = nil, id = nil)
  delete remove_from_index_path("node", index, key_or_id, value_or_id, id)
end
batch_remove_node_property(id, property) click to toggle source
# File lib/neography/rest/batch.rb, line 130
def batch_remove_node_property(id, property)
  delete "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property}
end
batch_remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil) click to toggle source
# File lib/neography/rest/batch.rb, line 201
def batch_remove_relationship_from_index(index, key_or_id, value_or_id = nil, id = nil)
  delete remove_from_index_path("relationship", index, key_or_id, value_or_id, id)
end
batch_reset_node_properties(id, body) click to toggle source
# File lib/neography/rest/batch.rb, line 124
def batch_reset_node_properties(id, body)
  put "/node/%{id}/properties" % {:id => get_id(id)} do
    body
  end
end
batch_reset_relationship_properties(id, body) click to toggle source
# File lib/neography/rest/batch.rb, line 213
def batch_reset_relationship_properties(id, body)
  put build_relationship_uri(id) + "/properties" do
    body
  end
end
batch_set_node_property(id, property) click to toggle source

NodeProperties

# File lib/neography/rest/batch.rb, line 118
def batch_set_node_property(id, property)
  put "/node/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
    property.values.first
  end
end
batch_set_relationship_property(id, property) click to toggle source

RelationshipProperties

# File lib/neography/rest/batch.rb, line 207
def batch_set_relationship_property(id, property)
  put "/relationship/%{id}/properties/%{property}" % {:id => get_id(id), :property => property.keys.first} do
    property.values.first
  end
end
build_node_uri(value) click to toggle source

Helper methods

# File lib/neography/rest/batch.rb, line 392
def build_node_uri(value)
  build_uri(value, "node")
end
build_relationship_uri(value) click to toggle source
# File lib/neography/rest/batch.rb, line 396
def build_relationship_uri(value)
  build_uri(value, "relationship")
end
build_uri(value, type) click to toggle source
# File lib/neography/rest/batch.rb, line 400
def build_uri(value, type)
  path_or_variable(value, type) + "#{get_id(value)}"
end
compute_batch_options(*args) click to toggle source
# File lib/neography/rest/batch.rb, line 26
def compute_batch_options(*args)
  batch = []
  Array(args).each_with_index do |c, i|
    batch << {:id => i }.merge(get_batch(c))
  end
  {:body => batch.to_json, :headers => json_content_type}
end
delete(to, &block) click to toggle source
# File lib/neography/rest/batch.rb, line 369
def delete(to, &block)
  request "DELETE", to, &block
end
do_batch(*args) click to toggle source
# File lib/neography/rest/batch.rb, line 16
def do_batch(*args)
  @connection.post("/batch", compute_batch_options(*args))
end
do_batch_no_streaming(*args) click to toggle source
# File lib/neography/rest/batch.rb, line 20
def do_batch_no_streaming(*args)
  options = compute_batch_options(*args)
  options[:headers].merge!({ 'X-Stream' => false })
  @connection.post("/batch", options)
end
get(to, &block) click to toggle source
# File lib/neography/rest/batch.rb, line 365
def get(to, &block)
  request "GET", to, &block
end
get_batch(args) click to toggle source
# File lib/neography/rest/batch.rb, line 34
def get_batch(args)
  begin
    send("batch_#{args[0]}".to_sym, *args[1..-1])
  rescue
    raise UnknownBatchOptionException.new("Unknown option #{args[0]} - #{args}")
  end
end
path_or_variable(value, type) click to toggle source
# File lib/neography/rest/batch.rb, line 404
def path_or_variable(value, type)
  if value.is_a?(String) && value.start_with?("{")
    ""
  else
    "/#{type}/"
  end
end
post(to, &block) click to toggle source
# File lib/neography/rest/batch.rb, line 373
def post(to, &block)
  request "POST", to, &block
end
put(to, &block) click to toggle source
# File lib/neography/rest/batch.rb, line 377
def put(to, &block)
  request "PUT", to, &block
end
remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil) click to toggle source

Similar between nodes and relationships

# File lib/neography/rest/batch.rb, line 246
def remove_from_index_path(klass, index, key_or_id, value_or_id = nil, id = nil)
  if id
    "/index/#{klass}/%{index}/%{key}/%{value}/%{id}" % {:index => index, :key => key_or_id, :value => value_or_id, :id => get_id(id)}
  elsif value_or_id
    "/index/#{klass}/%{index}/%{key}/%{id}" % {:index => index, :key => key_or_id, :id => get_id(value_or_id)}
  else
    "/index/#{klass}/%{index}/%{id}" % {:index => index, :id => get_id(key_or_id)}
  end
end
request(method, to) { || ... } click to toggle source
# File lib/neography/rest/batch.rb, line 381
def request(method, to, &block)
  request = {
    :method => method,
    :to     => to
  }
  request.merge!({ :body => yield }) if block_given?
  request
end