algoliasearch 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -50,17 +50,17 @@ Gem::Specification.new do |s|
50
50
  s.specification_version = 4
51
51
 
52
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<httpclient>, ["~> 2.7.1"])
53
+ s.add_runtime_dependency(%q<httpclient>, ["~> 2.8.2"])
54
54
  s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
55
55
  s.add_development_dependency "travis"
56
56
  s.add_development_dependency "rake"
57
57
  s.add_development_dependency "rdoc"
58
58
  else
59
- s.add_dependency(%q<httpclient>, ["~> 2.4"])
59
+ s.add_dependency(%q<httpclient>, ["~> 2.8.2"])
60
60
  s.add_dependency(%q<json>, [">= 1.5.1"])
61
61
  end
62
62
  else
63
- s.add_dependency(%q<httpclient>, ["~> 2.4"])
63
+ s.add_dependency(%q<httpclient>, ["~> 2.8.2"])
64
64
  s.add_dependency(%q<json>, [">= 1.5.1"])
65
65
  end
66
66
  end
@@ -333,12 +333,14 @@ module Algolia
333
333
  end
334
334
  receive_timeout = type == :search ? @search_timeout : @receive_timeout
335
335
 
336
- (type == :write ? @hosts : @search_hosts).size.times do |i|
336
+ thread_local_hosts(type != :write).each_with_index do |host, i|
337
337
  connect_timeout += 2 if i == 2
338
338
  send_timeout += 10 if i == 2
339
339
  receive_timeout += 10 if i == 2
340
340
 
341
- host = thread_local_hosts(type != :write, connect_timeout, send_timeout, receive_timeout)[i]
341
+ host[:session].connect_timeout = connect_timeout
342
+ host[:session].send_timeout = send_timeout
343
+ host[:session].receive_timeout = receive_timeout
342
344
  begin
343
345
  return perform_request(host[:session], host[:base_url] + uri, method, data)
344
346
  rescue AlgoliaProtocolError => e
@@ -370,27 +372,16 @@ module Algolia
370
372
  private
371
373
 
372
374
  # This method returns a thread-local array of sessions
373
- #
374
- # Since the underlying httpclient library resets the connections pool
375
- # if you change any of its attributes, we cannot change the timeout
376
- # of an HTTP session dynamically. That being said, having 1 pool per
377
- # timeout appears to be the only acceptable solution
378
- def thread_local_hosts(read, connect_timeout, send_timeout, receive_timeout)
379
- thread_local_var = read ? :algolia_search_hosts : :algolia_hosts
380
- Thread.current[thread_local_var] ||= {}
381
- Thread.current[thread_local_var]["#{self.hash}:#{connect_timeout}-#{send_timeout}-#{receive_timeout}"] ||= (read ? search_hosts : hosts).map do |host|
375
+ def thread_local_hosts(read)
376
+ Thread.current[read ? :algolia_search_hosts : :algolia_hosts] ||= (read ? search_hosts : hosts).map do |host|
382
377
  client = HTTPClient.new
383
378
  client.ssl_config.ssl_version = @ssl_version if @ssl && @ssl_version
