algoliasearch 1.1.18 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed9bdf3f12f211dae2feda61a34a774cd2290cfd
4
- data.tar.gz: f90d402531a97f525a1d6e653afd4dc306e91bdf
3
+ metadata.gz: 06ce79db65e2f53814c3725a690ea5f4194d1a57
4
+ data.tar.gz: 10375aa725de3a232155b493fe50ce05387543d0
5
5
  SHA512:
6
- metadata.gz: 3d14cde3da631f5d2dbd769749103c2b27b26e700c2e8626b35581c72b820e945a6d1cce524a09a40b655ed6b64e3819144daf8b0e960de003ecdaef4b640dbe
7
- data.tar.gz: 16d7cb85403471dad4b9b1a8f494d8ba72b11bc08b712a228682367bf5189cdfbaff45a21960ef0082add8a4a31b0e4c5202c9e579bf0700cb5b820601887b3a
6
+ metadata.gz: e14ff400d8dee763cc12240fa0042f3e70504e375f63e498092a1160d4db45b257bc8c4f325620adb45c125afdff404504eb894325adeb10580279724cb7bed0
7
+ data.tar.gz: f6f84cf2825cd15b258bc706f23abd4c2bd74b09b25d13229c6ed4ba077168898a6c99b849ab80fb8825641828e88e51531a0b5d2cc18704e34569f13fb4a3d0
data/.travis.yml CHANGED
@@ -3,8 +3,11 @@ branches:
3
3
  only:
4
4
  - master
5
5
  rvm:
6
+ - 2.1.0
6
7
  - 2.0.0
7
8
  - 1.9.3
9
+ - jruby
10
+ - rbx
8
11
  env:
9
12
  global:
10
13
  - secure: lBLtTjQyeJW7+TWgGmf1mmsXgUzsTnq3/KHvCk+BvOGwoHXTBR1Y6yiczWWHEP4/wBeXXm31xUQC+VoYc/7Ev/2NNB/mqlXAgGw+D0nwQriNXjYt1WV6lQvyoiaUzQ+w+7VahWdx0LuKvSYI+khe8M8BfHQqYacu0VlpAUnjb2I=
data/ChangeLog CHANGED
@@ -1,5 +1,13 @@
1
1
  CHANGELOG
2
2
 
