lib/algolia/client.rb in algoliasearch-1.2.14 vs lib/algolia/client.rb in algoliasearch-1.3.0
- old
+ new
@@ -8,19 +8,18 @@
module Algolia
# A class which encapsulates the HTTPS communication with the Algolia
# API server. Uses the HTTPClient library for low-level HTTP communication.
class Client
- attr_reader :ssl, :ssl_version, :hosts, :application_id, :api_key, :headers, :connect_timeout, :send_timeout, :receive_timeout, :search_timeout
+ attr_reader :ssl, :hosts, :application_id, :api_key, :headers, :connect_timeout, :send_timeout, :receive_timeout, :search_timeout
def initialize(data = {})
@ssl = data[:ssl].nil? ? true : data[:ssl]
- @ssl_version = data[:ssl_version].nil? ? nil : data[:ssl_version]
@application_id = data[:application_id]
@api_key = data[:api_key]
- @hosts = (data[:hosts] || 1.upto(3).map { |i| "#{@application_id}-#{i}.algolia.io" }).shuffle
+ @hosts = (data[:hosts] || 1.upto(3).map { |i| "#{@application_id}-#{i}.algolia.net" }).shuffle
@connect_timeout = data[:connect_timeout]
@send_timeout = data[:send_timeout]
@receive_timeout = data[:receive_timeout]
@search_timeout = data[:search_timeout]
@headers = {
@@ -39,11 +38,11 @@
exceptions = []
thread_local_hosts(timeout).each do |host|
begin
return perform_request(host[:session], host[:base_url] + uri, method, data)
rescue AlgoliaProtocolError => e
- raise if e.code == Protocol::ERROR_BAD_REQUEST or e.code == Protocol::ERROR_FORBIDDEN or e.code == Protocol::ERROR_NOT_FOUND
+ raise if e.code != Protocol::ERROR_TIMEOUT and e.code != Protocol::ERROR_UNAVAILABLE
exceptions << e
rescue => e
exceptions << e
end
end
@@ -75,14 +74,12 @@
# of an HTTP session dynamically. That being said, having 1 pool per
# timeout appears to be the only acceptable solution
def thread_local_hosts(forced_timeout)
Thread.current[:algolia_hosts] ||= {}
Thread.current[:algolia_hosts][forced_timeout.to_s] ||= hosts.map do |host|
- client = HTTPClient.new
- client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version
hinfo = {
:base_url => "http#{@ssl ? 's' : ''}://#{host}",
- :session => client
+ :session => HTTPClient.new
}
hinfo[:session].transparent_gzip_decompression = true
hinfo[:session].connect_timeout = @connect_timeout if @connect_timeout
if forced_timeout
hinfo[:session].send_timeout = hinfo[:session].receive_timeout = forced_timeout