@@ -16,7 +16,7 @@ def initialize(url, options = {})
1616 end
1717
1818 def connect
19- @requestor = Requestor . new ( @url , USER_AGENT_STRING , self . class . method ( :instrument_request ) )
19+ @requestor = Requestor . new ( @url , USER_AGENT_STRING , self . class . method ( :instrument_request ) , @options [ :faraday_options ] ||= { } )
2020 end
2121
2222 ROW_REST = %w( row REST )
@@ -101,13 +101,12 @@ class Requestor
101101 include Adaptors ::HasUri
102102 default_url ( 'http://neo4:neo4j@localhost:7474' )
103103 validate_uri { |uri | uri . is_a? ( URI ::HTTP ) }
104-
105- def initialize ( url , user_agent_string , instrument_proc )
104+ def initialize ( url , user_agent_string , instrument_proc , faraday_options = { } )
106105 self . url = url
107106 @user = user
108107 @password = password
109108 @user_agent_string = user_agent_string
110- @faraday = wrap_connection_failed! { faraday_connection }
109+ @faraday = wrap_connection_failed! { faraday_connection ( faraday_options . fetch ( :initialize , { } ) ) }
111110 @instrument_proc = instrument_proc
112111 end
113112
@@ -144,12 +143,12 @@ def get(path, body = '', options = {})
144143
145144 private
146145
147- def faraday_connection
146+ def faraday_connection ( options = { } )
148147 require 'faraday'
149148 require 'faraday_middleware/multi_json'
150149
151- Faraday . new ( url ) do |c |
152- c . request :basic_auth , user , password
150+ Faraday . new ( url , options ) do |c |
151+ c . request :basic_auth , config_username ( user , options ) , config_password ( password , options )
153152 c . request :multi_json
154153
155154 c . response :multi_json , symbolize_keys : true , content_type : 'application/json'
@@ -162,6 +161,14 @@ def faraday_connection
162161 end
163162 end
164163
164+ def config_password ( password , options )
165+ options [ :basic_auth ] ? options [ :basic_auth ] [ :password ] : password
166+ end
167+
168+ def config_username ( user , options )
169+ options [ :basic_auth ] ? options [ :basic_auth ] [ :username ] : user
170+ end
171+
165172 def request_body ( body )
166173 return body if body . is_a? ( String )
167174
0 commit comments