dnz-client 0.0.5 → 0.0.7
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/History.txt +4 -0
- data/Rakefile +1 -0
- data/lib/dnz/client.rb +11 -2
- data/lib/dnz/search.rb +9 -2
- data/lib/dnz.rb +1 -1
- data/spec/dnz/search_spec.rb +11 -4
- metadata +3 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -16,6 +16,7 @@ $hoe = Hoe.spec 'dnz-client' do
|
|
16
16
|
self.description = "Ruby library for accessing Digital New Zealand's search API (digitalnz.org)"
|
17
17
|
#self.rubyforge_name = self.name # TODO this is default value
|
18
18
|
self.extra_deps = [['activesupport','>= 2.0.2'], ['nokogiri', '>= 1.2.3']]
|
19
|
+
self.extra_rdoc_files << 'README.rdoc'
|
19
20
|
end
|
20
21
|
|
21
22
|
require 'newgem/tasks'
|
data/lib/dnz/client.rb
CHANGED
@@ -21,11 +21,13 @@ module DNZ
|
|
21
21
|
# The version of the API to use (defaults to v1)
|
22
22
|
attr_reader :version
|
23
23
|
|
24
|
+
# API URLS
|
24
25
|
APIS = {
|
25
26
|
:search => 'records/${version}.xml/',
|
26
27
|
:custom_search => 'custom_searches/${version}/${custom_search}.xml'
|
27
28
|
}
|
28
29
|
|
30
|
+
# API Arguments
|
29
31
|
ARGS = {
|
30
32
|
:v1 => {
|
31
33
|
:search => Set.new([
|
@@ -114,14 +116,21 @@ module DNZ
|
|
114
116
|
# * <tt>:num_results</tt> - The number of results to return in this call. Defaults to 20.
|
115
117
|
# * <tt>:start</tt> - The starting offset of the results.
|
116
118
|
# * <tt>:facets</tt> - The facets to return for this search.
|
117
|
-
# * <tt>:filter</tt> - A hash of filters to apply to the results
|
119
|
+
# * <tt>:filter</tt> - A hash of filters to apply to the results. Filters can be a string value or
|
120
|
+
# an array of string values.
|
118
121
|
# * <tt>:custom_search</tt> - The name of a custom search created at http://digitalnz.org
|
119
122
|
#
|
120
123
|
# ==== Example
|
121
|
-
# search = client.search('
|
124
|
+
# search = client.search('rugby', :num_results => 50)
|
122
125
|
# search.results.each_with_index do |result, index|
|
123
126
|
# puts "#{index+1}: #{result.title}"
|
124
127
|
# end
|
128
|
+
#
|
129
|
+
# ==== Filter example
|
130
|
+
# This example will search for rugby items with the category Images or Web pages.
|
131
|
+
#
|
132
|
+
# search = client.search('rugby', :filter => {:category => ['Images', 'Web pages']})
|
133
|
+
#
|
125
134
|
def search(text, options = {})
|
126
135
|
options.reverse_merge!(
|
127
136
|
:search_text => text,
|
data/lib/dnz/search.rb
CHANGED
@@ -105,7 +105,14 @@ module DNZ
|
|
105
105
|
filter = @search_options[:filter]
|
106
106
|
filter = {} unless filter.is_a?(Hash)
|
107
107
|
filter.symbolize_keys!
|
108
|
-
filter.map
|
108
|
+
filter.map do |k,v|
|
109
|
+
if v.is_a?(Array)
|
110
|
+
# OR together multiple values for the same filter
|
111
|
+
'(' + v.map{|i| '%s:"%s"' % [k,i]}.join(' OR ') + ')'
|
112
|
+
else
|
113
|
+
'%s:"%s"' % [k,v]
|
114
|
+
end
|
115
|
+
end
|
109
116
|
end
|
110
117
|
memoize :parsed_search_filter
|
111
118
|
|
@@ -210,4 +217,4 @@ module DNZ
|
|
210
217
|
end
|
211
218
|
end
|
212
219
|
end
|
213
|
-
end
|
220
|
+
end
|
data/lib/dnz.rb
CHANGED
data/spec/dnz/search_spec.rb
CHANGED
@@ -54,17 +54,24 @@ describe Search do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
describe 'filtering' do
|
57
|
-
|
57
|
+
it 'should call @client.fetch with the search text set to \'test AND category:"Images"\'' do
|
58
58
|
@options = {:search_text => 'test', :filter => {:category => 'Images'}}
|
59
|
+
@client.should_receive(:fetch).with(
|
60
|
+
:search,
|
61
|
+
:search_text => 'test AND category:"Images"',
|
62
|
+
:facets => ""
|
63
|
+
).and_return(@xml)
|
64
|
+
Search.new(@client, @options)
|
59
65
|
end
|
60
66
|
|
61
|
-
it 'should call @client.fetch with the search text set to \'test AND category:"Images"\'' do
|
67
|
+
it 'should call @client.fetch with the search text set to \'test AND (category:"Images" OR category:"Videos"\'' do
|
68
|
+
@options = {:search_text => 'test', :filter => {:category => ['Images', 'Videos']}}
|
62
69
|
@client.should_receive(:fetch).with(
|
63
70
|
:search,
|
64
|
-
:search_text => 'test AND category:"Images"',
|
71
|
+
:search_text => 'test AND (category:"Images" OR category:"Videos")',
|
65
72
|
:facets => ""
|
66
73
|
).and_return(@xml)
|
67
74
|
Search.new(@client, @options)
|
68
75
|
end
|
69
76
|
end
|
70
|
-
end
|
77
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dnz-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Wells
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-16 00:00:00 +13:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -54,6 +54,7 @@ extra_rdoc_files:
|
|
54
54
|
- Manifest.txt
|
55
55
|
- PostInstall.txt
|
56
56
|
- License.txt
|
57
|
+
- README.rdoc
|
57
58
|
files:
|
58
59
|
- History.txt
|
59
60
|
- Manifest.txt
|