384
- hinfo = {
379
+ client.transparent_gzip_decompression = true
380
+ client.ssl_config.add_trust_ca File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt'))
381
+ {
385
382
  :base_url => "http#{@ssl ? 's' : ''}://#{host}",
386
383
  :session => client
387
384
  }
388
- hinfo[:session].transparent_gzip_decompression = true
389
- hinfo[:session].connect_timeout = connect_timeout
390
- hinfo[:session].send_timeout = send_timeout
391
- hinfo[:session].receive_timeout = receive_timeout
392
- hinfo[:session].ssl_config.add_trust_ca File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt'))
393
- hinfo
394
385
  end
395
386
  end
396
387
 
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.10.0"
2
+ VERSION = "1.11.0"
3
3
  end
data/lib/algoliasearch.rb CHANGED
@@ -8,7 +8,14 @@ require "rubygems"
8
8
  require "bundler/setup"
9
9
 
10
10
  require 'json'
11
- require 'httpclient'
11
+ if !defined?(RUBY_ENGINE) && defined?(RUBY_VERSION) && RUBY_VERSION == '1.8.7'
12
+ # work-around a limitation from nahi/httpclient, using the undefined RUBY_ENGINE constant
13
+ RUBY_ENGINE = 'ruby1.8'
14
+ require 'httpclient'
15
+ Object.send(:remove_const, :RUBY_ENGINE)
16
+ else
17
+ require 'httpclient'
18
+ end
12
19
  require 'date'
13
20
  require 'cgi'
14
21
 
data/spec/client_spec.rb CHANGED
@@ -738,7 +738,13 @@ describe 'Client' do
738
738
  key = Algolia.generate_secured_api_key('my_api_key', :tagFilters => '(public,user1)')
739
739
  key.should eq(Base64.encode64("#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), 'my_api_key', 'tagFilters=%28public%2Cuser1%29')}tagFilters=%28public%2Cuser1%29").gsub("\n", ''))
740
740
  key = Algolia.generate_secured_api_key('182634d8894831d5dbce3b3185c50881', :tagFilters => '(public,user1)', :userToken => 42)
741
- key.should eq('OGYwN2NlNTdlOGM2ZmM4MjA5NGM0ZmYwNTk3MDBkNzMzZjQ0MDI3MWZjNTNjM2Y3YTAzMWM4NTBkMzRiNTM5YnRhZ0ZpbHRlcnM9JTI4cHVibGljJTJDdXNlcjElMjkmdXNlclRva2VuPTQy')
741
+ # in ruby 1.8.7, the map iteration doesn't have the same ordering,
742
+ # making the hash slightly different
743
+ expected_keys = [
744
+ 'ZDU0N2YzZjA3NGZkZGM2OTUxNzY3NzhkZDI3YWFkMjhhNzU5OTBiOGIyYTgyYzFmMjFjZTY4NTA0ODNiN2I1ZnVzZXJUb2tlbj00MiZ0YWdGaWx0ZXJzPSUyOHB1YmxpYyUyQ3VzZXIxJTI5',
745
+ 'OGYwN2NlNTdlOGM2ZmM4MjA5NGM0ZmYwNTk3MDBkNzMzZjQ0MDI3MWZjNTNjM2Y3YTAzMWM4NTBkMzRiNTM5YnRhZ0ZpbHRlcnM9JTI4cHVibGljJTJDdXNlcjElMjkmdXNlclRva2VuPTQy'
746
+ ]
747
+ expected_keys.include?(key).should eq(true)
742
748
  end
743
749
 
744
750
  it 'Check attributes multipleQueries' do
@@ -894,23 +900,25 @@ describe 'Client' do
894
900
  @index.search_synonyms('')['nbHits'].should eq(0)
895
901
  end
896
902
 
897
- context 'DNS timeout' do
898
- before(:all) do
899
- @client = Algolia::Client.new :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY'],
900
- :hosts => [
901
- "#{ENV['ALGOLIA_APPLICATION_ID']}.algolia.biz",
902
- "#{ENV['ALGOLIA_APPLICATION_ID']}.algolia.net",
903
- "#{ENV['ALGOLIA_APPLICATION_ID']}-1.algolianet.com",
904
- "#{ENV['ALGOLIA_APPLICATION_ID']}-2.algolianet.com",
905
- "#{ENV['ALGOLIA_APPLICATION_ID']}-3.algolianet.com"
906
- ],
907
- :connect_timeout => 5
908
- end
903
+ if ENV['TRAVIS'].to_s != "true"
904
+ context 'DNS timeout' do
905
+ before(:all) do
906
+ @client = Algolia::Client.new :application_id => ENV['ALGOLIA_APPLICATION_ID'], :api_key => ENV['ALGOLIA_API_KEY'],
907
+ :hosts => [
908
+ "#{ENV['ALGOLIA_APPLICATION_ID']}.algolia.biz",
909
+ "#{ENV['ALGOLIA_APPLICATION_ID']}.algolia.net",
910
+ "#{ENV['ALGOLIA_APPLICATION_ID']}-1.algolianet.com",
911
+ "#{ENV['ALGOLIA_APPLICATION_ID']}-2.algolianet.com",
912
+ "#{ENV['ALGOLIA_APPLICATION_ID']}-3.algolianet.com"
913
+ ],
914
+ :connect_timeout => 5
915
+ end
909
916
 
910
- it "should fallback to the 2nd host after a few seconds" do
911
- start_time = Time.now
912
- @client.list_indexes # fallback on the second host after 5 sec (connection timeout)
913
- expect(start_time.to_i + 5).to be <= Time.now.to_i + 1
917
+ it "should fallback to the 2nd host after a few seconds" do
918
+ start_time = Time.now
919
+ @client.list_indexes # fallback on the second host after 5 sec (connection timeout)
920
+ expect(start_time.to_i + 5).to be <= Time.now.to_i + 1
921
+ end
914
922
  end
915
923
  end
916
924
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.7.1
19
+ version: 2.8.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.7.1
26
+ version: 2.8.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.4.8
134
+ rubygems_version: 2.5.1
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: A simple Ruby client for the algolia.com REST API