diff --git a/lib/neography/connection.rb b/lib/neography/connection.rb index 60c456e..c7dde90 100644 --- a/lib/neography/connection.rb +++ b/lib/neography/connection.rb @@ -47,23 +47,6 @@ def post(path, options={}) evaluate_response(@client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers])) end - def post_chunked(path, options={}) - authenticate(configuration + path) - result = "" - - response = @client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]) do |chunk| - result << chunk - end - - r = evaluate_chunk_response(response, result) - - if r.last["status"] > 399 - handle_4xx_500_response(r.last["status"], r.last["body"] || r.last ) - end - - r - end - def put(path, options={}) authenticate(configuration + path) evaluate_response(@client.put(configuration + path, merge_options(options)[:body], merge_options(options)[:headers])) @@ -185,10 +168,13 @@ def handle_4xx_500_response(code, body) stacktrace = parsed_body["stacktrace"] @logger.error "#{code} error: #{body}" if @log_enabled - + raise_errors(code, parsed_body["exception"], message, stacktrace) + end + + def raise_errors(code, exception, message, stacktrace) case code when 400, 404 - case parsed_body["exception"] + case exception when /SyntaxException/ ; raise SyntaxException.new(message, code, stacktrace) when /this is not a query/ ; raise SyntaxException.new(message, code, stacktrace) when /PropertyValueException/ ; raise PropertyValueException.new(message, code, stacktrace) @@ -208,6 +194,7 @@ def handle_4xx_500_response(code, body) else raise NeographyError.new(message, code, stacktrace) end + end def parse_string_options(options) diff --git a/lib/neography/path_traverser.rb b/lib/neography/path_traverser.rb index 56f55b0..fbc5937 100644 --- a/lib/neography/path_traverser.rb +++ b/lib/neography/path_traverser.rb @@ -63,15 +63,15 @@ def each if @get.include?("node") path["nodes"].each_with_index do |n, i| - @loaded_nodes[n.split('/').last.to_i] = Neography::Node.load(n) if @loaded_nodes.at(n.split('/').last.to_i).nil? - paths[i * 2] = @loaded_nodes[n.split('/').last.to_i] + @loaded_nodes[get_id(n)] = Neography::Node.load(n) if @loaded_nodes.at(get_id(n)).nil? + paths[i * 2] = @loaded_nodes[get_id(n)] end end if @get.include?("rel") path["relationships"].each_with_index do |r, i| - @loaded_rels[r.split('/').last.to_i] = Neography::Relationship.load(r) if @loaded_rels.at(r.split('/').last.to_i).nil? - paths[i * 2 + 1] = @loaded_rels[r.split('/').last.to_i] + @loaded_rels[get_id(r)] = Neography::Relationship.load(r) if @loaded_rels.at(get_id(r)).nil? + paths[i * 2 + 1] = @loaded_rels[get_id(r)] end end @@ -90,6 +90,11 @@ def iterator @from.neo_server.get_paths(@from, @to, @relationships, @depth, @algorithm) end end + + private + def get_id(object) + object.split('/').last.to_i + end end end \ No newline at end of file diff --git a/lib/neography/rest/helpers.rb b/lib/neography/rest/helpers.rb index cf4b398..78443a7 100644 --- a/lib/neography/rest/helpers.rb +++ b/lib/neography/rest/helpers.rb @@ -21,6 +21,18 @@ def json_content_type {'Content-Type' => 'application/json'} end + def parse_direction(direction) + case direction + when :incoming, "incoming", :in, "in" + "in" + when :outgoing, "outgoing", :out, "out" + "out" + else + "all" + end + end + + end end end diff --git a/lib/neography/rest/node_relationships.rb b/lib/neography/rest/node_relationships.rb index 57240d3..33fa68a 100644 --- a/lib/neography/rest/node_relationships.rb +++ b/lib/neography/rest/node_relationships.rb @@ -37,17 +37,6 @@ def get(id, direction = nil, types = nil) node_relationships end - def parse_direction(direction) - case direction - when :incoming, "incoming", :in, "in" - "in" - when :outgoing, "outgoing", :out, "out" - "out" - else - "all" - end - end - end end end diff --git a/lib/neography/rest/other_node_relationships.rb b/lib/neography/rest/other_node_relationships.rb index a99b960..a2d8c8d 100644 --- a/lib/neography/rest/other_node_relationships.rb +++ b/lib/neography/rest/other_node_relationships.rb @@ -36,24 +36,13 @@ def get(id, other_id, direction = "all", types = [nil]) }.merge(relationships).to_json, :headers => json_content_type } - #puts options.inspect + node_relationships = @connection.post(base_path(:id => get_id(id)), options) || [] return nil if node_relationships.empty? node_relationships end - def parse_direction(direction) - case direction - when :incoming, "incoming", :in, "in" - "in" - when :outgoing, "outgoing", :out, "out" - "out" - else - "all" - end - end - end end end