class Neo4j::Core::CypherSession::Responses::HTTP

Attributes

request_data[R]
results[R]

Public Class Methods

new(faraday_response, options = {}) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
10 def initialize(faraday_response, options = {})
11   @faraday_response = faraday_response
12   @request_data = request_data
13 
14   validate_faraday_response!(faraday_response)
15 
16   @wrap_level = options[:wrap_level] || Neo4j::Core::Config.wrapping_level
17 
18   @results = faraday_response.body[:results].map do |result_data|
19     result_from_data(result_data[:columns], result_data[:data])
20   end
21 end

Public Instance Methods

result_from_data(columns, entities_data) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
23 def result_from_data(columns, entities_data)
24   rows = entities_data.map do |entity_data|
25     wrap_entity entity_data[:row], entity_data[:rest]
26   end
27 
28   Result.new(columns, rows)
29 end
wrap_entity(row_datum, rest_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
31 def wrap_entity(row_datum, rest_datum)
32   if rest_datum.is_a?(Array)
33     row_datum.zip(rest_datum).map { |row, rest| wrap_entity(row, rest) }
34   elsif ident = identify_entity(rest_datum)
35     send("wrap_#{ident}", rest_datum, row_datum)
36   elsif rest_datum.is_a?(Hash)
37     rest_datum.each_with_object({}) do |(k, v), result|
38       result[k.to_sym] = wrap_entity(row_datum[k], v)
39     end
40   else
41     row_datum
42   end
43 end

Private Instance Methods

id_from_rest_datum(rest_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
91 def id_from_rest_datum(rest_datum)
92   if rest_datum[:metadata]
93     rest_datum[:metadata][:id]
94   else
95     id_from_url(rest_datum[:self])
96   end
97 end
id_from_url(url) click to toggle source
    # File lib/neo4j/core/cypher_session/responses/http.rb
 99 def id_from_url(url)
100   url.split('/').last.to_i
101 end
identify_entity(rest_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
47 def identify_entity(rest_datum)
48   return if !rest_datum.is_a?(Hash)
49   self_string = rest_datum[:self]
50   if self_string
51     type = self_string.split('/')[-2]
52     type.to_sym if %w[node relationship].include?(type)
53   elsif %i[nodes relationships start end length].all? { |k| rest_datum.key?(k) }
54     :path
55   end
56 end
validate_faraday_response!(faraday_response) click to toggle source
    # File lib/neo4j/core/cypher_session/responses/http.rb
103 def validate_faraday_response!(faraday_response)
104   if faraday_response.body.is_a?(Hash) && error = faraday_response.body[:errors][0]
105     fail CypherError.new_from(error[:code], error[:message], error[:stack_trace])
106   end
107 
108   return if (200..299).cover?(status = faraday_response.status)
109 
110   fail CypherError, "Expected 200-series response for #{faraday_response.env.url} (got #{status})"
111 end
wrap_node(rest_datum, row_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
58 def wrap_node(rest_datum, row_datum)
59   wrap_by_level(row_datum) do
60     metadata_data = rest_datum[:metadata]
61     ::Neo4j::Core::Node.new(id_from_rest_datum(rest_datum),
62                             metadata_data && metadata_data[:labels],
63                             rest_datum[:data])
64   end
65 end
wrap_path(rest_datum, row_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
78 def wrap_path(rest_datum, row_datum)
79   wrap_by_level(row_datum) do
80     nodes = rest_datum[:nodes].each_with_index.map do |url, i|
81       Node.from_url(url, row_datum[2 * i])
82     end
83     relationships = rest_datum[:relationships].each_with_index.map do |url, i|
84       Relationship.from_url(url, row_datum[(2 * i) + 1])
85     end
86 
87     ::Neo4j::Core::Path.new(nodes, relationships, rest_datum[:directions])
88   end
89 end
wrap_relationship(rest_datum, row_datum) click to toggle source
   # File lib/neo4j/core/cypher_session/responses/http.rb
67 def wrap_relationship(rest_datum, row_datum)
68   wrap_by_level(row_datum) do
69     metadata_data = rest_datum[:metadata]
70     ::Neo4j::Core::Relationship.new(id_from_rest_datum(rest_datum),
71                                     metadata_data && metadata_data[:type],
72                                     rest_datum[:data],
73                                     id_from_url(rest_datum[:start]),
74                                     id_from_url(rest_datum[:end]))
75   end
76 end