-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Faraday init params to be passed to HTTP adaptor #288
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def initialize(url, options = {}) | |
end | ||
|
||
def connect | ||
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request)) | ||
@requestor = Requestor.new(@url, USER_AGENT_STRING, self.class.method(:instrument_request), @options[:faraday_opts] = {}) | ||
end | ||
|
||
ROW_REST = %w(row REST) | ||
|
@@ -101,13 +101,13 @@ class Requestor | |
include Adaptors::HasUri | ||
default_url('http://neo4:neo4j@localhost:7474') | ||
validate_uri { |uri| uri.is_a?(URI::HTTP) } | ||
|
||
def initialize(url, user_agent_string, instrument_proc) | ||
def initialize(url, user_agent_string, instrument_proc, params = {}) | ||
self.url = url | ||
@user = user | ||
@password = password | ||
@user_agent_string = user_agent_string | ||
@faraday = wrap_connection_failed! { faraday_connection } | ||
init_params = params[:initialize] && params.delete(:initialize) if params.key?(:initialize) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is what the previous code did, but I don't like the @faraday = wrap_connection_failed! { faraday_connection(params.fetch(:initialize, {})) } Honestly since we're passing in a hash with the key of Separately we're going to need to make the Rails integration like this work: config.neo4j.session.options = {initialize: { ssl: { verify: true }}} But I think that we could simply pass down the values of config.neo4j.session.options = {faraday_options: { ssl: { verify: true }}} And probably raising a deprecation warning about how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (apart from rails-related config changes) |
||
@faraday = wrap_connection_failed! { faraday_connection(init_params) } | ||
@instrument_proc = instrument_proc | ||
end | ||
|
||
|
@@ -144,12 +144,13 @@ def get(path, body = '', options = {}) | |
|
||
private | ||
|
||
def faraday_connection | ||
def faraday_connection(params = {}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're in the place where we're creating the Faraday connection, I would probably just call this variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
require 'faraday' | ||
require 'faraday_middleware/multi_json' | ||
|
||
Faraday.new(url) do |c| | ||
Faraday.new(url,params) do |c| | ||
c.request :basic_auth, user, password | ||
c.request :basic_auth, params[:basic_auth][:username], params[:basic_auth][:password] if params[:basic_auth] | ||
c.request :multi_json | ||
|
||
c.response :multi_json, symbolize_keys: true, content_type: 'application/json' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
faraday_options
would be better, I thinkAlso, did you mean to do
@options[:faraday_opts] ||= {}
here? Otherwise it's going to always set / pass through an emptyHash
. You could also do@options.fetch(:faraday_options, {})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch. That was some post-implementation cleanup I thought was correct, so thanks for spotting