rsolr-em 0.0.2
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 +13 -0
- data/README.rdoc +21 -0
- data/Rakefile +14 -0
- data/VERSION +1 -0
- data/lib/rsolr-em.rb +73 -0
- metadata +95 -0
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2010 Colin Steele / Matt Mitchell
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
=RSolr::EM
|
2
|
+
|
3
|
+
Used like so:
|
4
|
+
|
5
|
+
EM.run do
|
6
|
+
http = RSolr::EM.new 'http://localhost:8983/solr/'
|
7
|
+
solr = RSolr::Client.new http
|
8
|
+
solr.get('select',
|
9
|
+
:params => {:q => '*:*'},
|
10
|
+
:on_success => proc do |response, req, res|
|
11
|
+
p 'success'
|
12
|
+
p response
|
13
|
+
EM.stop
|
14
|
+
end,
|
15
|
+
:on_error => proc do |req,res,e|
|
16
|
+
p 'error'
|
17
|
+
puts e.to_s
|
18
|
+
EM.stop
|
19
|
+
end
|
20
|
+
)
|
21
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
|
6
|
+
ENV['RUBYOPT'] = '-W1'
|
7
|
+
|
8
|
+
task :environment do
|
9
|
+
require File.dirname(__FILE__) + '/lib/rsolr-em'
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
13
|
+
|
14
|
+
task :default => ['spec:api']
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/lib/rsolr-em.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "eventmachine"
|
2
|
+
require "em-http"
|
3
|
+
require "rsolr"
|
4
|
+
|
5
|
+
# Need by em-http on ruby 1.8 :(
|
6
|
+
unless "".respond_to?(:bytesize)
|
7
|
+
class String
|
8
|
+
alias :bytesize :size
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module RSolr
|
13
|
+
|
14
|
+
class EM
|
15
|
+
|
16
|
+
def execute client, request_context
|
17
|
+
method = request_context[:method]
|
18
|
+
options = {}
|
19
|
+
options[:head] = request_context[:headers] if request_context[:headers]
|
20
|
+
options[:body] = request_context[:data] if request_context[:body].to_s
|
21
|
+
options[:proxy] ||= request_context[:proxy] if request_context[:proxy]
|
22
|
+
|
23
|
+
uri = request_context[:uri]
|
24
|
+
http_request = EventMachine::HttpRequest.new(uri.to_s)
|
25
|
+
http = http_request.send(method, options)
|
26
|
+
|
27
|
+
success_cb = request_context[:success] || request_context[:callback]
|
28
|
+
error_cb = request_context[:error] || request_context[:errback]
|
29
|
+
|
30
|
+
http.callback { |http|
|
31
|
+
begin
|
32
|
+
response_hash = {
|
33
|
+
:body => http.response,
|
34
|
+
:status => http.response_header.status,
|
35
|
+
:headers => http.response_header
|
36
|
+
}
|
37
|
+
solr_response = client.adapt_response(request_context, response_hash)
|
38
|
+
success_cb_args = case success_cb.arity
|
39
|
+
when 1
|
40
|
+
[solr_response]
|
41
|
+
when 2
|
42
|
+
[solr_response, request_context]
|
43
|
+
when 3
|
44
|
+
[solr_response, request_context, response_hash]
|
45
|
+
end
|
46
|
+
success_cb.call *success_cb_args
|
47
|
+
rescue
|
48
|
+
if error_cb
|
49
|
+
error_cb_args = case error_cb.arity
|
50
|
+
when 1
|
51
|
+
[$!]
|
52
|
+
when 2
|
53
|
+
[$!, request_context, response_hash]
|
54
|
+
when 3
|
55
|
+
[$!, request_context, response_hash]
|
56
|
+
end
|
57
|
+
error_cb.call *error_cb_args
|
58
|
+
else
|
59
|
+
raise $!
|
60
|
+
end
|
61
|
+
end # begin/rescue clause
|
62
|
+
}
|
63
|
+
http.errback {
|
64
|
+
if error_cb
|
65
|
+
error_cb.call request_context, {}, nil
|
66
|
+
end
|
67
|
+
}
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
|
71
|
+
end # EMHttp
|
72
|
+
|
73
|
+
end # RSolr
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsolr-em
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Colin Steele
|
13
|
+
- Matt Mitchell
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-10-17 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: eventmachine
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 12
|
31
|
+
- 10
|
32
|
+
version: 0.12.10
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rsolr
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
- beta3
|
47
|
+
version: 1.0.0.beta3
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: EventMachine/async based connection driver for RSolr -- compatible with Ruby 1.8
|
51
|
+
email: goodieboy@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- LICENSE
|
61
|
+
- README.rdoc
|
62
|
+
- VERSION
|
63
|
+
- lib/rsolr-em.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/mwmitchell/rsolr-em
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
requirements: []
|
88
|
+
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.3.6
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: EventMachine Connection for RSolr
|
94
|
+
test_files:
|
95
|
+
- Rakefile
|