Class: Neo4j::Core::CypherSession::Adaptors::HTTP
- Defined in:
- lib/neo4j/core/cypher_session/adaptors/http.rb
Defined Under Namespace
Classes: Requestor
Constant Summary collapse
- DEFAULT_FARADAY_CONFIGURATOR =
proc do |faraday| faraday.adapter :typhoeus end
- 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
-
#requestor ⇒ Object
readonly
Returns the value of attribute requestor.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #check_for_schema_response_error!(response_body) ⇒ Object
- #connect ⇒ Object
- #connected? ⇒ Boolean
- #constraints(_session, _label = nil, _options = {}) ⇒ Object
-
#indexes(_session) ⇒ Object
Schema inspection methods.
-
#indexes_for_label(label) ⇒ Object
Schema inspection methods.
-
#initialize(url, options = {}) ⇒ HTTP
constructor
A new instance of HTTP.
- #query_set(transaction, queries, options = {}) ⇒ Object
- #version ⇒ Object
Methods inherited from Base
instrument_queries, #logger, #queries, #query, #setup_queries!, #transaction
Methods included from Instrumentable
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, = {}) @url = url @options = end |
Instance Attribute Details
#requestor ⇒ Object (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 |
#url ⇒ Object (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_class ⇒ Object
81 82 83 84 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 81 def self.transaction_class require 'neo4j/core/cypher_session/transactions/http' Neo4j::Core::CypherSession::Transactions::HTTP end |
Instance Method Details
#check_for_schema_response_error!(response_body) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 73 def check_for_schema_response_error!(response_body) return if !response_body.is_a?(Hash) || !response_body.key?(:errors) = response_body[:errors].map { |error| "#{error[:code]}: #{error[:message]}" }.join("\n ") fail CypherSession::ConnectionFailedError, "Connection failure: \n #{}" end |
#connect ⇒ Object
22 23 24 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 22 def connect @requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request), @options.fetch(:faraday_configurator, DEFAULT_FARADAY_CONFIGURATOR)) end |
#connected? ⇒ Boolean
97 98 99 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 97 def connected? !!@requestor end |
#constraints(_session, _label = nil, _options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 61 def constraints(_session, _label = nil, = {}) response = @requestor.get('db/data/schema/constraint') check_for_schema_response_error!(response.body) 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
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 46 def indexes(_session) response = @requestor.get('db/data/schema/index') check_for_schema_response_error!(response.body) 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
87 88 89 90 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 87 def indexes_for_label(label) url = db_data_url + "schema/index/#{label}" @connection.get(url) end |
#query_set(transaction, queries, options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 28 def query_set(transaction, queries, = {}) setup_queries!(queries, transaction) return unless path = transaction.query_path(.delete(:commit)) faraday_response = @requestor.post(path, queries) transaction.apply_id_from_url!(faraday_response.env[:response_headers][:location]) wrap_level = [:wrap_level] || @options[:wrap_level] Responses::HTTP.new(faraday_response, wrap_level: wrap_level).results end |
#version ⇒ Object
41 42 43 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 41 def version @version ||= @requestor.get('db/data/').body[:neo4j_version] end |