3
+ 2014-01-07 1.2.1
4
+
5
+ * Removed 'jeweler' since it doesn't support platform specific deps (see https://github.com/technicalpickles/jeweler/issues/170)
6
+
7
+ 2014-01-07 1.2.0
8
+
9
+ * Removed 'curb' dependency and switched on 'httpclient' to avoid fork-safety issue (see issue #5)
10
+
3
11
  2014-01-06 1.1.18
4
12
 
5
13
  * Fixed batch request builder (broken since last refactoring)
data/Gemfile CHANGED
@@ -1,11 +1,12 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'curb', '~> 0.8'
3
+ gem 'httpclient', '~> 2.3'
4
4
  gem 'json', '>= 1.5.1'
5
+ gem 'rubysl', '~> 2.0', platform: :rbx
5
6
 
6
7
  group :development do
7
- gem 'jeweler'
8
8
  gem 'travis'
9
+ gem 'rake'
9
10
  end
10
11
 
11
12
  group :test do
data/Gemfile.lock CHANGED
@@ -8,12 +8,10 @@ GEM
8
8
  autotest-fsevent (0.2.9)
9
9
  sys-uname
10
10
  autotest-growl (0.2.16)
11
- backports (3.3.5)
12
- builder (3.2.2)
11
+ backports (3.4.0)
13
12
  coderay (1.1.0)
14
13
  crack (0.4.1)
15
14
  safe_yaml (~> 0.9.0)
16
- curb (0.8.5)
17
15
  diff-lcs (1.2.5)
18
16
  ethon (0.6.2)
19
17
  ffi (>= 1.3.0)
@@ -23,6 +21,8 @@ GEM
23
21
  faraday_middleware (0.9.0)
24
22
  faraday (>= 0.7.4, < 0.9)
25
23
  ffi (1.9.3)
24
+ ffi (1.9.3-java)
25
+ ffi2-generators (0.1.1)
26
26
  gh (0.13.0)
27
27
  addressable
28
28
  backports
@@ -30,56 +30,30 @@ GEM
30
30
  multi_json (~> 1.0)
31
31
  net-http-persistent (>= 2.7)
32
32
  net-http-pipeline
33
- git (1.2.6)
34
- github_api (0.10.1)
35
- addressable
36
- faraday (~> 0.8.1)
37
- hashie (>= 1.2)
38
- multi_json (~> 1.4)
39
- nokogiri (~> 1.5.2)
40
- oauth2
41
- hashie (2.0.5)
42
33
  highline (1.6.20)
43
- httpauth (0.2.0)
44
- jeweler (1.8.8)
45
- builder
46
- bundler (~> 1.0)
47
- git (>= 1.2.5)
48
- github_api (= 0.10.1)
49
- highline (>= 1.6.15)
50
- nokogiri (= 1.5.10)
51
- rake
52
- rdoc
34
+ httpclient (2.3.4.1)
53
35
  json (1.8.1)
54
- jwt (0.1.8)
55
- multi_json (>= 1.5)
36
+ json (1.8.1-java)
56
37
  launchy (2.4.2)
57
38
  addressable (~> 2.3)
58
39
  method_source (0.8.2)
59
40
  mime-types (1.25.1)
60
41
  multi_json (1.8.2)
61
- multi_xml (0.5.5)
62
42
  multipart-post (1.2.0)
63
43
  net-http-persistent (2.9)
64
44
  net-http-pipeline (1.0.1)
65
- nokogiri (1.5.10)
66
- oauth2 (0.9.2)
67
- faraday (~> 0.8)
68
- httpauth (~> 0.2)
69
- jwt (~> 0.1.4)
70
- multi_json (~> 1.0)
71
- multi_xml (~> 0.5)
72
- rack (~> 1.2)
73
45
  pry (0.9.12.4)
74
46
  coderay (~> 1.0)
75
47
  method_source (~> 0.8)
76
48
  slop (~> 3.4)
49
+ pry (0.9.12.4-java)
50
+ coderay (~> 1.0)
51
+ method_source (~> 0.8)
52
+ slop (~> 3.4)
53
+ spoon (~> 0.0)
77
54
  pusher-client (0.4.0)
78
55
  websocket (~> 1.0.0)
79
- rack (1.5.2)
80
56
  rake (10.1.1)
81
- rdoc (4.0.1)
82
- json (~> 1.4)
83
57
  redgreen (1.2.2)
84
58
  rspec (2.14.1)
85
59
  rspec-core (~> 2.14.0)
@@ -89,8 +63,212 @@ GEM
89
63
  rspec-expectations (2.14.4)
90
64
  diff-lcs (>= 1.1.3, < 2.0)
91
65
  rspec-mocks (2.14.4)
66
+ rubysl (2.0.15)
67
+ rubysl-abbrev (~> 2.0)
68
+ rubysl-base64 (~> 2.0)
69
+ rubysl-benchmark (~> 2.0)
70
+ rubysl-bigdecimal (~> 2.0)
71
+ rubysl-cgi (~> 2.0)
72
+ rubysl-cgi-session (~> 2.0)
73
+ rubysl-cmath (~> 2.0)
74
+ rubysl-complex (~> 2.0)
75
+ rubysl-continuation (~> 2.0)
76
+ rubysl-coverage (~> 2.0)
77
+ rubysl-csv (~> 2.0)
78
+ rubysl-curses (~> 2.0)
79
+ rubysl-date (~> 2.0)
80
+ rubysl-delegate (~> 2.0)
81
+ rubysl-digest (~> 2.0)
82
+ rubysl-drb (~> 2.0)
83
+ rubysl-e2mmap (~> 2.0)
84
+ rubysl-english (~> 2.0)
85
+ rubysl-enumerator (~> 2.0)
86
+ rubysl-erb (~> 2.0)
87
+ rubysl-etc (~> 2.0)
88
+ rubysl-expect (~> 2.0)
89
+ rubysl-fcntl (~> 2.0)
90
+ rubysl-fiber (~> 2.0)
91
+ rubysl-fileutils (~> 2.0)
92
+ rubysl-find (~> 2.0)
93
+ rubysl-forwardable (~> 2.0)
94
+ rubysl-getoptlong (~> 2.0)
95
+ rubysl-gserver (~> 2.0)
96
+ rubysl-io-console (~> 2.0)
97
+ rubysl-io-nonblock (~> 2.0)
98
+ rubysl-io-wait (~> 2.0)
99
+ rubysl-ipaddr (~> 2.0)
100
+ rubysl-irb (~> 2.0)
101
+ rubysl-logger (~> 2.0)
102
+ rubysl-mathn (~> 2.0)
103
+ rubysl-matrix (~> 2.0)
104
+ rubysl-mkmf (~> 2.0)
105
+ rubysl-monitor (~> 2.0)
106
+ rubysl-mutex_m (~> 2.0)
107
+ rubysl-net-ftp (~> 2.0)
108
+ rubysl-net-http (~> 2.0)
109
+ rubysl-net-imap (~> 2.0)
110
+ rubysl-net-pop (~> 2.0)
111
+ rubysl-net-protocol (~> 2.0)
112
+ rubysl-net-smtp (~> 2.0)
113
+ rubysl-net-telnet (~> 2.0)
114
+ rubysl-nkf (~> 2.0)
115
+ rubysl-observer (~> 2.0)
116
+ rubysl-open-uri (~> 2.0)
117
+ rubysl-open3 (~> 2.0)
118
+ rubysl-openssl (~> 2.0)
119
+ rubysl-optparse (~> 2.0)
120
+ rubysl-ostruct (~> 2.0)
121
+ rubysl-pathname (~> 2.0)
122
+ rubysl-prettyprint (~> 2.0)
123
+ rubysl-prime (~> 2.0)
124
+ rubysl-profile (~> 2.0)
125
+ rubysl-profiler (~> 2.0)
126
+ rubysl-pstore (~> 2.0)
127
+ rubysl-pty (~> 2.0)
128
+ rubysl-rational (~> 2.0)
129
+ rubysl-readline (~> 2.0)
130
+ rubysl-resolv (~> 2.0)
131
+ rubysl-rexml (~> 2.0)
132
+ rubysl-rinda (~> 2.0)
133
+ rubysl-rss (~> 2.0)
134
+ rubysl-scanf (~> 2.0)
135
+ rubysl-securerandom (~> 2.0)
136
+ rubysl-set (~> 2.0)
137
+ rubysl-shellwords (~> 2.0)
138
+ rubysl-singleton (~> 2.0)
139
+ rubysl-socket (~> 2.0)
140
+ rubysl-stringio (~> 2.0)
141
+ rubysl-strscan (~> 2.0)
142
+ rubysl-sync (~> 2.0)
143
+ rubysl-syslog (~> 2.0)
144
+ rubysl-tempfile (~> 2.0)
145
+ rubysl-thread (~> 2.0)
146
+ rubysl-thwait (~> 2.0)
147
+ rubysl-time (~> 2.0)
148
+ rubysl-timeout (~> 2.0)
149
+ rubysl-tmpdir (~> 2.0)
150
+ rubysl-tsort (~> 2.0)
151
+ rubysl-un (~> 2.0)
152
+ rubysl-uri (~> 2.0)
153
+ rubysl-weakref (~> 2.0)
154
+ rubysl-webrick (~> 2.0)
155
+ rubysl-xmlrpc (~> 2.0)
156
+ rubysl-yaml (~> 2.0)
157
+ rubysl-zlib (~> 2.0)
158
+ rubysl-abbrev (2.0.4)
159
+ rubysl-base64 (2.0.0)
160
+ rubysl-benchmark (2.0.1)
161
+ rubysl-bigdecimal (2.0.2)
162
+ rubysl-cgi (2.0.1)
163
+ rubysl-cgi-session (2.0.1)
164
+ rubysl-cmath (2.0.0)
165
+ rubysl-complex (2.0.0)
166
+ rubysl-continuation (2.0.0)
167
+ rubysl-coverage (2.0.3)
168
+ rubysl-csv (2.0.2)
169
+ rubysl-english (~> 2.0)
170
+ rubysl-curses (2.0.1)
171
+ rubysl-date (2.0.6)
172
+ rubysl-delegate (2.0.1)
173
+ rubysl-digest (2.0.3)
174
+ rubysl-drb (2.0.1)
175
+ rubysl-e2mmap (2.0.0)
176
+ rubysl-english (2.0.0)
177
+ rubysl-enumerator (2.0.0)
178
+ rubysl-erb (2.0.1)
179
+ rubysl-etc (2.0.3)
180
+ ffi2-generators (~> 0.1)
181
+ rubysl-expect (2.0.0)
182
+ rubysl-fcntl (2.0.4)
183
+ ffi2-generators (~> 0.1)
184
+ rubysl-fiber (2.0.0)
185
+ rubysl-fileutils (2.0.3)
186
+ rubysl-find (2.0.1)
187
+ rubysl-forwardable (2.0.1)
188
+ rubysl-getoptlong (2.0.0)
189
+ rubysl-gserver (2.0.0)
190
+ rubysl-socket (~> 2.0)
191
+ rubysl-thread (~> 2.0)
192
+ rubysl-io-console (2.0.0)
193
+ rubysl-io-nonblock (2.0.0)
194
+ rubysl-io-wait (2.0.0)
195
+ rubysl-ipaddr (2.0.0)
196
+ rubysl-irb (2.0.4)
197
+ rubysl-e2mmap (~> 2.0)
198
+ rubysl-mathn (~> 2.0)
199
+ rubysl-readline (~> 2.0)
200
+ rubysl-thread (~> 2.0)
201
+ rubysl-logger (2.0.0)
202
+ rubysl-mathn (2.0.0)
203
+ rubysl-matrix (2.1.0)
204
+ rubysl-e2mmap (~> 2.0)
205
+ rubysl-mkmf (2.0.1)
206
+ rubysl-fileutils (~> 2.0)
207
+ rubysl-shellwords (~> 2.0)
208
+ rubysl-monitor (2.0.0)
209
+ rubysl-mutex_m (2.0.0)
210
+ rubysl-net-ftp (2.0.1)
211
+ rubysl-net-http (2.0.4)
212
+ rubysl-cgi (~> 2.0)
213
+ rubysl-erb (~> 2.0)
214
+ rubysl-singleton (~> 2.0)
215
+ rubysl-net-imap (2.0.1)
216
+ rubysl-net-pop (2.0.1)
217
+ rubysl-net-protocol (2.0.1)
218
+ rubysl-net-smtp (2.0.1)
219
+ rubysl-net-telnet (2.0.0)
220
+ rubysl-nkf (2.0.1)
221
+ rubysl-observer (2.0.0)
222
+ rubysl-open-uri (2.0.0)
223
+ rubysl-open3 (2.0.0)
224
+ rubysl-openssl (2.0.6)
225
+ rubysl-optparse (2.0.1)
226
+ rubysl-shellwords (~> 2.0)
227
+ rubysl-ostruct (2.0.4)
228
+ rubysl-pathname (2.0.0)
229
+ rubysl-prettyprint (2.0.2)
230
+ rubysl-prime (2.0.1)
231
+ rubysl-profile (2.0.0)
232
+ rubysl-profiler (2.0.1)
233
+ rubysl-pstore (2.0.0)
234
+ rubysl-pty (2.0.2)
235
+ rubysl-rational (2.0.1)
236
+ rubysl-readline (2.0.2)
237
+ rubysl-resolv (2.0.0)
238
+ rubysl-rexml (2.0.2)
239
+ rubysl-rinda (2.0.0)
240
+ rubysl-rss (2.0.0)
241
+ rubysl-scanf (2.0.0)
242
+ rubysl-securerandom (2.0.0)
243
+ rubysl-set (2.0.1)
244
+ rubysl-shellwords (2.0.0)
245
+ rubysl-singleton (2.0.0)
246
+ rubysl-socket (2.0.1)
247
+ rubysl-stringio (2.0.0)
248
+ rubysl-strscan (2.0.0)
249
+ rubysl-sync (2.0.0)
250
+ rubysl-syslog (2.0.1)
251
+ ffi2-generators (~> 0.1)
252
+ rubysl-tempfile (2.0.1)
253
+ rubysl-thread (2.0.2)
254
+ rubysl-thwait (2.0.0)
255
+ rubysl-time (2.0.3)
256
+ rubysl-timeout (2.0.0)
257
+ rubysl-tmpdir (2.0.0)
258
+ rubysl-tsort (2.0.1)
259
+ rubysl-un (2.0.0)
260
+ rubysl-fileutils (~> 2.0)
261
+ rubysl-optparse (~> 2.0)
262
+ rubysl-uri (2.0.0)
263
+ rubysl-weakref (2.0.0)
264
+ rubysl-webrick (2.0.0)
265
+ rubysl-xmlrpc (2.0.0)
266
+ rubysl-yaml (2.0.4)
267
+ rubysl-zlib (2.0.1)
92
268
  safe_yaml (0.9.7)
93
269
  slop (3.4.7)
270
+ spoon (0.0.4)
271
+ ffi
94
272
  sys-uname (0.9.2)
95
273
  ffi (>= 1.0.0)
96
274
  travis (1.6.6)
@@ -112,16 +290,18 @@ GEM
112
290
  websocket (1.0.7)
113
291
 
114
292
  PLATFORMS
293
+ java
115
294
  ruby
116
295
 
117
296
  DEPENDENCIES
118
297
  autotest
119
298
  autotest-fsevent
120
299
  autotest-growl
121
- curb (~> 0.8)
122
- jeweler
300
+ httpclient (~> 2.3)
123
301
  json (>= 1.5.1)
302
+ rake
124
303
  redgreen
125
304
  rspec (>= 2.5.0)
305
+ rubysl (~> 2.0)
126
306
  travis
127
307
  webmock
data/Rakefile CHANGED
@@ -13,21 +13,6 @@ require 'rake'
13
13
 
14
14
  require File.expand_path('../lib/algolia/version', __FILE__)
15
15
 
16
- require 'jeweler'
17
- Jeweler::Tasks.new do |gem|
18
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
- gem.name = "algoliasearch"
20
- gem.homepage = "http://github.com/algolia/algoliasearch-client-ruby"
21
- gem.license = "MIT"
22
- gem.summary = %Q{A simple Ruby client for the algolia.com REST API}
23
- gem.description = %Q{A simple Ruby client for the algolia.com REST API}
24
- gem.email = "contact@algolia.com"
25
- gem.authors = ["Algolia"]
26
- gem.version = Algolia::VERSION
27
- # dependencies defined in Gemfile
28
- end
29
- Jeweler::RubygemsDotOrgTasks.new
30
-
31
16
  require 'rake/testtask'
32
17
  Rake::TestTask.new(:test) do |test|
33
18
  test.libs << 'lib' << 'test'
@@ -2,15 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: algoliasearch 1.1.18 ruby lib
5
+ # stub: algoliasearch 1.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "algoliasearch"
9
- s.version = "1.1.18"
9
+ s.version = "1.2.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
12
13
  s.authors = ["Algolia"]
13
- s.date = "2014-01-06"
14
+ s.date = "2014-01-07"
14
15
  s.description = "A simple Ruby client for the algolia.com REST API"
15
16
  s.email = "contact@algolia.com"
16
17
  s.extra_rdoc_files = [
@@ -44,29 +45,23 @@ Gem::Specification.new do |s|
44
45
  ]
45
46
  s.homepage = "http://github.com/algolia/algoliasearch-client-ruby"
46
47
  s.licenses = ["MIT"]
47
- s.require_paths = ["lib"]
48
- s.rubygems_version = "2.1.11"
48
+ s.rubygems_version = "2.2.1"
49
49
  s.summary = "A simple Ruby client for the algolia.com REST API"
50
50
 
51
51
  if s.respond_to? :specification_version then
52
52
  s.specification_version = 4
53
53
 
54
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<curb>, ["~> 0.8"])
55
+ s.add_runtime_dependency(%q<httpclient>, ["~> 2.3"])
56
56
  s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
