Skip to content

Commit

Permalink
Merge f684f5d into 5689a70
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszkopinski committed Nov 3, 2016
2 parents 5689a70 + f684f5d commit 41edbd7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/geoip2/client.rb
Expand Up @@ -28,6 +28,7 @@ def initialize(config)
@parallel_requests = config[:parallel_requests]
@user = config[:user_id]
@password = config[:license_key]
@faraday_options = {}
end

#
Expand Down Expand Up @@ -74,10 +75,17 @@ def preform(url, type, params = {}, &block)
# @return an instance of Faraday initialized with all that this gem needs
def connection(faraday_options = {})
if @faraday_options != faraday_options
options = {url: @base_url, parallel_manager: Typhoeus::Hydra.new(max_concurrency: @parallel_requests)}.merge(faraday_options)
@faraday_options = faraday_options
@connection = Faraday.new(options) do |conn|
@connection = nil
end

@connection ||= begin
options = {
url: @base_url,
parallel_manager: Typhoeus::Hydra.new(max_concurrency: @parallel_requests)
}.merge(@faraday_options)

Faraday.new(options) do |conn|
conn.request :basic_auth, @user, @password

# Set the response to be mashified
Expand All @@ -93,7 +101,6 @@ def connection(faraday_options = {})
conn.adapter :typhoeus
end
end
@connection
end
end
end

0 comments on commit 41edbd7

Please sign in to comment.