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.



97
98
99
100
101
102
103
104
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 97

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

Instance Method Details

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

Convenience method to #request(:get, …)



131
132
133
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 131

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

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



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

def request(method, path, body = '', _options = {})
  request_body = request_body(body)
  url = url_from_path(path)
  @instrument_proc.call(method, url, request_body) 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

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

Convenience method to #request(:post, …)



126
127
128
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 126

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

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



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

def request(method, path, body = '', _options = {})
  request_body = request_body(body)
  url = url_from_path(path)
  @instrument_proc.call(method, url, request_body) 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