rsolr 1.0.10.pre1 → 1.0.10

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: f864085d45dbff290a9820ec8f12bb8388ac445a
4
- data.tar.gz: 7a117de8e81fb1c59368d4c33bc342ea379f2239
3
+ metadata.gz: 2c51404db922cb38d87d897879b80c175e6999fe
4
+ data.tar.gz: 3c6ac7bf24da6216b288442fc10fc9e207941c00
5
5
  SHA512:
6
- metadata.gz: 00410c0dd950cf7ff57a56dc55ae2d771a7de08f4b139558cd39029f763071709970400c6e99d3a5985135b54e205c576c10d8ac765010cb77e5acf71caeb87d
7
- data.tar.gz: 3d274051c0b81c3267bdf9330ff7888c9ad65b7d6d8edb034e840d06f41c5bc49e55f7c8b72a0531518be03350e66b775b26bed9ffb65799b837753cfddcab49
6
+ metadata.gz: 3ad642cbdd3f948e7f372dbcc75f0e63ae4b011678f2d2b7730f40f378b4298814dbea5fe5a32044317c6537f4eed07064cc1b0e68e429b21bf720bc4ff15e2f
7
+ data.tar.gz: a3c3283fb33be2db71b9195d5f177075673b819ea5f20e163d0ae69af8b2b7fcfb66f4411edb245f381f3832c8cd4ab8e692e0c01480cb284b10d411d82eafb6
data/.travis.yml CHANGED
@@ -2,6 +2,7 @@ rvm:
2
2
  - 2.1.0
3
3
  - 2.0.0
4
4
  - 1.9.3
5
+ - 1.8.7
5
6
  - jruby-19mode
6
7
 
7
8
  notifications:
@@ -13,3 +14,7 @@ env:
13
14
  global:
14
15
  - JRUBY_OPTS="-J-Xms512m -J-Xmx1024m"
15
16
  - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: 1.8.7
data/Gemfile CHANGED
@@ -1,15 +1,19 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
5
  gem "builder", ">= 2.1.2"
6
6
 
7
7
  group :development do
8
- gem "rake", "~> 0.9.2"
9
- gem "rdoc", "~> 3.9.4"
8
+ gem "rake", ">= 0.9.2"
9
+ gem "rdoc", ">= 3.9"
10
10
  end
11
11
 
12
12
  group :test do
13
- gem "rake", "~> 0.9.2"
14
- gem "rspec", "~> 2.6.0"
15
- end
13
+ gem "rake", ">= 0.9.2"
14
+ gem "rspec", "~> 2.6"
15
+ end
16
+
17
+ if defined? RUBY_VERSION and RUBY_VERSION < "1.9"
18
+ gem 'nokogiri', "< 1.6"
19
+ end
data/lib/rsolr/client.rb CHANGED
@@ -1,4 +1,19 @@
1
+ begin
2
+ require 'json'
3
+ rescue LoadError
4
+ end
5
+
1
6
  class RSolr::Client
7
+
8
+ class << self
9
+ def default_wt
10
+ @default_wt || :ruby
11
+ end
12
+
13
+ def default_wt= value
14
+ @default_wt = value
15
+ end
16
+ end
2
17
 
3
18
  attr_reader :connection, :uri, :proxy, :options
4
19
 
@@ -225,7 +240,7 @@ class RSolr::Client
225
240
  opts[:proxy] = proxy unless proxy.nil?
226
241
  opts[:method] ||= :get
227
242
  raise "The :data option can only be used if :method => :post" if opts[:method] != :post and opts[:data]
228
- opts[:params] = opts[:params].nil? ? {:wt => :ruby} : {:wt => :ruby}.merge(opts[:params])
243
+ opts[:params] = opts[:params].nil? ? {:wt => default_wt} : {:wt => default_wt}.merge(opts[:params])
229
244
  query = RSolr::Uri.params_to_solr(opts[:params]) unless opts[:params].empty?
230
245
  opts[:query] = query
231
246
  if opts[:data].is_a? Hash
@@ -266,7 +281,13 @@ class RSolr::Client
266
281
  raise "The response does not have the correct keys => :body, :headers, :status" unless
267
282
  %W(body headers status) == response.keys.map{|k|k.to_s}.sort
268
283
  raise RSolr::Error::Http.new request, response unless [200,302].include? response[:status]
269
- result = request[:params][:wt] == :ruby ? evaluate_ruby_response(request, response) : response[:body]
284
+
285
+ result = if respond_to? "evaluate_#{request[:params][:wt]}_response", true
286
+ send "evaluate_#{request[:params][:wt]}_response", request, response
287
+ else
288
+ response[:body]
289
+ end
290
+
270
291
  result.extend Context
271
292
  result.request, result.response = request, response
272
293
  result.is_a?(Hash) ? result.extend(RSolr::Response) : result
@@ -297,5 +318,18 @@ class RSolr::Client
297
318
  raise RSolr::Error::InvalidRubyResponse.new request, response
298
319
  end
299
320
  end