57
- s.add_development_dependency(%q<jeweler>, [">= 0"])
58
57
  s.add_development_dependency(%q<travis>, [">= 0"])
59
58
  else
60
- s.add_dependency(%q<curb>, ["~> 0.8"])
59
+ s.add_dependency(%q<httpclient>, ["~> 2.3"])
61
60
  s.add_dependency(%q<json>, [">= 1.5.1"])
62
- s.add_dependency(%q<jeweler>, [">= 0"])
63
- s.add_dependency(%q<travis>, [">= 0"])
64
61
  end
65
62
  else
66
- s.add_dependency(%q<curb>, ["~> 0.8"])
63
+ s.add_dependency(%q<httpclient>, ["~> 2.3"])
67
64
  s.add_dependency(%q<json>, [">= 1.5.1"])
68
- s.add_dependency(%q<jeweler>, [">= 0"])
69
- s.add_dependency(%q<travis>, [">= 0"])
70
65
  end
71
66
  end
72
67
 
@@ -7,18 +7,22 @@ require 'zlib'
7
7
  module Algolia
8
8
 
9
9
  # A class which encapsulates the HTTPS communication with the Algolia
10
- # API server. Uses the Curb (Curl) library for low-level HTTP communication.
10
+ # API server. Uses the HTTPClient library for low-level HTTP communication.
11
11
  class Client
