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

Inherits:
Object
  • Object
show all
Includes:
Neo4j::Core::CypherSession::Adaptors::HasUri
Defined in:
lib/neo4j/core/cypher_session/adaptors/http.rb

Overview

Basic wrapper around HTTP requests to standard Neo4j HTTP endpoints

- Takes care of JSONifying objects passed as body (Hash/Array/Query)
- Sets headers, including user agent string

Constant Summary collapse

REQUEST_HEADERS =
{'Accept'.to_sym => 'application/json; charset=UTF-8',
'Content-Type'.to_sym => 'application/json'}

Instance Method Summary collapse

Methods included from Neo4j::Core::CypherSession::Adaptors::HasUri

#url, #url=, #url_without_password

Constructor Details

#initialize(url, user_agent_string, instrument_proc, faraday_configurator) ⇒ Requestor

Returns a new instance of Requestor



116
117
118
119
120
121
122
123
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 116

def initialize(url, user_agent_string, instrument_proc, faraday_configurator)
  self.url = url
  @user = user
  @password = password
  @user_agent_string = user_agent_string
  @faraday = wrap_connection_failed! { faraday_connection(faraday_configurator) }
  @instrument_proc = instrument_proc
end

Instance Method Details

#get(path, body = '', options = {}) ⇒ Object

Convenience method to #request(:get, …)



148
149
150
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 148

def get(path, body = '', options = {})
  request(:get, path, body, options)
end

#HTTP(method(: get/:post/:delete/:put)) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 132

def request(method, path, body = '', _options = {})
  request_body = request_body(body)
  url = url_from_path(path)
  @instrument_proc.call(method, url, request_body) do
    wrap_connection_failed! do
      @faraday.run_request(method, url, request_body, REQUEST_HEADERS)
    end
  end
end

#post(path, body = '', options = {}) ⇒ Object

Convenience method to #request(:post, …)



143
144
145
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 143

def post(path, body = '', options = {})
  request(:post, path, body, options)
end

#request(method, path, body = '', _options = {}) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 132

def request(method, path, body = '', _options = {})
  request_body = request_body(body)
  url = url_from_path(path)
  @instrument_proc.call(method, url, request_body) do
    wrap_connection_failed! do
      @faraday.run_request(method, url, request_body, REQUEST_HEADERS)
    end
  end
end