Skip to content

Commit

Permalink
clean up a little code
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 16, 2013
1 parent ae830d8 commit b921317
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 46 deletions.
25 changes: 6 additions & 19 deletions lib/neography/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions lib/neography/path_traverser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
12 changes: 12 additions & 0 deletions lib/neography/rest/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 0 additions & 11 deletions lib/neography/rest/node_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 1 addition & 12 deletions lib/neography/rest/other_node_relationships.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b921317

Please sign in to comment.