eshopworks-rboss 0.1.3 → 0.1.5
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.
- metadata +7 -43
- data/History.txt +0 -13
- data/License.txt +0 -20
- data/Manifest.txt +0 -34
- data/README.textile +0 -196
- data/Rakefile +0 -4
- data/TODO.txt +0 -3
- data/config/hoe.rb +0 -69
- data/config/requirements.rb +0 -15
- data/gem_tasks/deployment.rake +0 -34
- data/gem_tasks/environment.rake +0 -7
- data/gem_tasks/fix_cr_lf.rake +0 -10
- data/gem_tasks/gemspec.rake +0 -6
- data/gem_tasks/rspec.rake +0 -27
- data/gem_tasks/verify_rcov.rake +0 -7
- data/gem_tasks/website.rake +0 -17
- data/lib/boss/api.rb +0 -106
- data/lib/boss/config.rb +0 -18
- data/lib/boss/result/base.rb +0 -15
- data/lib/boss/result/image.rb +0 -8
- data/lib/boss/result/news.rb +0 -8
- data/lib/boss/result/spell.rb +0 -8
- data/lib/boss/result/web.rb +0 -8
- data/lib/boss/result.rb +0 -1
- data/lib/boss/result_collection.rb +0 -27
- data/lib/boss/result_factory.rb +0 -53
- data/lib/boss/version.rb +0 -9
- data/lib/boss.rb +0 -17
- data/rboss.gemspec +0 -41
- data/spec/boss/api_spec.rb +0 -160
- data/spec/boss/config_spec.rb +0 -33
- data/spec/boss/result_collection_spec.rb +0 -24
- data/spec/boss/result_factory_spec.rb +0 -57
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -7
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eshopworks-rboss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Wilk
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: json_pure
|
17
17
|
version_requirement:
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
@@ -55,46 +55,10 @@ executables: []
|
|
55
55
|
|
56
56
|
extensions: []
|
57
57
|
|
58
|
-
extra_rdoc_files:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
- TODO.txt
|
63
|
-
files:
|
64
|
-
- History.txt
|
65
|
-
- License.txt
|
66
|
-
- Manifest.txt
|
67
|
-
- README.textile
|
68
|
-
- Rakefile
|
69
|
-
- TODO.txt
|
70
|
-
- config/hoe.rb
|
71
|
-
- config/requirements.rb
|
72
|
-
- gem_tasks/deployment.rake
|
73
|
-
- gem_tasks/environment.rake
|
74
|
-
- gem_tasks/fix_cr_lf.rake
|
75
|
-
- gem_tasks/gemspec.rake
|
76
|
-
- gem_tasks/rspec.rake
|
77
|
-
- gem_tasks/verify_rcov.rake
|
78
|
-
- gem_tasks/website.rake
|
79
|
-
- lib/boss.rb
|
80
|
-
- lib/boss/api.rb
|
81
|
-
- lib/boss/config.rb
|
82
|
-
- lib/boss/result.rb
|
83
|
-
- lib/boss/result/base.rb
|
84
|
-
- lib/boss/result/image.rb
|
85
|
-
- lib/boss/result/news.rb
|
86
|
-
- lib/boss/result/spell.rb
|
87
|
-
- lib/boss/result/web.rb
|
88
|
-
- lib/boss/result_collection.rb
|
89
|
-
- lib/boss/result_factory.rb
|
90
|
-
- lib/boss/version.rb
|
91
|
-
- rboss.gemspec
|
92
|
-
- spec/boss/api_spec.rb
|
93
|
-
- spec/boss/config_spec.rb
|
94
|
-
- spec/boss/result_collection_spec.rb
|
95
|
-
- spec/boss/result_factory_spec.rb
|
96
|
-
- spec/spec.opts
|
97
|
-
- spec/spec_helper.rb
|
58
|
+
extra_rdoc_files: []
|
59
|
+
|
60
|
+
files: []
|
61
|
+
|
98
62
|
has_rdoc: true
|
99
63
|
homepage: http://github.com/eshopworks/rboss-gem
|
100
64
|
post_install_message:
|
data/History.txt
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
=== Version 0.1.3
|
2
|
-
* Fix for duplicate information being storied in the ResultCollection
|
3
|
-
|
4
|
-
=== Version 0.1.2
|
5
|
-
* Maintain search result data in ResultCollection
|
6
|
-
|
7
|
-
=== Version 0.1.1
|
8
|
-
* Fixed exact search error
|
9
|
-
* search method takes the same arguments as other search methods
|
10
|
-
* Encodes parameters correctly
|
11
|
-
|
12
|
-
=== Version 0.1.0
|
13
|
-
* Brand spanking new release.
|
data/License.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 eShopworks
|
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/Manifest.txt
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
License.txt
|
3
|
-
Manifest.txt
|
4
|
-
README.textile
|
5
|
-
Rakefile
|
6
|
-
TODO.txt
|
7
|
-
config/hoe.rb
|
8
|
-
config/requirements.rb
|
9
|
-
gem_tasks/deployment.rake
|
10
|
-
gem_tasks/environment.rake
|
11
|
-
gem_tasks/fix_cr_lf.rake
|
12
|
-
gem_tasks/gemspec.rake
|
13
|
-
gem_tasks/rspec.rake
|
14
|
-
gem_tasks/verify_rcov.rake
|
15
|
-
gem_tasks/website.rake
|
16
|
-
lib/boss.rb
|
17
|
-
lib/boss/api.rb
|
18
|
-
lib/boss/config.rb
|
19
|
-
lib/boss/result.rb
|
20
|
-
lib/boss/result/base.rb
|
21
|
-
lib/boss/result/image.rb
|
22
|
-
lib/boss/result/news.rb
|
23
|
-
lib/boss/result/spell.rb
|
24
|
-
lib/boss/result/web.rb
|
25
|
-
lib/boss/result_collection.rb
|
26
|
-
lib/boss/result_factory.rb
|
27
|
-
lib/boss/version.rb
|
28
|
-
rboss.gemspec
|
29
|
-
spec/boss/api_spec.rb
|
30
|
-
spec/boss/config_spec.rb
|
31
|
-
spec/boss/result_collection_spec.rb
|
32
|
-
spec/boss/result_factory_spec.rb
|
33
|
-
spec/spec.opts
|
34
|
-
spec/spec_helper.rb
|
data/README.textile
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
h1. RBoss Gem - Yahoo! Boss Search
|
2
|
-
|
3
|
-
h2. DESCRIPTION:
|
4
|
-
|
5
|
-
A handy gem to make using the Yahoo Boss API nice and easy in ruby.
|
6
|
-
|
7
|
-
"Yahoo! Boss Search official site":http://developer.yahoo.com/search/boss/
|
8
|
-
|
9
|
-
"Yahoo! Boss Search API":http://developer.yahoo.com/search/boss/boss_guide/
|
10
|
-
|
11
|
-
Add feature requests and bugs here: "http://eshopworks.lighthouseapp.com/projects/15732-rboss/overview":http://eshopworks.lighthouseapp.com/projects/15732-rboss/overview
|
12
|
-
|
13
|
-
h2. FEATURES:
|
14
|
-
|
15
|
-
Search
|
16
|
-
* Images
|
17
|
-
* News
|
18
|
-
* Web
|
19
|
-
|
20
|
-
Also spelling suggestions
|
21
|
-
|
22
|
-
Return results as:
|
23
|
-
* JSON string
|
24
|
-
* XML string
|
25
|
-
* Plain old ruby objects (POROs)
|
26
|
-
|
27
|
-
h2. INSTALL:
|
28
|
-
|
29
|
-
<pre><code>
|
30
|
-
gem sources --add http://gems.github.com/
|
31
|
-
gem install eshopworks-rboss
|
32
|
-
</code></pre>
|
33
|
-
|
34
|
-
Get a yahoo boss api-key: "http://developer.yahoo.com/wsregapp":http://developer.yahoo.com/wsregapp
|
35
|
-
|
36
|
-
h2. USAGE:
|
37
|
-
|
38
|
-
<pre><code>
|
39
|
-
require 'rubygems'
|
40
|
-
require 'boss'
|
41
|
-
|
42
|
-
api = Boss::Api.new('boss-api-key-got-from-yahoo')
|
43
|
-
|
44
|
-
#Search defaults to web search with following defaults
|
45
|
-
# count = 10
|
46
|
-
# format = object (ruby object)
|
47
|
-
# lang = eng
|
48
|
-
api.search('monkeys')
|
49
|
-
|
50
|
-
#Delimit multiple search terms with commas
|
51
|
-
api.search('dancing,monkeys')
|
52
|
-
|
53
|
-
#Delimit Exact search with quotation marks
|
54
|
-
api.search('"dancing monkeys"')
|
55
|
-
|
56
|
-
#Search images, spelling, news and web
|
57
|
-
api.search_images('monkeys')
|
58
|
-
api.search_spelling('monkeys')
|
59
|
-
api.search_news('monkeys')
|
60
|
-
api.search_web('monkeys')
|
61
|
-
|
62
|
-
#By default returns ruby object results
|
63
|
-
results = api.search_web('monkeys')
|
64
|
-
results.each { |web| puts web.title }
|
65
|
-
|
66
|
-
#Configure search with hash
|
67
|
-
xml = api.search_spelling('monkeys', :format => 'xml', :count => 5)
|
68
|
-
|
69
|
-
#Configure search with block
|
70
|
-
xml = api.search_spelling('monkeys') do |config|
|
71
|
-
config.format = 'xml'
|
72
|
-
config.count = 5
|
73
|
-
end
|
74
|
-
|
75
|
-
#Access general search result information
|
76
|
-
results = api.search('monkeys', :count => 5)
|
77
|
-
puts results.totalhits
|
78
|
-
</code></pre>
|
79
|
-
|
80
|
-
h3. Global Search Options (applies to news/images/web search)
|
81
|
-
|
82
|
-
<pre><code>
|
83
|
-
api.search('monkeys') do |config|
|
84
|
-
config.start = 1
|
85
|
-
config.count = 10
|
86
|
-
config.lang = 'en'
|
87
|
-
config.region = 'us'
|
88
|
-
config.format = 'xml'
|
89
|
-
config.callback = ''
|
90
|
-
config.sites = 'abc.com,cnn.com'
|
91
|
-
end
|
92
|
-
</pre></code>
|
93
|
-
|
94
|
-
h3. Global Search Results data (applies to news/images/web search results)
|
95
|
-
|
96
|
-
<pre><code>
|
97
|
-
results = api.search('monkeys', :count => 1)
|
98
|
-
puts results.deephits #approximate count that includes duplicates
|
99
|
-
puts results.totalhits #approximate count that excludes duplicates
|
100
|
-
puts results.responsecode #response code return by Yahoo webservice
|
101
|
-
puts results.start #the first numeric result to display
|
102
|
-
puts results.count #Indicates how many results to show per page
|
103
|
-
puts results.nextpage #link to what would be the next page of search results
|
104
|
-
</pre></code>
|
105
|
-
|
106
|
-
h3. Web Search Result
|
107
|
-
|
108
|
-
<pre><code>
|
109
|
-
#We filter here to exclude certain types of content
|
110
|
-
results = api.search_web('monkeys', :filter => '-porn')
|
111
|
-
results.each do |web|
|
112
|
-
puts web.abstract
|
113
|
-
puts web.date
|
114
|
-
puts web.dispurl #URL of document matching the query result.
|
115
|
-
puts web.clickurl #navigation URL that leads to the target URL
|
116
|
-
puts web.size #document’s size in bytes
|
117
|
-
puts web.title
|
118
|
-
puts web.url
|
119
|
-
end
|
120
|
-
</code></pre>
|
121
|
-
|
122
|
-
h3. News Search Result
|
123
|
-
|
124
|
-
<pre><code>
|
125
|
-
#We retrieve documents by age (possible options: [1-30]d )
|
126
|
-
results = api.search_news('monkeys', :age => '7d')
|
127
|
-
results.each do |news|
|
128
|
-
puts news.abstract
|
129
|
-
puts news.clickurl
|
130
|
-
puts news.title
|
131
|
-
puts news.language
|
132
|
-
puts news.date
|
133
|
-
puts news.time
|
134
|
-
puts news.source
|
135
|
-
puts news.sourceurl
|
136
|
-
puts news.url
|
137
|
-
end
|
138
|
-
</code></pre>
|
139
|
-
|
140
|
-
h3. Image Search Result
|
141
|
-
|
142
|
-
<pre><code>
|
143
|
-
#Add constraint on dimension (possible options: 'small', 'medium', 'large', 'wallpaper')
|
144
|
-
#Activate the Offensive Content Reduction filter
|
145
|
-
results = api.search_images('monkeys', :dimensions => 'small', :filter => 'true')
|
146
|
-
results.each do |image|
|
147
|
-
puts image.abstract
|
148
|
-
puts image.clickurl
|
149
|
-
puts image.filename
|
150
|
-
puts image.size
|
151
|
-
puts image.format
|
152
|
-
puts image.height
|
153
|
-
puts image.date
|
154
|
-
puts image.mimetype
|
155
|
-
puts image.refererclickurl
|
156
|
-
puts image.refererurl
|
157
|
-
puts image.title
|
158
|
-
puts image.url
|
159
|
-
puts image.width
|
160
|
-
puts image.thumbnail_height
|
161
|
-
puts image.thumbnail_url
|
162
|
-
puts image.thumbnail_width
|
163
|
-
end
|
164
|
-
</code></pre>
|
165
|
-
|
166
|
-
h3. Spell Search Result
|
167
|
-
|
168
|
-
<pre><code>
|
169
|
-
results = api.search_spelling('monkeys')
|
170
|
-
results.each do |spell|
|
171
|
-
puts spell.suggestion
|
172
|
-
end
|
173
|
-
</code></pre>
|
174
|
-
|
175
|
-
h2. LICENSE:
|
176
|
-
|
177
|
-
Copyright (c) 2008 eShopworks
|
178
|
-
|
179
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
180
|
-
a copy of this software and associated documentation files (the
|
181
|
-
"Software"), to deal in the Software without restriction, including
|
182
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
183
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
184
|
-
permit persons to whom the Software is furnished to do so, subject to
|
185
|
-
the following conditions:
|
186
|
-
|
187
|
-
The above copyright notice and this permission notice shall be
|
188
|
-
included in all copies or substantial portions of the Software.
|
189
|
-
|
190
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
191
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
192
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
193
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
194
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
195
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
196
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
data/TODO.txt
DELETED
data/config/hoe.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'boss'
|
2
|
-
require 'boss/version'
|
3
|
-
|
4
|
-
AUTHOR = 'Joseph Wilk' # can also be an array of Authors
|
5
|
-
EMAIL = "joe@eshopworks.co.uk"
|
6
|
-
DESCRIPTION = "Api wrapping Yahoo Boss search"
|
7
|
-
GEM_NAME = 'rboss' # what ppl will type to install your gem
|
8
|
-
HOMEPATH = "http://github.com/eshopworks/rboss-gem"
|
9
|
-
RUBYFORGE_PROJECT = nil
|
10
|
-
|
11
|
-
@config_file = "~/.rubyforge/user-config.yml"
|
12
|
-
@config = nil
|
13
|
-
RUBYFORGE_USERNAME = "eshopworks"
|
14
|
-
def rubyforge_username
|
15
|
-
unless @config
|
16
|
-
begin
|
17
|
-
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
18
|
-
rescue
|
19
|
-
puts <<-EOS
|
20
|
-
ERROR: No rubyforge config file found: #{@config_file}
|
21
|
-
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
22
|
-
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
23
|
-
EOS
|
24
|
-
exit
|
25
|
-
end
|
26
|
-
end
|
27
|
-
RUBYFORGE_USERNAME.replace @config["username"]
|
28
|
-
end
|
29
|
-
|
30
|
-
|
31
|
-
REV = nil
|
32
|
-
# UNCOMMENT IF REQUIRED:
|
33
|
-
# REV = YAML.load(`svn info`)['Revision']
|
34
|
-
VERS = Boss::VERSION::STRING + (REV ? ".#{REV}" : "")
|
35
|
-
RDOC_OPTS = ['--quiet', '--title', 'RBoss documentation',
|
36
|
-
"--opname", "index.html",
|
37
|
-
"--line-numbers",
|
38
|
-
"--main", "README.textile",
|
39
|
-
"--inline-source"]
|
40
|
-
|
41
|
-
class Hoe
|
42
|
-
def extra_deps
|
43
|
-
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
44
|
-
@extra_deps
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# Generate all the Rake tasks
|
49
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
50
|
-
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
51
|
-
p.developer(AUTHOR, EMAIL)
|
52
|
-
p.description = DESCRIPTION
|
53
|
-
p.summary = DESCRIPTION
|
54
|
-
p.url = HOMEPATH
|
55
|
-
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
56
|
-
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store', '**/*.class', '**/*.jar'] #An array of file patterns to delete on clean.
|
57
|
-
|
58
|
-
# == Optional
|
59
|
-
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
60
|
-
#p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
61
|
-
p.extra_deps = [ ['json', '>= 1.1.3'], ['rspec', '>= 1.1.4'], ['diff-lcs', '>= 1.1.2'] ]
|
62
|
-
|
63
|
-
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
64
|
-
end
|
65
|
-
|
66
|
-
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
67
|
-
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
68
|
-
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
69
|
-
$hoe.rsync_args = '-av --delete --ignore-errors'
|
data/config/requirements.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
include FileUtils
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
%w[rake hoe].each do |req_gem|
|
6
|
-
begin
|
7
|
-
require req_gem
|
8
|
-
rescue LoadError
|
9
|
-
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
-
puts "Installation: gem install #{req_gem} -y"
|
11
|
-
exit
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/gem_tasks/deployment.rake
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
desc 'Release the website and new gem version'
|
2
|
-
task :deploy => [:check_version, :website, :release] do
|
3
|
-
puts "Remember to create SVN tag:"
|
4
|
-
puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
|
5
|
-
"svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
|
6
|
-
puts "Suggested comment:"
|
7
|
-
puts "Tagging release #{CHANGES}"
|
8
|
-
end
|
9
|
-
|
10
|
-
desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
|
11
|
-
task :local_deploy => [:website_generate, :install_gem]
|
12
|
-
|
13
|
-
task :check_version do
|
14
|
-
unless ENV['VERSION']
|
15
|
-
puts 'Must pass a VERSION=x.y.z release version'
|
16
|
-
exit
|
17
|
-
end
|
18
|
-
unless ENV['VERSION'] == VERS
|
19
|
-
puts "Please update your version.rb to match the release version, currently #{VERS}"
|
20
|
-
exit
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
|
25
|
-
task :install_gem_no_doc => [:clean, :package] do
|
26
|
-
sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
|
27
|
-
end
|
28
|
-
|
29
|
-
namespace :manifest do
|
30
|
-
desc 'Recreate Manifest.txt to include ALL files'
|
31
|
-
task :refresh do
|
32
|
-
`rake check_manifest | patch -p0 > Manifest.txt`
|
33
|
-
end
|
34
|
-
end
|
data/gem_tasks/environment.rake
DELETED
data/gem_tasks/fix_cr_lf.rake
DELETED
data/gem_tasks/gemspec.rake
DELETED
data/gem_tasks/rspec.rake
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'spec'
|
3
|
-
rescue LoadError
|
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
|
16
|
-
|
17
|
-
desc "Run the specs under spec/models"
|
18
|
-
Spec::Rake::SpecTask.new do |t|
|
19
|
-
t.spec_opts = ['--options', "spec/spec.opts"]
|
20
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
-
|
22
|
-
unless ENV['NO_RCOV']
|
23
|
-
t.rcov = true
|
24
|
-
t.rcov_dir = 'coverage'
|
25
|
-
t.rcov_opts = ['--exclude', 'spec\/boss,bin\/spec,examples,\/var\/lib\/gems,\/Library\/Ruby,\.autotest']
|
26
|
-
end
|
27
|
-
end
|
data/gem_tasks/verify_rcov.rake
DELETED
data/gem_tasks/website.rake
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
desc 'Generate website files'
|
2
|
-
task :website_generate => :ruby_env do
|
3
|
-
(Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
|
4
|
-
sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
desc 'Upload website files to rubyforge'
|
9
|
-
task :website_upload do
|
10
|
-
host = "#{rubyforge_username}@rubyforge.org"
|
11
|
-
remote_dir = "/var/www/gforge-projects/#{PATH}/"
|
12
|
-
local_dir = 'website'
|
13
|
-
sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
|
14
|
-
end
|
15
|
-
|
16
|
-
desc 'Generate and upload website files'
|
17
|
-
task :website => [:website_generate, :website_upload, :publish_docs]
|
data/lib/boss/api.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'rexml/document'
|
3
|
-
require 'uri'
|
4
|
-
|
5
|
-
require 'cgi'
|
6
|
-
|
7
|
-
|
8
|
-
module Boss
|
9
|
-
|
10
|
-
module SearchType
|
11
|
-
%w[web images news spell].each { |e| const_set(e.upcase, e) }
|
12
|
-
end
|
13
|
-
|
14
|
-
module SearchService
|
15
|
-
#Annoying inconsitency between 'spelling' and 'spell' in api
|
16
|
-
SPELL = 'spelling'
|
17
|
-
end
|
18
|
-
|
19
|
-
FORMATS = %w[xml json]
|
20
|
-
|
21
|
-
class Api
|
22
|
-
|
23
|
-
attr_accessor :endpoint
|
24
|
-
|
25
|
-
def initialize(app_id)
|
26
|
-
@app_id = app_id
|
27
|
-
@endpoint = 'http://boss.yahooapis.com/ysearch/'
|
28
|
-
end
|
29
|
-
|
30
|
-
def search(term, *conditions, &block)
|
31
|
-
search_boss(term, SearchType::WEB, *conditions, &block)
|
32
|
-
end
|
33
|
-
|
34
|
-
def search_images(term, *conditions, &block)
|
35
|
-
search_boss(term, SearchType::IMAGES, *conditions, &block)
|
36
|
-
end
|
37
|
-
|
38
|
-
def search_news(term, *conditions, &block)
|
39
|
-
search_boss(term, SearchType::NEWS, *conditions, &block)
|
40
|
-
end
|
41
|
-
|
42
|
-
def search_web(term, *conditions, &block)
|
43
|
-
search_boss(term, SearchType::WEB, *conditions, &block)
|
44
|
-
end
|
45
|
-
|
46
|
-
def search_spelling(term, *conditions, &block)
|
47
|
-
search_boss(term, SearchService::SPELL, *conditions, &block)
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
def search_boss(terms, search_type=SearchType::WEB, config = {})
|
52
|
-
config = config.empty? ? Config.new : Config.new(config)
|
53
|
-
search_results = []
|
54
|
-
|
55
|
-
yield config if block_given?
|
56
|
-
|
57
|
-
if config.format == 'object'
|
58
|
-
format_as_objects=true
|
59
|
-
config.format= "json"
|
60
|
-
else
|
61
|
-
format_as_objects=false
|
62
|
-
end
|
63
|
-
|
64
|
-
raise InvalidFormat unless (FORMATS.include? config.format)
|
65
|
-
raise InvalidConfig unless (config.count>0)
|
66
|
-
|
67
|
-
request = URI.parse(build_request_url(terms, search_type, config))
|
68
|
-
response = Net::HTTP.get_response(request)
|
69
|
-
|
70
|
-
case response.code
|
71
|
-
when "200"
|
72
|
-
data = response.body
|
73
|
-
|
74
|
-
if format_as_objects
|
75
|
-
search_results = ResultFactory.build(search_type, data)
|
76
|
-
else
|
77
|
-
search_results = data
|
78
|
-
end
|
79
|
-
else
|
80
|
-
raise BossError, parse_error(data)
|
81
|
-
end
|
82
|
-
|
83
|
-
search_results
|
84
|
-
end
|
85
|
-
|
86
|
-
#TODO: parse error responses
|
87
|
-
def parse_error(data)
|
88
|
-
"Error contacting Yahoo Boss web-service"
|
89
|
-
end
|
90
|
-
|
91
|
-
protected
|
92
|
-
def build_request_url(terms, search_type, config)
|
93
|
-
#We could use URI.encode but it leaves things like ? unencoded which fails search.
|
94
|
-
encoded_terms = CGI.escape(terms)
|
95
|
-
# puts "#{@endpoint}#{search_type}/#{boss_version}/#{encoded_terms}?appid=#{@app_id}#{config.to_url}"
|
96
|
-
"#{@endpoint}#{search_type}/#{boss_version}/#{encoded_terms}?appid=#{@app_id}#{config.to_url}"
|
97
|
-
end
|
98
|
-
|
99
|
-
protected
|
100
|
-
def boss_version
|
101
|
-
"v#{Boss::YAHOO_VERSION}"
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
data/lib/boss/config.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
|
3
|
-
module Boss
|
4
|
-
|
5
|
-
class Config < OpenStruct
|
6
|
-
|
7
|
-
def initialize(hash={})
|
8
|
-
#Setup defaults
|
9
|
-
super({:count => 10, :lang => "en", :format => "object"}.merge(hash))
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_url
|
13
|
-
self.marshal_dump.inject("") {|accum, key| encoded_value=CGI.escape(key[1].to_s); accum+="&#{key[0]}=#{encoded_value}" }
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
data/lib/boss/result/base.rb
DELETED
data/lib/boss/result/image.rb
DELETED
data/lib/boss/result/news.rb
DELETED
data/lib/boss/result/spell.rb
DELETED
data/lib/boss/result/web.rb
DELETED
data/lib/boss/result.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
%w{base web image news spell}.each{|f| require "boss/result/#{f}"}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Boss
|
2
|
-
class ResultCollection
|
3
|
-
include Enumerable
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@results=[]
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_instance_variable(name, value)
|
10
|
-
instance_variable_set("@#{name}",value)
|
11
|
-
instance_eval("def #{name}\n @#{name}\n end")
|
12
|
-
end
|
13
|
-
|
14
|
-
def each
|
15
|
-
@results.each { |result| yield result }
|
16
|
-
end
|
17
|
-
|
18
|
-
def <<(element)
|
19
|
-
@results << element
|
20
|
-
end
|
21
|
-
|
22
|
-
def [](key)
|
23
|
-
@results[key]
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
data/lib/boss/result_factory.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module Boss
|
4
|
-
class ResultFactory
|
5
|
-
|
6
|
-
class << self
|
7
|
-
|
8
|
-
SEARCH_RESPONSE = 'ysearchresponse'
|
9
|
-
RESULT_SET = 'resultset'
|
10
|
-
|
11
|
-
def build(search_type, data)
|
12
|
-
|
13
|
-
#Deal with inconsistency between search service 'spelling' and result 'spell'
|
14
|
-
search_type = SearchType::SPELL if search_type == SearchService::SPELL
|
15
|
-
|
16
|
-
json_hash = JSON.parse(data)
|
17
|
-
|
18
|
-
if json_hash.has_key? 'Error' or !json_hash.has_key? SEARCH_RESPONSE
|
19
|
-
raise BossError, "Results from webservice appear to be mangled."
|
20
|
-
end
|
21
|
-
|
22
|
-
result_collection = ResultCollection.new
|
23
|
-
|
24
|
-
json_hash[SEARCH_RESPONSE].each do |key,value|
|
25
|
-
|
26
|
-
if key == "#{RESULT_SET}_#{search_type}"
|
27
|
-
|
28
|
-
json_hash[SEARCH_RESPONSE]["#{RESULT_SET}_#{search_type}"].each do |result|
|
29
|
-
|
30
|
-
case search_type
|
31
|
-
when SearchType::WEB
|
32
|
-
result_collection << Result::Web.new(result)
|
33
|
-
when SearchType::IMAGES
|
34
|
-
result_collection << Result::Image.new(result)
|
35
|
-
when SearchType::NEWS
|
36
|
-
result_collection << Result::News.new(result)
|
37
|
-
when SearchType::SPELL
|
38
|
-
result_collection << Result::Spell.new(result)
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
else
|
43
|
-
result_collection.set_instance_variable(key, value)
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
result_collection
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
data/lib/boss/version.rb
DELETED
data/lib/boss.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
|
-
require 'boss/api'
|
5
|
-
require 'boss/config'
|
6
|
-
require 'boss/result'
|
7
|
-
require 'boss/result_collection'
|
8
|
-
require 'boss/result_factory'
|
9
|
-
require 'boss/version'
|
10
|
-
|
11
|
-
module Boss
|
12
|
-
YAHOO_VERSION = 1
|
13
|
-
|
14
|
-
class BossError < StandardError; end
|
15
|
-
class InvalidFormat < StandardError; end
|
16
|
-
class InvalidConfig < StandardError; end
|
17
|
-
end
|
data/rboss.gemspec
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
Gem::Specification.new do |s|
|
2
|
-
s.name = %q{rboss}
|
3
|
-
s.version = "0.1.3"
|
4
|
-
|
5
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
|
-
s.authors = ["Joseph Wilk"]
|
7
|
-
s.date = %q{2008-08-22}
|
8
|
-
s.description = %q{Api wrapping Yahoo Boss search}
|
9
|
-
s.email = ["joe@eshopworks.co.uk"]
|
10
|
-
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "TODO.txt"]
|
11
|
-
s.files = ["History.txt", "License.txt", "Manifest.txt", "README.textile", "Rakefile", "TODO.txt", "config/hoe.rb", "config/requirements.rb", "gem_tasks/deployment.rake", "gem_tasks/environment.rake", "gem_tasks/fix_cr_lf.rake", "gem_tasks/gemspec.rake", "gem_tasks/rspec.rake", "gem_tasks/verify_rcov.rake", "gem_tasks/website.rake", "lib/boss.rb", "lib/boss/api.rb", "lib/boss/config.rb", "lib/boss/result.rb", "lib/boss/result/base.rb", "lib/boss/result/image.rb", "lib/boss/result/news.rb", "lib/boss/result/spell.rb", "lib/boss/result/web.rb", "lib/boss/result_collection.rb", "lib/boss/result_factory.rb", "lib/boss/version.rb", "rboss.gemspec", "spec/boss/api_spec.rb", "spec/boss/config_spec.rb", "spec/boss/result_collection_spec.rb", "spec/boss/result_factory_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
|
12
|
-
s.has_rdoc = true
|
13
|
-
s.homepage = %q{http://github.com/eshopworks/rboss-gem}
|
14
|
-
s.rdoc_options = ["--main", "README.txt"]
|
15
|
-
s.require_paths = ["lib"]
|
16
|
-
s.rubyforge_project = %q{rboss}
|
17
|
-
s.rubygems_version = %q{1.2.0}
|
18
|
-
s.summary = %q{Api wrapping Yahoo Boss search}
|
19
|
-
|
20
|
-
if s.respond_to? :specification_version then
|
21
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
22
|
-
s.specification_version = 2
|
23
|
-
|
24
|
-
if current_version >= 3 then
|
25
|
-
s.add_runtime_dependency(%q<json>, [">= 1.1.3"])
|
26
|
-
s.add_runtime_dependency(%q<rspec>, [">= 1.1.4"])
|
27
|
-
s.add_runtime_dependency(%q<diff-lcs>, [">= 1.1.2"])
|
28
|
-
s.add_development_dependency(%q<hoe>, [">= 1.7.0"])
|
29
|
-
else
|
30
|
-
s.add_dependency(%q<json>, [">= 1.1.3"])
|
31
|
-
s.add_dependency(%q<rspec>, [">= 1.1.4"])
|
32
|
-
s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
|
33
|
-
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
34
|
-
end
|
35
|
-
else
|
36
|
-
s.add_dependency(%q<json>, [">= 1.1.3"])
|
37
|
-
s.add_dependency(%q<rspec>, [">= 1.1.4"])
|
38
|
-
s.add_dependency(%q<diff-lcs>, [">= 1.1.2"])
|
39
|
-
s.add_dependency(%q<hoe>, [">= 1.7.0"])
|
40
|
-
end
|
41
|
-
end
|
data/spec/boss/api_spec.rb
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
# require File.dirname(__FILE__) + '/../../boss/api.rb'
|
3
|
-
|
4
|
-
describe Boss::Api do
|
5
|
-
|
6
|
-
def mock_http_response(stubs={})
|
7
|
-
mock('http_response', {:body => '{"ysearchresponse":{}}', :code => "200"}.merge(stubs))
|
8
|
-
end
|
9
|
-
|
10
|
-
before(:each) do
|
11
|
-
@api = Boss::Api.new( appid = 'test' )
|
12
|
-
@api.endpoint = 'http://www.example.com/'
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "responding to spelling search" do
|
16
|
-
|
17
|
-
it "should make a spelling request to yahoo service" do
|
18
|
-
Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
|
19
|
-
|
20
|
-
@api.search_spelling("girafes")
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should build the spelling objects" do
|
24
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
25
|
-
Boss::ResultFactory.should_receive(:build).with(Boss::SearchService::SPELL, '{"ysearchresponse":{}}')
|
26
|
-
|
27
|
-
@api.search_spelling("girafes")
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "responding to news search" do
|
33
|
-
it "should make a news request to yahoo service" do
|
34
|
-
Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
|
35
|
-
|
36
|
-
@api.search_news("monkey")
|
37
|
-
end
|
38
|
-
|
39
|
-
it "should build the news objects" do
|
40
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
41
|
-
Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::NEWS, '{"ysearchresponse":{}}')
|
42
|
-
|
43
|
-
@api.search_news("monkey")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "responding to image search" do
|
48
|
-
it "should make a image request to yahoo service" do
|
49
|
-
Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
|
50
|
-
|
51
|
-
@api.search_images("hippo")
|
52
|
-
end
|
53
|
-
|
54
|
-
it "should build the image objects" do
|
55
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
56
|
-
Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::IMAGES, '{"ysearchresponse":{}}')
|
57
|
-
|
58
|
-
@api.search_images("hippo")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "responding to web search" do
|
63
|
-
|
64
|
-
it "should make a web request to yahoo service" do
|
65
|
-
Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
|
66
|
-
|
67
|
-
@api.search_web("monkey")
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should build the web objects" do
|
71
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
72
|
-
Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::WEB, '{"ysearchresponse":{}}')
|
73
|
-
|
74
|
-
@api.search_web("monkey")
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "failed search" do
|
80
|
-
|
81
|
-
it "should raise error on failed search" do
|
82
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response :code => "404" }
|
83
|
-
|
84
|
-
lambda { @api.search_web("monkey") }.should raise_error(Boss::BossError)
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
describe "configuring search" do
|
90
|
-
|
91
|
-
before(:each) do
|
92
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
93
|
-
|
94
|
-
@config = Boss::Config.new
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should allow configuring through block" do
|
98
|
-
@config.should_receive(:count=).with(1)
|
99
|
-
Boss::Config.should_receive(:new).and_return(@config)
|
100
|
-
|
101
|
-
result = @api.search_web("monkeys") do |setup|
|
102
|
-
setup.count = 1
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
it "should allow configuring through hash" do
|
107
|
-
Boss::Config.should_receive(:new).with({:count => 1}).and_return(@config)
|
108
|
-
|
109
|
-
@api.search_web("monkeys", :count => 1)
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
|
-
describe "formats" do
|
115
|
-
|
116
|
-
before(:each) do
|
117
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should not return any objects when format is 'xml'" do
|
121
|
-
Boss::ResultFactory.should_receive(:build).never
|
122
|
-
@api.search_web("monkeys", :format => 'xml', :count => 1)
|
123
|
-
end
|
124
|
-
|
125
|
-
it "should not return any objects when format is 'json'" do
|
126
|
-
Boss::ResultFactory.should_receive(:build).never
|
127
|
-
@api.search_web("monkeys", :format => 'json', :count => 1)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "should raise an error invalid format" do
|
131
|
-
lambda { @api.search_web("monkeys", :format => 'grilled_cheese', :count => 1) }.should raise_error(Boss::InvalidFormat)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "should raise an error on invalid count" do
|
135
|
-
lambda { @api.search_web("monkeys", :count => 0) }.should raise_error(Boss::InvalidConfig)
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
describe "search should still work when get returns a successful but not code 200" do
|
141
|
-
it "should description" do
|
142
|
-
pending("fix for http://eshopworks.lighthouseapp.com/projects/15732/tickets/1")
|
143
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response :code => "206" }
|
144
|
-
|
145
|
-
lambda { @api.search_web("monkey") }.should_not raise_error(Boss::BossError)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
describe "searching terms" do
|
150
|
-
it "should encode invalid characters" do
|
151
|
-
Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
|
152
|
-
CGI.stub!(:escape)
|
153
|
-
CGI.should_receive(:escape).with('monkey?magic').and_return('monkey%3Fmagic')
|
154
|
-
|
155
|
-
@api.search_web("monkey?magic")
|
156
|
-
end
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
end
|
data/spec/boss/config_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Boss::Config do
|
4
|
-
|
5
|
-
it "should create with defaults" do
|
6
|
-
config = Boss::Config.new
|
7
|
-
|
8
|
-
config.respond_to?(:count).should be_true
|
9
|
-
config.respond_to?(:lang).should be_true
|
10
|
-
config.respond_to?(:format).should be_true
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should create url from defaults" do
|
14
|
-
config = Boss::Config.new :count => 1, :lang => 'en', :format => "object"
|
15
|
-
|
16
|
-
config.to_url.should include("&count=1")
|
17
|
-
config.to_url.should include("&format=object")
|
18
|
-
config.to_url.should include("&lang=en")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should add custom values to url" do
|
22
|
-
config = Boss::Config.new(:mizaru => 'cannot_see')
|
23
|
-
|
24
|
-
config.to_url.should include("&mizaru=cannot_see")
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should encode invalid url characters" do
|
28
|
-
config = Boss::Config.new(:mizaru => 'dancing monkeys?')
|
29
|
-
|
30
|
-
config.to_url.should include("dancing+monkeys%3F")
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Boss::ResultCollection do
|
4
|
-
|
5
|
-
it "should dynamically set instance values given at creation" do
|
6
|
-
collection = Boss::ResultCollection.new
|
7
|
-
collection.set_instance_variable(:totalhits, "344")
|
8
|
-
|
9
|
-
collection.totalhits.should eql("344")
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should allow iterating over result collection" do
|
13
|
-
collection = Boss::ResultCollection.new
|
14
|
-
|
15
|
-
collection << 1
|
16
|
-
collection << 2
|
17
|
-
|
18
|
-
collection.each do |value|
|
19
|
-
[1,2].member?(value).should be_true
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
|
3
|
-
describe Boss::ResultFactory do
|
4
|
-
|
5
|
-
news_json_result = '{"ysearchresponse":{"responsecode":"200","nextpage":"nextpage","totalhits":"344","count":"1","start":"0","resultset_news":[{"abstract":"abstract","clickurl":"clickurl","date":"2008\/08\/18","language":"en english","source":"source","sourceurl":"sourceurl","time":"09:17:29","title":"monkey_title","url":"url"}]}}'
|
6
|
-
|
7
|
-
image_json_result = '{"ysearchresponse":{"responsecode":"200","nextpage":"http:\/\/www.example.com","totalhits":"80","count":"1","start":"0","resultset_images":[{"abstract":"more monkeys","clickurl":"http:\/\/www.example.con\/click","date":"2001\/12\/19","filename":"monkeys.jpg","format":"jpeg","height":"600","mimetype":"image\/jpeg","refererclickurl":"http:\/\/www.example.com\/ref","refererurl":"http:\/\/www.monkeys.com","size":"60900","thumbnail_height":"116","thumbnail_url":"http:\/\/monkey.com\/image\/25\/m7\/3918546506","thumbnail_width":"155","title":"monkeys.jpg","url":"http:\/\/monkey\/monkeys.jpg","width":"800"}]}}'
|
8
|
-
|
9
|
-
web_json_result = '{"ysearchresponse":{"responsecode":"200","nextpage":"nextpage","totalhits":"344","count":"1","start":"0","resultset_web":[{"abstract":"abstract","clickurl":"clickurl","date":"2008\/08\/18","language":"en english","source":"source","sourceurl":"sourceurl","time":"09:17:29","title":"monkey_title","url":"url"}]}}'
|
10
|
-
|
11
|
-
spelling_json_result = '{"ysearchresponse":{"responsecode":"200","totalhits":"1","count":"1","start":"0","resultset_spell":[{"suggestion":"giraffes"}]}}'
|
12
|
-
|
13
|
-
error_json_result = '{"Error":"true"}'
|
14
|
-
|
15
|
-
it "should collect result objects in a result collection" do
|
16
|
-
result_collection = Boss::ResultCollection.new
|
17
|
-
result_collection.should_receive(:<<).once
|
18
|
-
Boss::ResultCollection.should_receive(:new).once.and_return(result_collection)
|
19
|
-
|
20
|
-
Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "should create a new news object from json" do
|
24
|
-
Boss::Result::News.should_receive(:new).once
|
25
|
-
|
26
|
-
Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should correctly map fields with from json to news object" do
|
30
|
-
news_results = Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
|
31
|
-
|
32
|
-
news_results[0].title.should == "monkey_title"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should build image objects from json" do
|
36
|
-
Boss::Result::Image.should_receive(:new).once
|
37
|
-
|
38
|
-
Boss::ResultFactory.build(Boss::SearchType::IMAGES, image_json_result)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should build web object from json" do
|
42
|
-
Boss::Result::Web.should_receive(:new).once
|
43
|
-
|
44
|
-
Boss::ResultFactory.build(Boss::SearchType::WEB, web_json_result)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should build spelling object from json" do
|
48
|
-
Boss::Result::Spell.should_receive(:new).once
|
49
|
-
|
50
|
-
Boss::ResultFactory.build(Boss::SearchType::SPELL, spelling_json_result)
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should raise an error if json result carries an error" do
|
54
|
-
lambda { Boss::ResultFactory.build(Boss::SearchType::WEB, error_json_result) }.should raise_error(Boss::BossError)
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
data/spec/spec.opts
DELETED