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.
111 112 113 114 115 116 117 118 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 111 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, …)
143 144 145 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 143 def get(path, body = '', = {}) request(:get, path, body, ) end |
#HTTP(method(: get/:post/:delete/:put)) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 127 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, …)
138 139 140 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 138 def post(path, body = '', = {}) request(:post, path, body, ) end |
#request(method, path, body = '', _options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/neo4j/core/cypher_session/adaptors/http.rb', line 127 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 |