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=

Constructor Details

#initialize(url, user_agent_string, instrument_proc) ⇒ Requestor

Returns a new instance of Requestor.



105
106
107
108
109
110
111
112
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 105

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

Instance Method Details

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

Convenience method to #request(:get, …)



141
142
143
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 141

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

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



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 121

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) do |req|
        # Temporary
        # req.options.timeout = 5
        # req.options.open_timeout = 5
      end
    end
  end
end

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

Convenience method to #request(:post, …)



136
137
138
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 136

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

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



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 121

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) do |req|
        # Temporary
        # req.options.timeout = 5
        # req.options.open_timeout = 5
      end
    end
  end
end