dnz-client 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Rakefile +0 -2
- data/lib/dnz/client.rb +7 -2
- data/lib/dnz/search.rb +8 -3
- data/lib/dnz.rb +1 -1
- data/spec/dnz/client_spec.rb +5 -0
- data/tasks/rspec.rake +3 -15
- metadata +2 -2
data/History.txt
CHANGED
data/Rakefile
CHANGED
data/lib/dnz/client.rb
CHANGED
@@ -100,13 +100,18 @@ module DNZ
|
|
100
100
|
|
101
101
|
# Get a list of all categories using the 'category' facet.
|
102
102
|
#
|
103
|
+
# ==== Options
|
104
|
+
#
|
105
|
+
# * <tt>:custom_search</tt> - The name of a custom search created at http://digitalnz.org
|
106
|
+
#
|
103
107
|
# ==== Example
|
104
108
|
# categories = client.categories
|
105
109
|
# categories.each do |category|
|
106
110
|
# puts category.name
|
107
111
|
# end
|
108
|
-
def categories
|
109
|
-
|
112
|
+
def categories(options = {})
|
113
|
+
options = options.merge(:facets => 'category', :facet_num_results => 100)
|
114
|
+
search('*:*', options).facets['category'].values
|
110
115
|
end
|
111
116
|
|
112
117
|
# Run a search using the digitalnz.org API.
|
data/lib/dnz/search.rb
CHANGED
@@ -75,7 +75,7 @@ module DNZ
|
|
75
75
|
|
76
76
|
# The number of pages available for the current search.
|
77
77
|
def pages
|
78
|
-
num_results_requested < result_count ? (result_count.to_f / num_results_requested).ceil :
|
78
|
+
num_results_requested < result_count ? (result_count.to_f / num_results_requested).ceil : 1
|
79
79
|
end
|
80
80
|
|
81
81
|
# The number of results requested via the :num_results option (see <tt>Client.search</tt>).
|
@@ -83,12 +83,17 @@ module DNZ
|
|
83
83
|
@num_results_requested || 20
|
84
84
|
end
|
85
85
|
|
86
|
+
def inspect
|
87
|
+
self.to_s
|
88
|
+
end
|
89
|
+
|
86
90
|
def to_s
|
87
91
|
{
|
88
|
-
:results => self.
|
92
|
+
:results => self.result_count,
|
89
93
|
:facets => self.facets.length,
|
90
94
|
:page => self.page,
|
91
|
-
:pages => self.pages
|
95
|
+
:pages => self.pages,
|
96
|
+
:per_page => self.num_results_requested
|
92
97
|
}.inspect
|
93
98
|
end
|
94
99
|
|
data/lib/dnz.rb
CHANGED
data/spec/dnz/client_spec.rb
CHANGED
@@ -141,6 +141,11 @@ describe Client do
|
|
141
141
|
@client.should_receive(:search).with('*:*', :facets => 'category', :facet_num_results => 100).and_return(@search)
|
142
142
|
@client.categories
|
143
143
|
end
|
144
|
+
|
145
|
+
it 'should run a search with custom_search' do
|
146
|
+
@client.should_receive(:search).with('*:*', :facets => 'category', :facet_num_results => 100, :custom_search => 'test').and_return(@search)
|
147
|
+
@client.categories(:custom_search => 'test')
|
148
|
+
end
|
144
149
|
|
145
150
|
it 'should return the categories facet' do
|
146
151
|
@client.categories.should == @categories
|
data/tasks/rspec.rake
CHANGED
@@ -1,18 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'spec'
|
6
|
-
end
|
7
|
-
begin
|
8
|
-
require 'spec/rake/spectask'
|
9
|
-
rescue LoadError
|
10
|
-
puts <<-EOS
|
11
|
-
To use rspec for testing you must install rspec gem:
|
12
|
-
gem install rspec
|
13
|
-
EOS
|
14
|
-
exit(0)
|
15
|
-
end
|
1
|
+
require 'spec'
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
16
4
|
|
17
5
|
desc "Run the specs under spec"
|
18
6
|
Spec::Rake::SpecTask.new do |t|
|
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.8
|
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-11-
|
12
|
+
date: 2009-11-19 00:00:00 +13:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|