index-tanked 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,8 +37,8 @@ module IndexTanked
37
37
  end
38
38
  end
39
39
 
40
- class ClientResponseMiddleware < FaradayMiddleware::ResponseMiddleware
41
- def process_response(env)
40
+ class ClientResponseMiddleware < Faraday::Response::Middleware
41
+ def on_complete(env)
42
42
  case env[:status]
43
43
  when 200
44
44
  nil # this is the expected return code
@@ -50,6 +50,11 @@ module IndexTanked
50
50
  raise UnexpectedHTTPException, env[:body]
51
51
  end
52
52
  end
53
+
54
+ def initialize(app)
55
+ super
56
+ @parser = nil
57
+ end
53
58
  end
54
59
  end
55
60
  end
@@ -65,8 +65,8 @@ module IndexTanked
65
65
  end
66
66
  end
67
67
 
68
- class DocumentResponseMiddleware < FaradayMiddleware::ResponseMiddleware
69
- def process_response(env)
68
+ class DocumentResponseMiddleware < Faraday::Response::Middleware
69
+ def on_complete(env)
70
70
  case env[:status]
71
71
  when 200
72
72
  nil # this is the expected code
@@ -27,8 +27,8 @@ module IndexTanked
27
27
  true
28
28
  when 409
29
29
  raise TooManyIndexes
30
- when 401
31
- raise InvalidApiKey
30
+ when 401
31
+ raise InvalidApiKey
32
32
  end
33
33
  end
34
34
 
@@ -37,7 +37,7 @@ module IndexTanked
37
37
  if not self.exists?
38
38
  raise NonExistentIndex
39
39
  end
40
-
40
+
41
41
  response = @conn.put do |req|
42
42
  req.url ""
43
43
  req.body = options.to_json
@@ -45,8 +45,8 @@ module IndexTanked
45
45
  case response.status
46
46
  when 204
47
47
  true
48
- when 401
49
- raise InvalidApiKey
48
+ when 401
49
+ raise InvalidApiKey
50
50
  end
51
51
  end
52
52
 
@@ -132,7 +132,7 @@ module IndexTanked
132
132
  end
133
133
  end
134
134
 
135
- # the options argument may contain an :index_code definition to override
135
+ # the options argument may contain an :index_code definition to override
136
136
  # this instance's default index_code
137
137
  # it can also contain any of the following:
138
138
  # :start => an int with the number of results to skip
@@ -155,15 +155,15 @@ module IndexTanked
155
155
  # :docvar_filters => a hash with int keys and Array values to filter the query based on document variables.
156
156
  # see http://indextank.com/documentation/ruby-client#range_queries
157
157
  #
158
- # Example:
159
- # docvar_filters = { 1 => [ [2, 3], [5, nil] ]}
158
+ # Example:
159
+ # docvar_filters = { 1 => [ [2, 3], [5, nil] ]}
160
160
  # means that only documents with document variable number 1 between 2 and 3 or bigger than 5
161
161
  # will match the query.
162
162
  # :function_filters => a hash with int keys and Array values to filter the query based on scoring functions.
163
163
  # see http://indextank.com/documentation/ruby-client#range_queries
164
164
  #
165
- # Example:
166
- # function_filters = { 3 => [ [nil, 2], [5, 7], [8,14] ]}
165
+ # Example:
166
+ # function_filters = { 3 => [ [nil, 2], [5, 7], [8,14] ]}
167
167
  # means that only documents whose score calculated by scoring function 3 is lower than 2,
168
168
  # between 5 and 7 or between 8 and 14 will match the query.
169
169
  def search(query, options = {})
@@ -175,24 +175,24 @@ module IndexTanked
175
175
 
176
176
  if options[:docvar_filters]
177
177
  # go from { 3 => [ [1, 3], [5, nil] ]} to filter_docvar3 => 1:3,5:*
