sru 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sru/client.rb +24 -7
- data/{test.rb → test/client_test.rb} +15 -14
- metadata +29 -22
data/lib/sru/client.rb
CHANGED
@@ -8,6 +8,21 @@ module SRU
|
|
8
8
|
# A client for issuing requests to a particular SRU server.
|
9
9
|
# SRU is a RESTlike information retrieval protocol detailed at
|
10
10
|
# http://www.loc.gov/standards/sru/
|
11
|
+
#
|
12
|
+
# require 'sru'
|
13
|
+
#
|
14
|
+
# client = SRU::Client.new 'http://sru.example.com'
|
15
|
+
#
|
16
|
+
# # fetch a SRU::ExplainResponse object from the server
|
17
|
+
# explain = client.explain
|
18
|
+
#
|
19
|
+
# # issue a search and get back a SRU::SearchRetrieveResponse object
|
20
|
+
# # which serves as an iterator
|
21
|
+
# records = client.search_retrieve 'rosetta stone', :maximumRecords => 5
|
22
|
+
# records.each {|record| puts record}
|
23
|
+
#
|
24
|
+
# # issue a scan request and print out each term
|
25
|
+
# client.scan('king tut', :maximumTerms => 12).each {|term| puts term}
|
11
26
|
|
12
27
|
class Client
|
13
28
|
|
@@ -41,11 +56,12 @@ module SRU
|
|
41
56
|
# as an optional second argument.
|
42
57
|
#
|
43
58
|
# client = SRU::Client.new 'http://example.com/sru'
|
44
|
-
# response = client.search_retrieve
|
59
|
+
# response = client.search_retrieve 'mark twain', maximumRecords => 1
|
45
60
|
|
46
61
|
def search_retrieve(query, options={})
|
47
|
-
options[
|
48
|
-
options[
|
62
|
+
options[:query] = query
|
63
|
+
options[:operation] = 'searchRetrieve'
|
64
|
+
options[:maximumRecords] = 10 unless options.has_key? :maximumRecords
|
49
65
|
doc = get_doc(options)
|
50
66
|
return SearchResponse.new(doc)
|
51
67
|
end
|
@@ -55,11 +71,12 @@ module SRU
|
|
55
71
|
# object. You must supply the first parameter which is the searchClause.
|
56
72
|
# Other SRU options can be sent in a hash as the seond argument.
|
57
73
|
#
|
58
|
-
# scan_response = client.scan 'title
|
74
|
+
# scan_response = client.scan 'title', :maximumTerms => 5
|
59
75
|
|
60
76
|
def scan(clause, options={})
|
61
|
-
options[
|
62
|
-
options[
|
77
|
+
options[:scanClause] = clause
|
78
|
+
options[:operation] = 'scan'
|
79
|
+
options[:maximumTerms] = 5 unless options.has_key? :maximumTerms
|
63
80
|
doc = get_doc(options)
|
64
81
|
return ScanResponse.new(doc)
|
65
82
|
end
|
@@ -71,7 +88,7 @@ module SRU
|
|
71
88
|
|
72
89
|
def get_doc(hash)
|
73
90
|
# all requests get a version
|
74
|
-
hash[
|
91
|
+
hash[:version] = @version
|
75
92
|
|
76
93
|
# don't want to monkey with the original
|
77
94
|
uri = @server.clone
|
@@ -1,9 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift 'lib'
|
4
|
-
require 'test/unit'
|
5
|
-
require 'sru'
|
6
|
-
|
7
1
|
class ClientTests < Test::Unit::TestCase
|
8
2
|
|
9
3
|
def test_explain
|
@@ -31,16 +25,23 @@ class ClientTests < Test::Unit::TestCase
|
|
31
25
|
assert_equal 0, results.entries.size
|
32
26
|
end
|
33
27
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
assert scan.entries.size > 0
|
39
|
-
assert_equal SRU::Term, scan.entries[0].class
|
40
|
-
assert_equal 'low', scan.entries[0].value
|
41
|
-
assert_equal '1', scan.entries[0].number_of_records
|
28
|
+
def test_default_maximum_records
|
29
|
+
client = SRU::Client.new 'http://z3950.loc.gov:7090/voyager'
|
30
|
+
results = client.search_retrieve 'twain'
|
31
|
+
assert_equal 10, results.entries.size
|
42
32
|
end
|
43
33
|
|
34
|
+
# need to find a target that supports scan so we can exercise it
|
35
|
+
#def test_scan
|
36
|
+
# # this scan response appears to be canned might need to change
|
37
|
+
# client = SRU::Client.new 'http://tweed.lib.ed.ac.uk:8080/elf/search/copac'
|
38
|
+
# scan = client.scan('foobar')
|
39
|
+
# assert scan.entries.size > 0
|
40
|
+
# assert_equal SRU::Term, scan.entries[0].class
|
41
|
+
# assert_equal 'low', scan.entries[0].value
|
42
|
+
# assert_equal '1', scan.entries[0].number_of_records
|
43
|
+
#end
|
44
|
+
|
44
45
|
def test_xml_exception
|
45
46
|
assert_raise(SRU::Exception) {SRU::Client.new 'http://www.google.com'}
|
46
47
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.
|
2
|
+
rubygems_version: 0.9.0
|
3
3
|
specification_version: 1
|
4
4
|
name: sru
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2006-
|
8
|
-
summary:
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2006-10-25 00:00:00 -04:00
|
8
|
+
summary: a Ruby library for Search and Retrieve by URL
|
9
9
|
require_paths:
|
10
|
-
|
10
|
+
- lib
|
11
11
|
email: ehs@pobox.com
|
12
12
|
homepage: http://www.textualize.com/sruby
|
13
13
|
rubyforge_project:
|
@@ -18,31 +18,38 @@ bindir: bin
|
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
20
|
requirements:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: 0.0.0
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
25
24
|
version:
|
26
25
|
platform: ruby
|
27
26
|
signing_key:
|
28
27
|
cert_chain:
|
28
|
+
post_install_message:
|
29
29
|
authors:
|
30
|
-
|
30
|
+
- Ed Summers
|
31
31
|
files:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
- lib/sru
|
33
|
+
- lib/sru.rb
|
34
|
+
- lib/sru/client.rb
|
35
|
+
- lib/sru/exception.rb
|
36
|
+
- lib/sru/explain.rb
|
37
|
+
- lib/sru/response.rb
|
38
|
+
- lib/sru/scan.rb
|
39
|
+
- lib/sru/search_retrieve.rb
|
40
|
+
- lib/sru/term.rb
|
41
|
+
- test/client_test.rb
|
42
|
+
test_files: []
|
43
|
+
|
43
44
|
rdoc_options: []
|
45
|
+
|
44
46
|
extra_rdoc_files: []
|
47
|
+
|
45
48
|
executables: []
|
49
|
+
|
46
50
|
extensions: []
|
51
|
+
|
47
52
|
requirements: []
|
48
|
-
|
53
|
+
|
54
|
+
dependencies: []
|
55
|
+
|