rsolr-patron 0.0.1
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.
- data/LICENSE +20 -0
- data/README.rdoc +24 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/rsolr-patron.rb +60 -0
- data/spec/rsolr-patron_spec.rb +93 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +91 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Nathan Witmer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
= rsolr-patron
|
2
|
+
|
3
|
+
rsolr-patron enhances RSolr with a Patron-based connection client
|
4
|
+
|
5
|
+
=Requirements
|
6
|
+
|
7
|
+
rsolr and the patron gem.
|
8
|
+
|
9
|
+
NOTE: this currently requires the latest rsolr version from aniero's fork,
|
10
|
+
found at http://github.com/aniero/rsolr
|
11
|
+
|
12
|
+
=How
|
13
|
+
|
14
|
+
Pass in :patron to the RSolr.connect method:
|
15
|
+
require 'rsolr-patron'
|
16
|
+
rsolr = RSolr.connect(:patron, :url => 'http://localhost:8983/solr')
|
17
|
+
|
18
|
+
== Credits
|
19
|
+
|
20
|
+
Based on rsolr-async, by Matt Mitchell
|
21
|
+
|
22
|
+
== Copyright
|
23
|
+
|
24
|
+
Copyright (c) 2010 Nathan Witmer. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rsolr-patron"
|
8
|
+
gem.summary = %Q{A Patron connection adapter for RSolr}
|
9
|
+
gem.description = %Q{Provides http connections to Solr via Patron/libcurl}
|
10
|
+
gem.email = "nwitmer@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/aniero/rsolr-patron"
|
12
|
+
gem.authors = ["Nathan Witmer"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_dependency "rsolr", ">= 0.12.1"
|
15
|
+
gem.add_dependency "patron", "~> 0.4.5"
|
16
|
+
|
17
|
+
gem.files = FileList['lib/**/*.rb', 'LICENSE', 'README.rdoc', 'VERSION']
|
18
|
+
gem.test_files = ['spec/*', 'Rakefile', 'solr/example/**/*']
|
19
|
+
|
20
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
|
+
end
|
22
|
+
# Jeweler::GemcutterTasks.new
|
23
|
+
rescue LoadError
|
24
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'spec/rake/spectask'
|
28
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
34
|
+
spec.libs << 'lib' << 'spec'
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :spec => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :spec
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "rsolr-patron #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/rsolr-patron.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require "rsolr"
|
2
|
+
require "patron"
|
3
|
+
|
4
|
+
module RSolr::Patron
|
5
|
+
|
6
|
+
module Connectable
|
7
|
+
|
8
|
+
def connect *args
|
9
|
+
if args.first == :patron
|
10
|
+
args.shift
|
11
|
+
RSolr::Client.new(RSolr::Patron::Connection.new(*args))
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
RSolr.extend Connectable
|
20
|
+
|
21
|
+
# Can be instantiated with the :url option (as per RSolr's default implementation)
|
22
|
+
# as well as any options that exist as attr_writers on a Patron::Session instance, e.g.
|
23
|
+
#
|
24
|
+
# RSolr::Client.connect :patron,
|
25
|
+
# :base_url => "http://localhost:8983", :timeout => 300, :headers => {"Connection" => "close"}
|
26
|
+
#
|
27
|
+
class Connection
|
28
|
+
|
29
|
+
include RSolr::Connection::Requestable
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def connection
|
34
|
+
unless @connection
|
35
|
+
@connection = ::Patron::Session.new
|
36
|
+
@connection.base_url = base_url # host/port, no path
|
37
|
+
@connection.proxy = opts[:proxy]
|
38
|
+
opts.each do |key, value|
|
39
|
+
next if [:url, :proxy].include? key
|
40
|
+
if @connection.respond_to?("#{key}=".to_sym)
|
41
|
+
@connection.send("#{key}=".to_sym, value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@connection
|
46
|
+
end
|
47
|
+
|
48
|
+
def get(url)
|
49
|
+
response = connection.get url
|
50
|
+
[response.body, response.status, response.status_line]
|
51
|
+
end
|
52
|
+
|
53
|
+
def post(url, data, headers={})
|
54
|
+
response = connection.post url, data, headers
|
55
|
+
[response.body, response.status, response.status_line]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe RSolr::Patron do
|
4
|
+
|
5
|
+
it "modifies RSolr" do
|
6
|
+
RSolr.should be_a(RSolr::Patron::Connectable)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "does not modify the default connection behavior" do
|
10
|
+
RSolr.connect.connection.should be_a(RSolr::Connection::NetHttp)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "creates an instance of RSolr::Patron::Connection with the :patron argument" do
|
14
|
+
RSolr.connect(:patron).connection.should be_a(RSolr::Patron::Connection)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "assigns additional options as allowed by the patron session" do
|
18
|
+
# whee black-box testing!
|
19
|
+
connection = RSolr::Patron::Connection.new(
|
20
|
+
:url => "http://foo", :timeout => 1234, :connect_timeout => 7)
|
21
|
+
connection.send(:connection).timeout.should == 1234
|
22
|
+
connection.send(:connection).connect_timeout.should == 7
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the patron base url and proxy" do
|
26
|
+
connection = RSolr::Patron::Connection.new(
|
27
|
+
:url => "http://foo:3456/path/to/things", :proxy => "http://proxy:8080")
|
28
|
+
connection.send(:connection).base_url.should == "http://foo:3456"
|
29
|
+
connection.send(:connection).proxy.should == "http://proxy:8080"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#get" do
|
33
|
+
it "calls #get on the patron connection with the appropriate data" do
|
34
|
+
connection = RSolr::Patron::Connection.new
|
35
|
+
connection.send(:connection) \
|
36
|
+
.should_receive(:get).with("/solr/search?q=foo") \
|
37
|
+
.and_return mock("body", :body => "", :status => 200, :status_line => "OK")
|
38
|
+
connection.request("/search", :q => "foo")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#post" do
|
43
|
+
it "calls #post on the patron connection" do
|
44
|
+
connection = RSolr::Patron::Connection.new
|
45
|
+
connection.send(:connection).should_receive(:post) \
|
46
|
+
.with("/solr/search", "q=query", {"Content-Type"=>"application/x-www-form-urlencoded"}) \
|
47
|
+
.and_return mock("body", :body => "", :status => 200, :status_line => "OK")
|
48
|
+
connection.request("/search", {:q => "query"}, :method => :post)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
# context '#request' do
|
53
|
+
# it 'should forward simple, non-data calls to #get' do
|
54
|
+
|
55
|
+
# EM.run do
|
56
|
+
|
57
|
+
# EM.add_timer(1) do
|
58
|
+
# EM.stop
|
59
|
+
# end
|
60
|
+
|
61
|
+
# EM::MockHttpRequest.pass_through_requests = false
|
62
|
+
# body = <<-EOM
|
63
|
+
# HTTP/1.1 200 OK
|
64
|
+
# Date: Mon, 16 Nov 2009 20:39:15 GMT
|
65
|
+
# Expires: -1
|
66
|
+
# Cache-Control: private, max-age=0
|
67
|
+
# Content-Type: text/xml; charset=utf-8
|
68
|
+
# Connection: close
|
69
|
+
|
70
|
+
# <?xml version="1.0" encoding="UTF-8"?>
|
71
|
+
# <response>
|
72
|
+
# <lst name="responseHeader"><int name="status">0</int><int name="QTime">1</int><lst name="params"><str name="q">a</str></lst></lst><result name="response" numFound="0" start="0"/>
|
73
|
+
# </response>
|
74
|
+
# EOM
|
75
|
+
# EM::MockHttpRequest.register 'http://127.0.0.1:8983/solr/select?q=a', :get, body
|
76
|
+
|
77
|
+
# Fiber.new do
|
78
|
+
# begin
|
79
|
+
# http = new_connection
|
80
|
+
# resp = http.request('/select', :q=>'a')
|
81
|
+
# resp[:status_code].should == 200
|
82
|
+
# rescue Exception => ex
|
83
|
+
# puts ex.message
|
84
|
+
# puts ex.backtrace.join("\n")
|
85
|
+
# end
|
86
|
+
# EM.stop
|
87
|
+
# end.resume
|
88
|
+
# end
|
89
|
+
|
90
|
+
# end
|
91
|
+
# end
|
92
|
+
|
93
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsolr-patron
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathan Witmer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-03-15 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rsolr
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.12.1
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: patron
|
37
|
+
type: :runtime
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.4.5
|
44
|
+
version:
|
45
|
+
description: Provides http connections to Solr via Patron/libcurl
|
46
|
+
email: nwitmer@gmail.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- LICENSE
|
56
|
+
- README.rdoc
|
57
|
+
- VERSION
|
58
|
+
- lib/rsolr-patron.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://github.com/aniero/rsolr-patron
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options:
|
65
|
+
- --charset=UTF-8
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
version:
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.3.5
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A Patron connection adapter for RSolr
|
87
|
+
test_files:
|
88
|
+
- spec/rsolr-patron_spec.rb
|
89
|
+
- spec/spec.opts
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- Rakefile
|