@@ -16,7 +16,7 @@ def initialize(url, options = {})
16
16
end
17
17
18
18
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 ] ||= { } )
20
20
end
21
21
22
22
ROW_REST = %w( row REST )
@@ -101,13 +101,12 @@ class Requestor
101
101
include Adaptors ::HasUri
102
102
default_url ( 'http://neo4:neo4j@localhost:7474' )
103
103
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 = { } )
106
105
self . url = url
107
106
@user = user
108
107
@password = password
109
108
@user_agent_string = user_agent_string
110
- @faraday = wrap_connection_failed! { faraday_connection }
109
+ @faraday = wrap_connection_failed! { faraday_connection ( faraday_options . fetch ( :initialize , { } ) ) }
111
110
@instrument_proc = instrument_proc
112
111
end
113
112
@@ -144,12 +143,12 @@ def get(path, body = '', options = {})
144
143
145
144
private
146
145
147
- def faraday_connection
146
+ def faraday_connection ( options = { } )
148
147
require 'faraday'
149
148
require 'faraday_middleware/multi_json'
150
149
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 )
153
152
c . request :multi_json
154
153
155
154
c . response :multi_json , symbolize_keys : true , content_type : 'application/json'
@@ -162,6 +161,14 @@ def faraday_connection
162
161
end
163
162
end
164
163
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
+
165
172
def request_body ( body )
166
173
return body if body . is_a? ( String )
167
174
0 commit comments