178
- options[:docvar_filters].each_pair { |k, v|
178
+ options[:docvar_filters].each_pair { |k, v|
179
179
  rng = v.map { |val|
180
180
  raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
181
181
  "#{val[0] || '*'}:#{val[1] || '*'}"
182
182
  }.join ","
183
- options.merge!( :"filter_docvar#{k}" => rng )
183
+ options.merge!( :"filter_docvar#{k}" => rng )
184
184
  }
185
185
  options.delete :docvar_filters
186
186
  end
187
187
 
188
188
  if options[:function_filters]
189
189
  # go from { 2 => [ [1 , 3],[5,8] ]} to filter_function2 => 1:3,5:8
190
- options[:function_filters].each_pair { |k, v|
190
+ options[:function_filters].each_pair { |k, v|
191
191
  rng = v.map { |val|
192
192
  raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
193
193
  "#{val[0] || '*'}:#{val[1] || '*'}"
194
194
  }.join ","
195
- options.merge!( :"filter_function#{k}" => rng )
195
+ options.merge!( :"filter_function#{k}" => rng )
196
196
  }
197
197
  options.delete :function_filters
198
198
  end
@@ -203,7 +203,7 @@ module IndexTanked
203
203
 
204
204
  response = @conn.get do |req|
205
205
  req.url 'search', options
206
- end
206
+ end
207
207
  case response.status
208
208
  when 400
209
209
  raise InvalidQuery
@@ -216,7 +216,7 @@ module IndexTanked
216
216
  response.body
217
217
  end
218
218
 
219
- # the options argument may contain an :index_code definition to override
219
+ # the options argument may contain an :index_code definition to override
220
220
  # this instance's default index_code
221
221
  # it can also contain any of the following:
222
222
  # :start => an int with the number of results to skip
@@ -234,15 +234,15 @@ module IndexTanked
234
234
  # :docvar_filters => a hash with int keys and Array values to filter the query based on document variables.
235
235
  # see http://indextank.com/documentation/ruby-client#range_queries
236
236
  #
237
- # Example:
238
- # docvar_filters = { 1 => [ [2, 3], [5, nil] ]}
237
+ # Example:
238
+ # docvar_filters = { 1 => [ [2, 3], [5, nil] ]}
239
239
  # means that only documents with document variable number 1 between 2 and 3 or bigger than 5
240
240
  # will match the query.
241
241
  # :function_filters => a hash with int keys and Array values to filter the query based on scoring functions.
242
242
  # see http://indextank.com/documentation/ruby-client#range_queries
243
243
  #
244
- # Example:
245
- # function_filters = { 3 => [ [nil, 2], [5, 7], [8,14] ]}
244
+ # Example:
245
+ # function_filters = { 3 => [ [nil, 2], [5, 7], [8,14] ]}
246
246
  # means that only documents whose score calculated by scoring function 3 is lower than 2,
247
247
  # between 5 and 7 or between 8 and 14 will match the query.
248
248
  def delete_by_search(query, options = {})
@@ -254,24 +254,24 @@ module IndexTanked
254
254
 
255
255
  if options[:docvar_filters]
256
256
  # go from { 3 => [ [1, 3], [5, nil] ]} to filter_docvar3 => 1:3,5:*
257
- options[:docvar_filters].each_pair { |k, v|
257
+ options[:docvar_filters].each_pair { |k, v|
258
258
  rng = v.map { |val|
259
259
  raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
260
260
  "#{val[0] || '*'}:#{val[1] || '*'}"
261
261
  }.join ","
262
- options.merge!( :"filter_docvar#{k}" => rng )
262
+ options.merge!( :"filter_docvar#{k}" => rng )
263
263
  }
264
264
  options.delete :docvar_filters
265
265
  end
266
266
 
267
267
  if options[:function_filters]
268
268
  # go from { 2 => [ [1 , 3],[5,8] ]} to filter_function2 => 1:3,5:8
269
- options[:function_filters].each_pair { |k, v|
269
+ options[:function_filters].each_pair { |k, v|
270
270
  rng = v.map { |val|
271
271
  raise ArgumentError, "using a range with bound count != 2" unless val.length == 2
272
272
  "#{val[0] || '*'}:#{val[1] || '*'}"
273
273
  }.join ","
274
- options.merge!( :"filter_function#{k}" => rng )
274
+ options.merge!( :"filter_function#{k}" => rng )
275
275
  }
276
276
  options.delete :function_filters
277
277
  end
@@ -282,7 +282,7 @@ module IndexTanked
282
282
 
283
283
  response = @conn.delete do |req|
284
284
  req.url 'search', options
285
- end
285
+ end
286
286
  case response.status
287
287
  when 400
288
288
  raise InvalidQuery
@@ -302,15 +302,15 @@ module IndexTanked
302
302
  end.body
303
303
  end
304
304
 
305
- # the options argument may contain an :index_code definition to override
306
- # this instance's default index_code
305
+ # the options argument may contain an :index_code definition to override
306
+ # this instance's default index_code
307
307
  def promote(docid, query, options={})
308
308
  options.merge!( :docid => docid, :query => query )
309
309
  resp = @conn.put do |req|
310
310
  req.url 'promote'
311
311
  req.body = options.to_json
312
312
  end
313
-
313
+
314
314
  case resp.status
315
315
  when 409
316
316
  raise IndexInitializing
@@ -1,23 +1,21 @@
1
1
  require 'faraday_middleware'
2
- require 'faraday_middleware/response_middleware'
3
2
  require 'uri'
4
3
 
5
- require 'index-tanked/indextank/client'
4
+ require "index-tanked/indextank/client"
6
5
 
7
6
  module IndexTanked
8
7
  module IndexTank
9
- VERSION = "1.0.12"
8
+ VERSION = "1.0.13"
10
9
 
11
10
  def self.setup_connection(url)
12
- ## in Faraday 0.8 or above:
13
- @conn = Faraday.new(url) do |conn|
14
- conn.response :json
15
- yield conn if block_given?
16
- conn.adapter Faraday.default_adapter
11
+ @conn = Faraday::Connection.new(:url => url) do |builder|
12
+ builder.use FaradayMiddleware::ParseJson
13
+ yield builder if block_given?
14
+ builder.adapter Faraday.default_adapter
17
15
  end
18
16
  @uri = URI.parse(url)
19
17
  @conn.basic_auth @uri.user,@uri.password
20
- @conn.headers['User-Agent'] = "IndexTanked::IndexTank-Ruby/#{VERSION}"
18
+ @conn.headers['User-Agent'] = "IndexTank-Ruby/#{VERSION}"
21
19
  @conn
22
20
  end
23
21
  end
@@ -1,3 +1,3 @@
1
1
  module IndexTanked
2
- GEM_VERSION = '0.7.0'
2
+ GEM_VERSION = '0.7.1'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: index-tanked
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 0
10
- version: 0.7.0
9
+ - 1
10
+ version: 0.7.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Kittelson
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2013-02-06 00:00:00 Z
20
+ date: 2013-06-19 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
23
  name: will_paginate
@@ -72,12 +72,14 @@ dependencies:
72
72
  requirement: &id004 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ">="
75
+ - - "="
76
76
  - !ruby/object:Gem::Version
77
- hash: 3
77
+ hash: 33
78
78
  segments:
79
- - 0
80
- version: "0"
79
+ - 2
80
+ - 10
81
+ - 3
82
+ version: 2.10.3
81
83
  type: :development
82
84
  version_requirements: *id004
83
85
  - !ruby/object:Gem::Dependency
@@ -249,10 +251,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
249
251
  requirements: []
250
252
 
251
253
  rubyforge_project:
252
- rubygems_version: 1.8.24
254
+ rubygems_version: 1.8.25
253
255
  signing_key:
254
256
  specification_version: 3
255
257
  summary: Index Tank <http://indextank.com> integration library.
256
258
  test_files: []
257
259
 
258
- has_rdoc: