Class: Neo4j::Core::CypherSession::Adaptors::HTTP

Inherits:
Base
  • Object
show all
Defined in:
lib/neo4j/core/cypher_session/adaptors/http.rb

Defined Under Namespace

Classes: Requestor

Constant Summary collapse

ROW_REST =
%w(row REST)
CONSTRAINT_TYPES =
{
  'UNIQUENESS' => :uniqueness
}

Constants inherited from Base

Base::EMPTY, Base::NEWLINE_W_SPACES, Base::USER_AGENT_STRING

Instance Attribute Summary collapse

Attributes inherited from Base

#wrap_level

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

instrument_queries, #logger, #queries, #query, #setup_queries!, #transaction

Methods included from Instrumentable

included

Constructor Details

#initialize(url, options = {}) ⇒ HTTP

Returns a new instance of HTTP.



13
14
15
16
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 13

def initialize(url, options = {})
  @url = url
  @options = options
end

Instance Attribute Details

#requestorObject (readonly)

Returns the value of attribute requestor.



11
12
13
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 11

def requestor
  @requestor
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 11

def url
  @url
end

Class Method Details

.transaction_classObject



69
70
71
72
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 69

def self.transaction_class
  require 'neo4j/core/cypher_session/transactions/http'
  Neo4j::Core::CypherSession::Transactions::HTTP
end

Instance Method Details

#connectObject



18
19
20
21
22
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 18

def connect
  @requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request))
rescue Faraday::ConnectionFailed => e
  raise CypherSession::ConnectionFailedError, "#{e.class}: #{e.message}"
end

#connected?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 85

def connected?
  !!@requestor
end

#constraints(_session, _label = nil, _options = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 58

def constraints(_session, _label = nil, _options = {})
  response = @requestor.get('db/data/schema/constraint')

  list = response.body || []
  list.map do |item|
    {type: CONSTRAINT_TYPES[item[:type]],
     label: item[:label].to_sym,
     properties: item[:property_keys].map(&:to_sym)}
  end
end

#indexes(_session) ⇒ Object

Schema inspection methods



44
45
46
47
48
49
50
51
52
53
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 44

def indexes(_session)
  response = @requestor.get('db/data/schema/index')

  list = response.body || []

  list.map do |item|
    {label: item[:label].to_sym,
     properties: item[:property_keys].map(&:to_sym)}
  end
end

#indexes_for_label(label) ⇒ Object

Schema inspection methods



75
76
77
78
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 75

def indexes_for_label(label)
  url = db_data_url + "schema/index/#{label}"
  @connection.get(url)
end

#query_set(transaction, queries, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 26

def query_set(transaction, queries, options = {})
  setup_queries!(queries, transaction)

  return unless path = transaction.query_path(options.delete(:commit))

  faraday_response = @requestor.post(path, queries)

  transaction.apply_id_from_url!(faraday_response.env[:response_headers][:location])

  wrap_level = options[:wrap_level] || @options[:wrap_level]
  Responses::HTTP.new(faraday_response, wrap_level: wrap_level).results
end

#versionObject



39
40
41
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 39

def version
  @version ||= @requestor.get('db/data/').body[:neo4j_version]
end