Class: Neo4j::Core::CypherSession::Adaptors::HTTP::Requestor
- Inherits:
-
Object
- Object
- Neo4j::Core::CypherSession::Adaptors::HTTP::Requestor
- 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
-
#get(path, body = '', options = {}) ⇒ Object
Convenience method to #request(:get, …).
- #HTTP(method(: get/:post/:delete/:put)) ⇒ Object
-
#initialize(url, user_agent_string, instrument_proc, faraday_configurator) ⇒ Requestor
constructor
A new instance of Requestor.
-
#post(path, body = '', options = {}) ⇒ Object
Convenience method to #request(:post, …).
- #request(method, path, body = '', _options = {}) ⇒ Object
Methods included from Neo4j::Core::CypherSession::Adaptors::HasUri
Constructor Details
#initialize(url, user_agent_string, instrument_proc, faraday_configurator) ⇒ Requestor
Returns a new instance of Requestor.
110 111 112 113 114 115 116 117 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 110 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, …)
142 143 144 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 142 def get(path, body = '', = {}) request(:get, path, body, ) end |
#HTTP(method(: get/:post/:delete/:put)) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 126 def request(method, path, body = '', = {}) 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, …)
137 138 139 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 137 def post(path, body = '', = {}) request(:post, path, body, ) end |
#request(method, path, body = '', _options = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 126 def request(method, path, body = '', = {}) 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 |