From 3b9e97fe3d5dda5a906c0f4ed7cdf42028d42bf3 Mon Sep 17 00:00:00 2001 From: Roel van Dijk Date: Sat, 8 Sep 2012 16:12:22 +0200 Subject: [PATCH] Add _path suffix in all REST classes. --- lib/neography/rest/batch.rb | 2 +- lib/neography/rest/clean.rb | 2 +- lib/neography/rest/node_auto_indexes.rb | 16 +++++++-------- lib/neography/rest/node_indexes.rb | 20 +++++++++---------- lib/neography/rest/node_paths.rb | 6 +++--- lib/neography/rest/node_properties.rb | 12 +++++------ lib/neography/rest/node_relationships.rb | 6 +++--- lib/neography/rest/node_traversal.rb | 2 +- lib/neography/rest/nodes.rb | 14 ++++++------- .../rest/relationship_auto_indexes.rb | 16 +++++++-------- lib/neography/rest/relationship_indexes.rb | 20 +++++++++---------- lib/neography/rest/relationship_properties.rb | 12 +++++------ lib/neography/rest/relationships.rb | 4 ++-- lib/neography/rest_paths.rb | 2 +- 14 files changed, 67 insertions(+), 67 deletions(-) diff --git a/lib/neography/rest/batch.rb b/lib/neography/rest/batch.rb index 6aec6c9..445ad0e 100644 --- a/lib/neography/rest/batch.rb +++ b/lib/neography/rest/batch.rb @@ -4,7 +4,7 @@ class Batch include Neography::Rest::Paths include Neography::Rest::Helpers - add_path :batch_path, "/batch" + add_path :batch, "/batch" def initialize(connection) @connection = connection diff --git a/lib/neography/rest/clean.rb b/lib/neography/rest/clean.rb index ca16fc3..5dfd686 100644 --- a/lib/neography/rest/clean.rb +++ b/lib/neography/rest/clean.rb @@ -12,7 +12,7 @@ def initialize(connection) def execute - @connection.delete(clean) + @connection.delete(clean_path) end end diff --git a/lib/neography/rest/node_auto_indexes.rb b/lib/neography/rest/node_auto_indexes.rb index 6e28001..e68afb8 100644 --- a/lib/neography/rest/node_auto_indexes.rb +++ b/lib/neography/rest/node_auto_indexes.rb @@ -15,21 +15,21 @@ def initialize(connection) end def get(key, value) - index = @connection.get(key_value(:key => key, :value => value)) || Array.new + index = @connection.get(key_value_path(:key => key, :value => value)) || Array.new return nil if index.empty? index end def find(key, value) - @connection.get(key_value(:key => key, :value => value)) || Array.new + @connection.get(key_value_path(:key => key, :value => value)) || Array.new end def query(query_expression) - @connection.get(query_index(:query => query_expression)) || Array.new + @connection.get(query_index_path(:query => query_expression)) || Array.new end def status - @connection.get(index_status) + @connection.get(index_status_path) end def status=(value) @@ -37,11 +37,11 @@ def status=(value) :body => value.to_json, :headers => json_content_type } - @connection.put(index_status, options) + @connection.put(index_status_path, options) end def properties - @connection.get(index_properties) + @connection.get(index_properties_path) end def add_property(property) @@ -49,11 +49,11 @@ def add_property(property) :body => property, :headers => json_content_type } - @connection.post(index_properties, options) + @connection.post(index_properties_path, options) end def remove_property(property) - @connection.delete(index_property(:property => property)) + @connection.delete(index_property_path(:property => property)) end end diff --git a/lib/neography/rest/node_indexes.rb b/lib/neography/rest/node_indexes.rb index 83ff40d..9d2130b 100644 --- a/lib/neography/rest/node_indexes.rb +++ b/lib/neography/rest/node_indexes.rb @@ -20,7 +20,7 @@ def initialize(connection) end def list - @connection.get(all) + @connection.get(all_path) end def create(name, type, provider) @@ -35,7 +35,7 @@ def create(name, type, provider) ).to_json, :headers => json_content_type } - @connection.post(all, options) + @connection.post(all_path, options) end def create_auto(type, provider) @@ -52,7 +52,7 @@ def create_unique(index, key, value, props) ).to_json, :headers => json_content_type } - @connection.post(unique(:index => index), options) + @connection.post(unique_path(:index => index), options) end def add(index, key, value, id) @@ -65,34 +65,34 @@ def add(index, key, value, id) ).to_json, :headers => json_content_type } - @connection.post(base(:index => index), options) + @connection.post(base_path(:index => index), options) end def get(index, key, value) - index = @connection.get(key_value(:index => index, :key => key, :value => value)) || Array.new + index = @connection.get(key_value_path(:index => index, :key => key, :value => value)) || Array.new return nil if index.empty? index end # TODO FIX BUG %20 def find_by_value(index, key, value) - @connection.get(key_value2(:index => index, :key => key, :value => value)) || Array.new + @connection.get(key_value2_path(:index => index, :key => key, :value => value)) || Array.new end def find_by_query(index, query) - @connection.get(query(:index => index, :query => query)) || Array.new + @connection.get(query_path(:index => index, :query => query)) || Array.new end def remove(index, id) - @connection.delete(node(:index => index, :id => get_id(id))) + @connection.delete(node_path(:index => index, :id => get_id(id))) end def remove_by_key(index, id, key) - @connection.delete(key(:index => index, :id => get_id(id), :key => key)) + @connection.delete(key_path(:index => index, :id => get_id(id), :key => key)) end def remove_by_value(index, id, key, value) - @connection.delete(value(:index => index, :id => get_id(id), :key => key, :value => value)) + @connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value)) end end diff --git a/lib/neography/rest/node_paths.rb b/lib/neography/rest/node_paths.rb index 9f2dee5..28ddb58 100644 --- a/lib/neography/rest/node_paths.rb +++ b/lib/neography/rest/node_paths.rb @@ -20,7 +20,7 @@ def get(from, to, relationships, depth, algorithm) }.to_json, :headers => json_content_type } - @connection.post(base(:id => get_id(from)), options) || Hash.new + @connection.post(base_path(:id => get_id(from)), options) || Hash.new end def get_all(from, to, relationships, depth, algorithm) @@ -32,7 +32,7 @@ def get_all(from, to, relationships, depth, algorithm) }.to_json, :headers => json_content_type } - @connection.post(all(:id => get_id(from)), options) || Array.new + @connection.post(all_path(:id => get_id(from)), options) || Array.new end def shortest_weighted(from, to, relationships, weight_attribute, depth, algorithm) @@ -45,7 +45,7 @@ def shortest_weighted(from, to, relationships, weight_attribute, depth, algorith }.to_json, :headers => json_content_type } - @connection.post(all(:id => get_id(from)), options) || Hash.new + @connection.post(all_path(:id => get_id(from)), options) || Hash.new end private diff --git a/lib/neography/rest/node_properties.rb b/lib/neography/rest/node_properties.rb index b2dca28..f5480b8 100644 --- a/lib/neography/rest/node_properties.rb +++ b/lib/neography/rest/node_properties.rb @@ -13,12 +13,12 @@ def initialize(connection) def reset(id, properties) options = { :body => properties.to_json, :headers => json_content_type } - @connection.put(all(:id => get_id(id)), options) + @connection.put(all_path(:id => get_id(id)), options) end def get(id, *properties) if properties.none? - @connection.get(all(:id => get_id(id))) + @connection.get(all_path(:id => get_id(id))) else get_each(id, *properties) end @@ -26,7 +26,7 @@ def get(id, *properties) def get_each(id, *properties) node_properties = properties.inject({}) do |memo, property| - value = @connection.get(single(:id => get_id(id), :property => property)) + value = @connection.get(single_path(:id => get_id(id), :property => property)) memo[property] = value unless value.nil? memo end @@ -36,7 +36,7 @@ def get_each(id, *properties) def remove(id, *properties) if properties.none? - @connection.delete(all(:id => get_id(id))) + @connection.delete(all_path(:id => get_id(id))) else remove_each(id, *properties) end @@ -44,14 +44,14 @@ def remove(id, *properties) def remove_each(id, *properties) properties.each do |property| - @connection.delete(single(:id => get_id(id), :property => property)) + @connection.delete(single_path(:id => get_id(id), :property => property)) end end def set(id, properties) properties.each do |property, value| options = { :body => value.to_json, :headers => json_content_type } - @connection.put(single(:id => get_id(id), :property => property), options) + @connection.put(single_path(:id => get_id(id), :property => property), options) end end diff --git a/lib/neography/rest/node_relationships.rb b/lib/neography/rest/node_relationships.rb index d00e22f..76bf047 100644 --- a/lib/neography/rest/node_relationships.rb +++ b/lib/neography/rest/node_relationships.rb @@ -21,16 +21,16 @@ def create(type, from, to, props) }.to_json, :headers => json_content_type } - @connection.post(base(:id => get_id(from)), options) + @connection.post(base_path(:id => get_id(from)), options) end def get(id, direction, types) direction = get_direction(direction) if types.nil? - node_relationships = @connection.get(direction(:id => get_id(id), :direction => direction)) || Array.new + node_relationships = @connection.get(direction_path(:id => get_id(id), :direction => direction)) || Array.new else - node_relationships = @connection.get(type(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || Array.new + node_relationships = @connection.get(type_path(:id => get_id(id), :direction => direction, :types => Array(types).join('&'))) || Array.new end return nil if node_relationships.empty? node_relationships diff --git a/lib/neography/rest/node_traversal.rb b/lib/neography/rest/node_traversal.rb index fe3c542..6cbd2ff 100644 --- a/lib/neography/rest/node_traversal.rb +++ b/lib/neography/rest/node_traversal.rb @@ -24,7 +24,7 @@ def traverse(id, return_type, description) type = get_type(return_type) - @connection.post(traversal(:id => get_id(id), :type => type), options) || Array.new + @connection.post(traversal_path(:id => get_id(id), :type => type), options) || Array.new end private diff --git a/lib/neography/rest/nodes.rb b/lib/neography/rest/nodes.rb index acecf26..abd0bd7 100644 --- a/lib/neography/rest/nodes.rb +++ b/lib/neography/rest/nodes.rb @@ -12,7 +12,7 @@ def initialize(connection) end def get(id) - @connection.get(base(:id => get_id(id))) + @connection.get(base_path(:id => get_id(id))) end def get_each(*nodes) @@ -25,7 +25,7 @@ def get_each(*nodes) def root root_node = @connection.get('/')["reference_node"] - @connection.get("/node/#{get_id(root_node)}") + @connection.get(base_path(:id => get_id(root_node))) end def create(*args) @@ -41,11 +41,11 @@ def create_with_attributes(attributes) :body => attributes.delete_if { |k, v| v.nil? }.to_json, :headers => json_content_type } - @connection.post(index, options) + @connection.post(index_path, options) end def create_empty - @connection.post(index) + @connection.post(index_path) end def create_multiple(nodes) @@ -73,12 +73,12 @@ def create_multiple_threaded(nodes) until node_queue.empty? do node = node_queue.pop if node.respond_to?(:each_pair) - responses.push( @connection.post(index, { + responses.push( @connection.post(index_path, { :body => node.to_json, :headers => json_content_type } ) ) else - responses.push( @connection.post(index) ) + responses.push( @connection.post(index_path) ) end end self.join @@ -94,7 +94,7 @@ def create_multiple_threaded(nodes) end def delete(id) - @connection.delete(base(:id => get_id(id))) + @connection.delete(base_path(:id => get_id(id))) end end diff --git a/lib/neography/rest/relationship_auto_indexes.rb b/lib/neography/rest/relationship_auto_indexes.rb index c4d55c2..04393b2 100644 --- a/lib/neography/rest/relationship_auto_indexes.rb +++ b/lib/neography/rest/relationship_auto_indexes.rb @@ -15,21 +15,21 @@ def initialize(connection) end def get(key, value) - index = @connection.get(key_value(:key => key, :value => value)) || Array.new + index = @connection.get(key_value_path(:key => key, :value => value)) || Array.new return nil if index.empty? index end def find(key, value) - @connection.get(key_value(:key => key, :value => value)) || Array.new + @connection.get(key_value_path(:key => key, :value => value)) || Array.new end def query(query_expression) - @connection.get(query_index(:query => query_expression)) || Array.new + @connection.get(query_index_path(:query => query_expression)) || Array.new end def status - @connection.get(index_status) + @connection.get(index_status_path) end def status=(value) @@ -37,11 +37,11 @@ def status=(value) :body => value.to_json, :headers => json_content_type } - @connection.put(index_status, options) + @connection.put(index_status_path, options) end def properties - @connection.get(index_properties) + @connection.get(index_properties_path) end def add_property(property) @@ -49,11 +49,11 @@ def add_property(property) :body => property, :headers => json_content_type } - @connection.post(index_properties, options) + @connection.post(index_properties_path, options) end def remove_property(property) - @connection.delete(index_property(:property => property)) + @connection.delete(index_property_path(:property => property)) end end diff --git a/lib/neography/rest/relationship_indexes.rb b/lib/neography/rest/relationship_indexes.rb index 58bd798..676f033 100644 --- a/lib/neography/rest/relationship_indexes.rb +++ b/lib/neography/rest/relationship_indexes.rb @@ -21,7 +21,7 @@ def initialize(connection) end def list - @connection.get(all) + @connection.get(all_path) end def create(name, type, provider) @@ -36,7 +36,7 @@ def create(name, type, provider) ).to_json, :headers => json_content_type } - @connection.post(all, options) + @connection.post(all_path, options) end def create_auto(type, provider) @@ -53,7 +53,7 @@ def create_unique(index, key, value, type, from, to) } options = { :body => body.to_json, :headers => json_content_type } - @connection.post(unique(:index => index), options) + @connection.post(unique_path(:index => index), options) end def add(index, key, value, id) @@ -67,33 +67,33 @@ def add(index, key, value, id) :headers => json_content_type } - @connection.post(base(:index => index), options) + @connection.post(base_path(:index => index), options) end def get(index, key, value) - index = @connection.get(key_value(:index => index, :key => key, :value => value)) || Array.new + index = @connection.get(key_value_path(:index => index, :key => key, :value => value)) || Array.new return nil if index.empty? index end def find_by_key_query(index, key, query) - @connection.get(key_query(:index => index, :key => key, :query => query)) || Array.new + @connection.get(key_query_path(:index => index, :key => key, :query => query)) || Array.new end def find_by_query(index, query) - @connection.get(query(:index => index, :query => query)) || Array.new + @connection.get(query_path(:index => index, :query => query)) || Array.new end def remove(index, id) - @connection.delete(relationship(:index => index, :id => get_id(id))) + @connection.delete(relationship_path(:index => index, :id => get_id(id))) end def remove_by_key(index, id, key) - @connection.delete(key(:index => index, :id => get_id(id), :key => key)) + @connection.delete(key_path(:index => index, :id => get_id(id), :key => key)) end def remove_by_value(index, id, key, value) - @connection.delete(value(:index => index, :id => get_id(id), :key => key, :value => value)) + @connection.delete(value_path(:index => index, :id => get_id(id), :key => key, :value => value)) end end diff --git a/lib/neography/rest/relationship_properties.rb b/lib/neography/rest/relationship_properties.rb index a8521fe..0821eb2 100644 --- a/lib/neography/rest/relationship_properties.rb +++ b/lib/neography/rest/relationship_properties.rb @@ -13,11 +13,11 @@ def initialize(connection) def get(id, properties) if properties.nil? - @connection.get(all(:id => get_id(id))) + @connection.get(all_path(:id => get_id(id))) else relationship_properties = Hash.new Array(properties).each do |property| - value = @connection.get(single(:id => get_id(id), :property => property)) + value = @connection.get(single_path(:id => get_id(id), :property => property)) relationship_properties[property] = value unless value.nil? end return nil if relationship_properties.empty? @@ -27,15 +27,15 @@ def get(id, properties) def reset(id, properties) options = { :body => properties.to_json, :headers => json_content_type } - @connection.put(all(:id => get_id(id)), options) + @connection.put(all_path(:id => get_id(id)), options) end def remove(id, properties) if properties.nil? - @connection.delete(all(id: get_id(id))) + @connection.delete(all_path(id: get_id(id))) else Array(properties).each do |property| - @connection.delete(single(:id => get_id(id), :property => property)) + @connection.delete(single_path(:id => get_id(id), :property => property)) end end end @@ -43,7 +43,7 @@ def remove(id, properties) def set(id, properties) properties.each do |key, value| options = { :body => value.to_json, :headers => json_content_type } - @connection.put(single(:id => get_id(id), :property => key), options) + @connection.put(single_path(:id => get_id(id), :property => key), options) end end diff --git a/lib/neography/rest/relationships.rb b/lib/neography/rest/relationships.rb index 9e7fd58..43cfa17 100644 --- a/lib/neography/rest/relationships.rb +++ b/lib/neography/rest/relationships.rb @@ -11,11 +11,11 @@ def initialize(connection) end def get(id) - @connection.get(base(:id => get_id(id))) + @connection.get(base_path(:id => get_id(id))) end def delete(id) - @connection.delete(base(:id => get_id(id))) + @connection.delete(base_path(:id => get_id(id))) end end diff --git a/lib/neography/rest_paths.rb b/lib/neography/rest_paths.rb index aae6efa..ba73c9e 100644 --- a/lib/neography/rest_paths.rb +++ b/lib/neography/rest_paths.rb @@ -14,7 +14,7 @@ def build_path(path, attributes) module ClassMethods def add_path(key, path) - define_method key do |*attributes| + define_method :"#{key}_path" do |*attributes| if attributes.any? build_path(path, *attributes) else