12
- attr_reader :hosts
13
- attr_reader :application_id
14
- attr_reader :api_key
12
+ attr_reader :hosts, :application_id, :api_key, :headers
13
+
15
14
 
16
15
  def initialize(data = {})
17
16
  @ssl = data[:ssl].nil? ? true : data[:ssl]
18
17
  @application_id = data[:application_id]
19
18
  @api_key = data[:api_key]
20
19
  @hosts = (data[:hosts] || 1.upto(3).map { |i| "#{@application_id}-#{i}.algolia.io" }).shuffle
21
- @debug = data[:debug]
20
+ @headers = {
21
+ Protocol::HEADER_API_KEY => api_key,
22
+ Protocol::HEADER_APP_ID => application_id,
23
+ 'Content-Type' => 'application/json; charset=utf-8',
24
+ 'User-Agent' => "Algolia for Ruby #{::Algolia::VERSION}"
25
+ }
22
26
  end
23
27
 
24
28
  # Perform an HTTP request for the given uri and method
@@ -29,12 +33,11 @@ module Algolia
29
33
  exceptions = []
30
34
  thread_local_hosts.each do |host|
31
35
  begin
32
- session = perform_request(host, uri, method, data)
33
- return JSON.parse(session.body_str)
36
+ return perform_request(host[:session], host[:base_url] + uri, method, data)
34
37
  rescue AlgoliaProtocolError => e