300
-
321
+
322
+ def evaluate_json_response request, response
323
+ return response[:body] unless defined? JSON
324
+
325
+ begin
326
+ JSON.parse response[:body].to_s, :symbolize_names => true
327
+ rescue JSON::ParserError
328
+ raise RSolr::Error::InvalidJsonResponse.new request, response
329
+ end
330
+ end
331
+
332
+ def default_wt
333
+ self.class.default_wt
334
+ end
301
335
  end
data/lib/rsolr/error.rb CHANGED
@@ -110,7 +110,19 @@ module RSolr::Error
110
110
 
111
111
  # Thrown if the :wt is :ruby
112
112
  # but the body wasn't succesfully parsed/evaluated
113
- class InvalidRubyResponse < Http
113
+ class InvalidResponse < Http
114
+
115
+ end
116
+
117
+ # Thrown if the :wt is :ruby
118
+ # but the body wasn't succesfully parsed/evaluated
119
+ class InvalidJsonResponse < InvalidResponse
120
+
121
+ end
122
+
123
+ # Thrown if the :wt is :ruby
124
+ # but the body wasn't succesfully parsed/evaluated
125
+ class InvalidRubyResponse < InvalidResponse
114
126
 
115
127
  end
116
128
 
@@ -11,6 +11,14 @@ module RSolr::Response
11
11
  end
12
12
  end
13
13
 
14
+ def with_indifferent_access
15
+ if {}.respond_to?(:with_indifferent_access)
16
+ super.extend RSolr::Response
17
+ else
18
+ raise NoMethodError, "undefined method `with_indifferent_access' for #{self.inspect}:#{self.class.name}"
19
+ end
20
+ end
21
+
14
22
  # A response module which gets mixed into the solr ["response"]["docs"] array.
15
23
  module PaginatedDocSet
16
24
 
@@ -0,0 +1,7 @@
1
+ module RSolr
2
+ VERSION = "1.0.10"
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
data/lib/rsolr.rb CHANGED
@@ -1,15 +1,12 @@
1
1
  $: << "#{File.dirname(__FILE__)}" unless $:.include? File.dirname(__FILE__)
2
2
 
3
3
  require 'rubygems'
4
+ require 'rsolr/version'
4
5
 
5
6
  module RSolr
6
7
 
7
8
  %W(Response Char Client Error Connection Uri Xml).each{|n|autoload n.to_sym, "rsolr/#{n.downcase}"}
8
9
 
9
- def self.version; "1.0.10.pre1" end
10
-
11
- VERSION = self.version
12
-
13
10
  def self.connect *args
14
11
  driver = Class === args[0] ? args[0] : RSolr::Connection
15
12
  opts = Hash === args[-1] ? args[-1] : {}
data/rsolr.gemspec CHANGED
@@ -1,13 +1,13 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
- require "rsolr"
4
+ require "rsolr/version"
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rsolr"
8
8
  s.summary = "A Ruby client for Apache Solr"
9
9
  s.description = %q{RSolr aims to provide a simple and extensible library for working with Solr}
