eshopworks-rboss 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,2 @@
1
+ == 0.1.0
2
+ * Brand spanking new release.
data/License.txt ADDED
@@ -0,0 +1,20 @@
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 ADDED
@@ -0,0 +1,31 @@
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/website.rake
15
+ lib/boss.rb
16
+ lib/boss/api.rb
17
+ lib/boss/config.rb
18
+ lib/boss/result.rb
19
+ lib/boss/result/base.rb
20
+ lib/boss/result/image.rb
21
+ lib/boss/result/news.rb
22
+ lib/boss/result/spell.rb
23
+ lib/boss/result/web.rb
24
+ lib/boss/result_factory.rb
25
+ lib/boss/version.rb
26
+ rboss.gemspec
27
+ spec/boss/api_spec.rb
28
+ spec/boss/config_spec.rb
29
+ spec/boss/result_factory_spec.rb
30
+ spec/spec.opts
31
+ spec/spec_helper.rb
data/README.textile ADDED
@@ -0,0 +1,93 @@
1
+ h1. RBoss-gem Yahoo Boss Search
2
+
3
+ "Yahoo boss search":http://developer.yahoo.com/search/boss/
4
+
5
+ "Yahoo boss API":http://developer.yahoo.com/search/boss/boss_guide/
6
+
7
+ h2. DESCRIPTION:
8
+
9
+ A handy gem to make using the Yahoo Boss API nice and easy in ruby.
10
+
11
+ Bug Tracking: "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
+ #Search images, spelling, news and web
51
+ api.search_images('monkeys')
52
+ api.search_spelling('monkeys')
53
+ api.search_news('monkeys')
54
+ api.search_web('monkeys')
55
+
56
+ #By default returns ruby object results
57
+ results = api.search_web('monkeys')
58
+ results.each { |web| puts web.title }
59
+
60
+ #Configure search with hash
61
+ xml = api.search_spelling('monkeys', :format => 'xml', :count => 5)
62
+
63
+ #Configure search with block
64
+ xml = api.search_spelling('monkeys') do |config|
65
+ config.format = 'xml'
66
+ config.count = 5
67
+ end
68
+ </code></pre>
69
+
70
+ Check "http://developer.yahoo.com/search/boss/boss_guide/":http://developer.yahoo.com/search/boss/boss_guide/ for the different values accessible for news/images/web/spell ruby object results
71
+
72
+ h2. LICENSE:
73
+
74
+ Copyright (c) 2008 eShopworks
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining
77
+ a copy of this software and associated documentation files (the
78
+ "Software"), to deal in the Software without restriction, including
79
+ without limitation the rights to use, copy, modify, merge, publish,
80
+ distribute, sublicense, and/or sell copies of the Software, and to
81
+ permit persons to whom the Software is furnished to do so, subject to
82
+ the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be
85
+ included in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
88
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
91
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
92
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
93
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['gem_tasks/**/*.rake'].each { |rake| load rake }
data/TODO.txt ADDED
@@ -0,0 +1,3 @@
1
+ == FEATURES/PROBLEMS:
2
+
3
+ * Search all
data/config/hoe.rb ADDED
@@ -0,0 +1,69 @@
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'
@@ -0,0 +1,15 @@
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]))
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,10 @@
1
+ desc 'Make all files use UNIX (\n) line endings'
2
+ task :fix_cr_lf do
3
+ files = FileList['**/*']
4
+ files.each do |f|
5
+ next if File.directory?(f)
6
+ s = IO.read(f)
7
+ s.gsub!(/\r?\n/, "\n")
8
+ File.open(f, "w") { |io| io.write(s) }
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ namespace :gemspec do
2
+ desc 'Refresh rboss-gem.gemspec to include ALL files'
3
+ task :refresh => 'manifest:refresh' do
4
+ File.open('rboss.gemspec', 'w') {|io| io.write($hoe.spec.to_ruby)}
5
+ end
6
+ end
@@ -0,0 +1,21 @@
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
+ end
@@ -0,0 +1,17 @@
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 ADDED
@@ -0,0 +1,92 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+ require 'uri'
4
+
5
+ require 'ostruct'
6
+
7
+ module Boss
8
+
9
+ module SearchType
10
+ %w[web images news spell].each { |e| const_set(e.upcase, e) }
11
+ end
12
+
13
+ module SearchService
14
+ #Annoying inconsitency between 'spelling' and 'spell' in api
15
+ SPELL = 'spelling'
16
+ end
17
+
18
+ FORMATS = %w[xml json]
19
+
20
+ class Api
21
+
22
+ def initialize(app_id)
23
+ @app_id = app_id
24
+ @endpoint = 'http://boss.yahooapis.com/ysearch/'
25
+ end
26
+
27
+ def search_images(term, *conditions, &block)
28
+ search term, SearchType::IMAGES, *conditions, &block
29
+ end
30
+
31
+ def search_news(term, *conditions, &block)
32
+ search term, SearchType::NEWS, *conditions, &block
33
+ end
34
+
35
+ def search_web(term, *conditions, &block)
36
+ search term, SearchType::WEB, *conditions, &block
37
+ end
38
+
39
+ def search_spelling(term, *conditions, &block)
40
+ search term, SearchService::SPELL, *conditions, &block
41
+ end
42
+
43
+ def search(terms, search_type=SearchType::WEB, config = {})
44
+ config = config.empty? ? Config.new : Config.new(config)
45
+ search_results = []
46
+
47
+ yield config if block_given?
48
+
49
+ if config.format == 'object'
50
+ format_as_objects=true
51
+ config.format= "json"
52
+ else
53
+ format_as_objects=false
54
+ end
55
+
56
+ raise InvalidFormat unless (FORMATS.include? config.format)
57
+ raise InvalidConfig unless (config.count>0)
58
+
59
+ response = Net::HTTP.get_response(URI.parse(query_url(terms, search_type, config)))
60
+
61
+ case response.code
62
+ when "200"
63
+ data = response.body
64
+
65
+ if format_as_objects
66
+ search_results = ResultFactory.build search_type, data
67
+ else
68
+ search_results = data
69
+ end
70
+ else
71
+ raise BossError, parse_error(data)
72
+ end
73
+
74
+ search_results
75
+ end
76
+
77
+ def parse_error(data)
78
+ end
79
+
80
+ protected
81
+ def query_url(terms, search_type, config)
82
+ #puts "#{@endpoint}#{search_type}/#{boss_version}/#{terms}?appid=#{@app_id}#{config.to_url}"
83
+ "#{@endpoint}#{search_type}/#{boss_version}/#{terms}?appid=#{@app_id}#{config.to_url}"
84
+ end
85
+
86
+ def boss_version
87
+ "v#{Boss::YAHOO_VERSION}"
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,16 @@
1
+ module Boss
2
+
3
+ class Config < OpenStruct
4
+
5
+ def initialize(hash={})
6
+ #Setup defaults
7
+ super({:count => 10, :lang => "en", :format => "object"}.merge(hash))
8
+ end
9
+
10
+ def to_url
11
+ self.marshal_dump.inject("") {|accum, key| accum+="&#{key[0]}=#{key[1]}" }
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,13 @@
1
+ module Boss
2
+ module Result
3
+ class Base < OpenStruct
4
+
5
+ def initialize(data={})
6
+ super
7
+ end
8
+
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,8 @@
1
+ module Boss
2
+ module Result
3
+ class Image < Base
4
+ end
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ module Boss
2
+ module Result
3
+ class News < Base
4
+ end
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ module Boss
2
+ module Result
3
+ class Spell < Base
4
+ end
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ module Boss
2
+ module Result
3
+ class Web < Base
4
+ end
5
+
6
+ end
7
+
8
+ end
@@ -0,0 +1 @@
1
+ %w{base web image news spell}.each{|f| require "boss/result/#{f}"}
@@ -0,0 +1,53 @@
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'
19
+ raise BossError, "Web service error"
20
+ end
21
+
22
+ search_results=[]
23
+
24
+ if has_results json_hash, :for => search_type
25
+
26
+ json_hash[SEARCH_RESPONSE]["#{RESULT_SET}_#{search_type}"].each do |result|
27
+
28
+ case search_type
29
+ when SearchType::WEB
30
+ search_results << Result::Web.new(result)
31
+ when SearchType::IMAGES
32
+ search_results << Result::Image.new(result)
33
+ when SearchType::NEWS
34
+ search_results << Result::News.new(result)
35
+ when SearchType::SPELL
36
+ search_results << Result::Spell.new(result)
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+ search_results
43
+ end
44
+
45
+ def has_results(json_hash, type={})
46
+ !(json_hash[SEARCH_RESPONSE]["#{RESULT_SET}_#{type[:for]}"]).nil?
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+ end
@@ -0,0 +1,9 @@
1
+ module Boss #:nodoc:
2
+ class VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/boss.rb ADDED
@@ -0,0 +1,16 @@
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_factory'
8
+ require 'boss/version'
9
+
10
+ module Boss
11
+ YAHOO_VERSION = 1
12
+
13
+ class BossError < StandardError; end
14
+ class InvalidFormat < StandardError; end
15
+ class InvalidConfig < StandardError; end
16
+ end
data/rboss.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{rboss}
3
+ s.version = "0.1.0"
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-19}
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/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_factory.rb", "lib/boss/version.rb", "rboss.gemspec", "spec/boss/api_spec.rb", "spec/boss/config_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
@@ -0,0 +1,152 @@
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 => 'pretend:"json"', :code => "200"}.merge(stubs))
8
+ end
9
+
10
+ before(:each) do
11
+ @api = Boss::Api.new( appid = 'test' )
12
+ end
13
+
14
+ describe "responding to spelling search" do
15
+
16
+ it "should make a spelling request to yahoo service" do
17
+ Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
18
+ Boss::ResultFactory.stub!(:build)
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, 'pretend:"json"')
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
+ Boss::ResultFactory.stub!(:build)
36
+
37
+ @api.search_news "monkey"
38
+ end
39
+
40
+ it "should build the news objects" do
41
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
42
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::NEWS, 'pretend:"json"')
43
+
44
+ @api.search_news "monkey"
45
+ end
46
+ end
47
+
48
+ describe "responding to image search" do
49
+ it "should make a image request to yahoo service" do
50
+ Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
51
+ Boss::ResultFactory.stub!(:build)
52
+
53
+ @api.search_images "hippo"
54
+ end
55
+
56
+ it "should build the image objects" do
57
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
58
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::IMAGES, 'pretend:"json"')
59
+
60
+ @api.search_images "hippo"
61
+ end
62
+ end
63
+
64
+ describe "responding to web search" do
65
+
66
+ it "should make a web request to yahoo service" do
67
+ Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
68
+ Boss::ResultFactory.stub!(:build)
69
+ @api.search_web "monkey"
70
+ end
71
+
72
+ it "should build the web objects" do
73
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
74
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::WEB, 'pretend:"json"')
75
+
76
+ @api.search_web "monkey"
77
+ end
78
+
79
+ end
80
+
81
+ describe "failed search" do
82
+
83
+ it "should raise error on failed search" do
84
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response :code => "404" }
85
+
86
+ lambda { @api.search_web "monkey" }.should raise_error(Boss::BossError)
87
+ end
88
+
89
+ end
90
+
91
+ describe "search should still work when get returns a successful but not code 200" do
92
+ it "should description" do
93
+ pending("fix for http://rboss.lighthouseapp.com/projects/15732/tickets/1")
94
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response :code => "206" }
95
+
96
+ lambda { @api.search_web "monkey" }.should_not raise_error(Boss::BossError)
97
+ end
98
+ end
99
+
100
+ describe "configuring search" do
101
+
102
+ before(:each) do
103
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
104
+ Boss::ResultFactory.stub!(:build)
105
+
106
+ @config = Boss::Config.new
107
+ end
108
+
109
+ it "should allow configuring through block" do
110
+ @config.should_receive(:count=).with(1)
111
+ Boss::Config.should_receive(:new).and_return(@config)
112
+
113
+ result = @api.search_web "monkeys" do |setup|
114
+ setup.count = 1
115
+ end
116
+ end
117
+
118
+ it "should allow configuring through hash" do
119
+ Boss::Config.should_receive(:new).with({:count => 1}).and_return(@config)
120
+
121
+ @api.search_web "monkeys", :count => 1
122
+ end
123
+
124
+ end
125
+
126
+ describe "formats" do
127
+
128
+ before(:each) do
129
+ Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
130
+ end
131
+
132
+ it "should not return any objects when format is 'xml'" do
133
+ Boss::ResultFactory.should_receive(:build).never
134
+ @api.search_web "monkeys", :format => 'xml', :count => 1
135
+ end
136
+
137
+ it "should not return any objects when format is 'json'" do
138
+ Boss::ResultFactory.should_receive(:build).never
139
+ @api.search_web "monkeys", :format => 'json', :count => 1
140
+ end
141
+
142
+ it "should raise an error invalid format" do
143
+ lambda { @api.search_web "monkeys", :format => 'grilled_cheese', :count => 1 }.should raise_error(Boss::InvalidFormat)
144
+ end
145
+
146
+ it "should raise an error on invalid count" do
147
+ lambda { @api.search_web "monkeys", :count => 0 }.should raise_error(Boss::InvalidConfig)
148
+ end
149
+
150
+ end
151
+
152
+ end
@@ -0,0 +1,27 @@
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
+ end
@@ -0,0 +1,44 @@
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
+
14
+ it "should create a new news object from json" do
15
+ Boss::Result::News.should_receive(:new).once
16
+
17
+ Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
18
+ end
19
+
20
+ it "should correctly map fields with from json to news object" do
21
+ news_results = Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
22
+
23
+ news_results[0].title.should == "monkey_title"
24
+ end
25
+
26
+ it "should build image objects from json" do
27
+ Boss::Result::Image.should_receive(:new).once
28
+
29
+ Boss::ResultFactory.build(Boss::SearchType::IMAGES, image_json_result)
30
+ end
31
+
32
+ it "should build web object from json" do
33
+ Boss::Result::Web.should_receive(:new).once
34
+
35
+ Boss::ResultFactory.build(Boss::SearchType::WEB, web_json_result)
36
+ end
37
+
38
+ it "should build spelling object from json" do
39
+ Boss::Result::Spell.should_receive(:new).once
40
+
41
+ Boss::ResultFactory.build(Boss::SearchType::SPELL, spelling_json_result)
42
+ end
43
+
44
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --diff
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'rspec'
3
+ require 'spec'
4
+
5
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
6
+
7
+ require 'boss'
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eshopworks-rboss
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joseph Wilk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-19 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.3
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rspec
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.1.4
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: diff-lcs
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.2
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: hoe
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.7.0
50
+ version:
51
+ description: Api wrapping Yahoo Boss search
52
+ email:
53
+ - joe@eshopworks.co.uk
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files:
59
+ - History.txt
60
+ - License.txt
61
+ - Manifest.txt
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/website.rake
78
+ - lib/boss.rb
79
+ - lib/boss/api.rb
80
+ - lib/boss/config.rb
81
+ - lib/boss/result.rb
82
+ - lib/boss/result/base.rb
83
+ - lib/boss/result/image.rb
84
+ - lib/boss/result/news.rb
85
+ - lib/boss/result/spell.rb
86
+ - lib/boss/result/web.rb
87
+ - lib/boss/result_factory.rb
88
+ - lib/boss/version.rb
89
+ - rboss.gemspec
90
+ - spec/boss/api_spec.rb
91
+ - spec/boss/config_spec.rb
92
+ - spec/boss/result_factory_spec.rb
93
+ - spec/spec.opts
94
+ - spec/spec_helper.rb
95
+ has_rdoc: true
96
+ homepage: http://github.com/eshopworks/rboss-gem
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --main
100
+ - README.txt
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: "0"
108
+ version:
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: "0"
114
+ version:
115
+ requirements: []
116
+
117
+ rubyforge_project: rboss
118
+ rubygems_version: 1.2.0
119
+ signing_key:
120
+ specification_version: 2
121
+ summary: Api wrapping Yahoo Boss search
122
+ test_files: []
123
+