35
38
  raise if e.code != Protocol::ERROR_TIMEOUT and e.code != Protocol::ERROR_UNAVAILABLE
36
39
  exceptions << e
37
- rescue Curl::Err::CurlError => e
40
+ rescue HTTPClient::BadResponseError, OpenSSL::SSL::SSLError => e
38
41
  exceptions << e
39
42
  end
40
43
  end
@@ -45,11 +48,11 @@ module Algolia
45
48
  request(uri, :GET)
46
49
  end
47
50
 
48
- def post(uri, body)
51
+ def post(uri, body = {})
49
52
  request(uri, :POST, body)
50
53
  end
51
54
 
52
- def put(uri, body)
55
+ def put(uri, body = {})
53
56
  request(uri, :PUT, body)
54
57
  end
55
58
 
@@ -57,36 +60,37 @@ module Algolia
57
60
  request(uri, :DELETE)
58
61
  end
59
62
 
63
+ private
64
+
60
65
  # this method returns a thread-local array of sessions
61
66
  def thread_local_hosts
62
67
  Thread.current[:algolia_hosts] ||= hosts.map do |host|
63
- hinfo = {}
64
- hinfo["base_url"] = "http#{@ssl ? 's' : ''}://#{host}"
65
- hinfo["host"] = host
66
- hinfo["session"] = init_session
68
+ hinfo = {
69
+ :base_url => "http#{@ssl ? 's' : ''}://#{host}",
70
+ :session => HTTPClient.new
71
+ }
72
+ hinfo[:session].transparent_gzip_decompression = true
73
+ hinfo[:session].ssl_config.add_trust_ca File.join(File.dirname(__FILE__), '..', '..', 'resources', 'ca-bundle.crt')
67
74
  hinfo
68
75
  end
69
76
  end
70
77
 
71
78
  private
72
- def perform_request(host, uri, method, data)
73
- session = host["session"]
74
- session.url = host["base_url"] + uri
75
- case method
76
- when :GET
77
- session.http_get
78
- when :POST
79
- session.post_body = data
80
- session.http_post
81
- when :PUT
82
- session.put(data)
83
- when :DELETE
84
- session.http_delete
85
- end
86
- if session.response_code >= 400 || session.response_code < 200
87
- raise AlgoliaProtocolError.new(session.response_code, "Cannot #{method} to #{session.url}: #{session.body_str} (#{session.response_code})")
88
- end
89
- session;
79
+ def perform_request(session, url, method, data)
80
+ response = case method
81
+ when :GET
82
+ session.get(url, { :header => @headers })
83
+ when :POST
84
+ session.post(url, { :body => data, :header => @headers })
85
+ when :PUT
86
+ session.put(url, { :body => data, :header => @headers })
87
+ when :DELETE
88
+ session.delete(url, { :header => @headers })
89
+ end
90
+ if response.code >= 400 || response.code < 200
91
+ raise AlgoliaProtocolError.new(response.code, "Cannot #{method} to #{url}: #{response.content} (#{response.code})")
92
+ end
93
+ return JSON.parse(response.content)
90
94
  end