10
- s.version = RSolr.version
10
+ s.version = RSolr::VERSION
11
11
  s.authors = ["Antoine Latter", "Dmitry Lihachev",
12
12
  "Lucas Souza", "Peter Kieltyka",
13
13
  "Rob Di Marco", "Magnus Bergmark",
@@ -28,8 +28,9 @@ Gem::Specification.new do |s|
28
28
  s.require_paths = ["lib"]
29
29
 
30
30
  s.add_dependency 'builder', '>= 2.1.2'
31
+ s.add_development_dependency 'activesupport'
31
32
  s.add_development_dependency 'nokogiri', '>= 1.4.0'
32
33
  s.add_development_dependency 'rake', '~> 0.9.2'
33
34
  s.add_development_dependency 'rdoc', '~> 3.9.4'
34
35
  s.add_development_dependency 'rspec', '~> 2.6.0'
35
- end
36
+ end
@@ -212,6 +212,17 @@ describe "RSolr::Client" do
212
212
  result.should == {:time=>"NOW"}
213
213
  end
214
214
 
215
+ it 'should evaluate json responses when the :wt is :json' do
216
+ body = '{"time": "NOW"}'
217
+ result = client.adapt_response({:params=>{:wt=>:json}}, {:status => 200, :body => body, :headers => {}})
218
+ if defined? JSON
219
+ result.should == {:time=>"NOW"}
220
+ else
221
+ # ruby 1.8 without the JSON gem
222
+ result.should == '{"time": "NOW"}'
223
+ end
224
+ end
225
+
215
226
  it "ought raise a RSolr::Error::InvalidRubyResponse when the ruby is indeed frugged, or even fruggified" do
216
227
  lambda {
217
228
  client.adapt_response({:params=>{:wt => :ruby}}, {:status => 200, :body => "<woops/>", :headers => {}})
@@ -220,6 +231,32 @@ describe "RSolr::Client" do
220
231
 
221
232
  end
222
233
 
234
+ context "indifferent access" do
235
+ include ClientHelper
236
+ it "should raise a NoMethodError if the #with_indifferent_access extension isn't loaded" do
237
+ # TODO: Find a less implmentation-tied way to test this
238
+ Hash.any_instance.should_receive(:respond_to?).with(:with_indifferent_access).and_return(false)
239
+ body = "{'foo'=>'bar'}"
240
+ result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
241
+ lambda { result.with_indifferent_access }.should raise_error NoMethodError
242
+ end
243
+
244
+ it "should provide indifferent access" do
245
+ require 'active_support/core_ext/hash/indifferent_access'
246
+ body = "{'foo'=>'bar'}"
247
+ result = client.adapt_response({:params=>{:wt=>:ruby}}, {:status => 200, :body => body, :headers => {}})
248
+ indifferent_result = result.with_indifferent_access
249
+
250
+ result.should be_a(RSolr::Response)
251
+ result['foo'].should == 'bar'
252
+ result[:foo].should be_nil
253
+
254
+ indifferent_result.should be_a(RSolr::Response)
255
+ indifferent_result['foo'].should == 'bar'
256
+ indifferent_result[:foo].should == 'bar'
257
+ end
258
+ end
259
+
223
260
  context "build_request" do
224
261
  include ClientHelper
225
262
  it 'should return a request context array' do
@@ -72,6 +72,7 @@ describe "RSolr::Connection" do
72
72
  end
73
73
 
74
74
  it "should configure Net:HTTP open_timeout" do
75
+ pending "doesn't work with ruby 1.8" if RUBY_VERSION < "1.9"
75
76
  http.should_receive(:request).and_raise(Errno::ECONNREFUSED)
76
77
  lambda {
77
78
  subject.execute client, request_context
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10.pre1
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antoine Latter
@@ -28,76 +28,90 @@ authors:
28
28
  autorequire:
29
29
  bindir: bin
30
30
  cert_chain: []
31
- date: 2014-01-16 00:00:00.000000000 Z
31
+ date: 2014-03-26 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: builder
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - '>='
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: 2.1.2
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - '>='
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.1.2
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: nokogiri
49
63
  requirement: !ruby/object:Gem::Requirement
50
64
  requirements:
51
- - - '>='
65
+ - - ">="
52
66
  - !ruby/object:Gem::Version
53
67
  version: 1.4.0
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
- - - '>='
72
+ - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: 1.4.0
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: rake
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
65
- - - ~>
79
+ - - "~>"
66
80
  - !ruby/object:Gem::Version
67
81
  version: 0.9.2
68
82
  type: :development
69
83
  prerelease: false
70
84
  version_requirements: !ruby/object:Gem::Requirement
71
85
  requirements:
72
- - - ~>
86
+ - - "~>"
73
87
  - !ruby/object:Gem::Version
74
88
  version: 0.9.2
75
89
  - !ruby/object:Gem::Dependency
76
90
  name: rdoc
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
- - - ~>
93
+ - - "~>"
80
94
  - !ruby/object:Gem::Version
81
95
  version: 3.9.4
82
96
  type: :development
83
97
  prerelease: false
84
98
  version_requirements: !ruby/object:Gem::Requirement
85
99
  requirements:
86
- - - ~>
100
+ - - "~>"
87
101
  - !ruby/object:Gem::Version
88
102
  version: 3.9.4
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: rspec
91
105
  requirement: !ruby/object:Gem::Requirement
92
106
  requirements:
93
- - - ~>
107
+ - - "~>"
94
108
  - !ruby/object:Gem::Version
95
109
  version: 2.6.0
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
- - - ~>
114
+ - - "~>"
101
115
  - !ruby/object:Gem::Version
102
116
  version: 2.6.0
103
117
  description: RSolr aims to provide a simple and extensible library for working with
@@ -108,8 +122,8 @@ executables: []
108
122
  extensions: []
109
123
  extra_rdoc_files: []
110
124
  files:
111
- - .gitignore
112
- - .travis.yml
125
+ - ".gitignore"
126
+ - ".travis.yml"
113
127
  - CHANGES.txt
114
128
  - Gemfile
115
129
  - LICENSE
@@ -122,6 +136,7 @@ files:
122
136
  - lib/rsolr/error.rb
123
137
  - lib/rsolr/response.rb
124
138
  - lib/rsolr/uri.rb
139
+ - lib/rsolr/version.rb
125
140
  - lib/rsolr/xml.rb
126
141
  - rsolr.gemspec
127
142
  - spec/api/char_spec.rb
@@ -146,17 +161,17 @@ require_paths:
146
161
  - lib
147
162
  required_ruby_version: !ruby/object:Gem::Requirement
148
163
  requirements:
149
- - - '>='
164
+ - - ">="
150
165
  - !ruby/object:Gem::Version
151
166
  version: '0'
152
167
  required_rubygems_version: !ruby/object:Gem::Requirement
153
168
  requirements:
154
- - - '>'
169
+ - - ">="
155
170
  - !ruby/object:Gem::Version
156
- version: 1.3.1
171
+ version: '0'
157
172
  requirements: []
158
173
  rubyforge_project: rsolr
159
- rubygems_version: 2.1.11
174
+ rubygems_version: 2.2.2
160
175
  signing_key:
161
176
  specification_version: 4
162
177
  summary: A Ruby client for Apache Solr