Module: Legion::Extensions::Neo4j::Helpers::Client
- Included in:
- Client, Runners::Admin, Runners::Cypher, Runners::GraphDataScience, Runners::Indexes, Runners::Nodes, Runners::Relationships, Runners::Transactions
- Defined in:
- lib/legion/extensions/neo4j/helpers/client.rb
Instance Method Summary collapse
- #connection(url: nil, username: nil, password: nil, _database: 'neo4j', **_opts) ⇒ Object
- #execute_cypher(query, parameters: {}, database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
Instance Method Details
#connection(url: nil, username: nil, password: nil, _database: 'neo4j', **_opts) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/legion/extensions/neo4j/helpers/client.rb', line 11 def connection(url: nil, username: nil, password: nil, _database: 'neo4j', **_opts) Faraday.new(url: url) do |conn| conn.request :json conn.response :json, content_type: /\bjson$/ conn.headers['Authorization'] = "Basic #{Base64.strict_encode64("#{username}:#{password}")}" if username && password conn.headers['Content-Type'] = 'application/json' conn.headers['Accept'] = 'application/json' end end |
#execute_cypher(query, parameters: {}, database: 'neo4j', url: nil, username: nil, password: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/neo4j/helpers/client.rb', line 21 def execute_cypher(query, parameters: {}, database: 'neo4j', url: nil, username: nil, password: nil, **) payload = { statements: [{ statement: query, parameters: parameters }] } resp = connection(url: url, username: username, password: password) .post("/db/#{database}/tx/commit", payload) body = resp.body raise CypherError, body[:errors].map { |e| e['message'] }.join('; ') if body.is_a?(Hash) && body[:errors] && !body[:errors].empty? body end |