91
95
 
92
96
  def init_session
@@ -130,24 +134,18 @@ module Algolia
130
134
  # @param rate_limit_api_key the API key on which you have a rate limit
131
135
  #
132
136
  def Algolia.enable_rate_limit_forward(admin_api_key, end_user_ip, rate_limit_api_key)
133
- Algolia.client.thread_local_hosts.each do |host|
134
- session = host["session"]
135
- session.headers[Protocol::HEADER_API_KEY] = admin_api_key
136
- session.headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip
137
- session.headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key
138
- end
137
+ Algolia.client.headers[Protocol::HEADER_API_KEY] = admin_api_key
138
+ Algolia.client.headers[Protocol::HEADER_FORWARDED_IP] = end_user_ip
139
+ Algolia.client.headers[Protocol::HEADER_FORWARDED_API_KEY] = rate_limit_api_key
139
140
  end
140
141
 
141
142
  #
142
143
  # Disable IP rate limit enabled with enableRateLimitForward() function
143
144
  #
144
145
  def Algolia.disable_rate_limit_forward
145
- Algolia.client.thread_local_hosts.each do |host|
146
- session = host["session"]
147
- session.headers[Protocol::HEADER_API_KEY] = Algolia.client.api_key
148
- session.headers.delete(Protocol::HEADER_FORWARDED_IP)
149
- session.headers.delete(Protocol::HEADER_FORWARDED_API_KEY)
150
- end
146
+ Algolia.client.headers[Protocol::HEADER_API_KEY] = Algolia.client.api_key
147
+ Algolia.client.headers.delete(Protocol::HEADER_FORWARDED_IP)
148
+ Algolia.client.headers.delete(Protocol::HEADER_FORWARDED_API_KEY)
151
149
  end
152
150
 
153
151
  #
data/lib/algolia/index.rb CHANGED
@@ -277,7 +277,7 @@ module Algolia
277
277
  #
278
278
  #
279
279
  def clear
280
- Algolia.client.post(Protocol.clear_uri(name), nil)
280
+ Algolia.client.post(Protocol.clear_uri(name))
281
281
  end
282
282
 
283
283
  #
@@ -1,3 +1,3 @@
1
1
  module Algolia
2
- VERSION = "1.1.18"
2
+ VERSION = "1.2.1"
3
3
  end
data/lib/algoliasearch.rb CHANGED
@@ -8,7 +8,7 @@ require "rubygems"
8
8
  require "bundler/setup"
9
9
 
10
10
  require 'json'
11
- require 'curb'
11
+ require 'httpclient'
12
12
  require 'date'
13
13
  require 'cgi'
14
14
 
data/spec/client_spec.rb CHANGED
@@ -63,6 +63,20 @@ describe 'Client' do
63
63
  threads.each { |t| t.join }
64
64
  end
65
65
 
66
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE != 'jruby'
67
+ it "should be fork safe" do
68
+ 8.times do
69
+ Process.fork do
70
+ 10.times do
71
+ res = @index.search("john")
72
+ res["hits"].length.should eq(1)
73
+ end
74
+ end
75
+ end
76
+ Process.waitall
77
+ end
78
+ end
79
+
66
80
  it "should clear the index" do
67
81
  @index.clear!
68
82
  @index.search("")["hits"].length.should eq(0)
data/spec/mock_spec.rb CHANGED
@@ -6,7 +6,7 @@ describe 'With a mocked client' do
6
6
 
7
7
  before(:each) do
8
8
  WebMock.enable!
9
- Thread.current[:algolia_hosts] = nil # reset Curb::Easy objects
9
+ Thread.current[:algolia_hosts] = nil # reset session objects
10
10
  end
11
11
 
12
12
  it "should add a simple object" do
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.18
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-06 00:00:00.000000000 Z
11
+ date: 2014-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: curb
14
+ name: httpclient
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0.8'
19
+ version: '2.3'
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: '0.8'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.5.1
41
- - !ruby/object:Gem::Dependency
42
- name: jeweler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: travis
57
43
  requirement: !ruby/object:Gem::Requirement