eshopworks-rboss 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,2 +1,7 @@
1
- == 0.1.0
1
+ === Version 0.1.1
2
+ * Fixed exact search error
3
+ * search method takes the same arguments as other search methods
4
+ * Encodes parameters correctly
5
+
6
+ === Version 0.1.0
2
7
  * Brand spanking new release.
data/Manifest.txt CHANGED
@@ -11,6 +11,7 @@ gem_tasks/environment.rake
11
11
  gem_tasks/fix_cr_lf.rake
12
12
  gem_tasks/gemspec.rake
13
13
  gem_tasks/rspec.rake
14
+ gem_tasks/verify_rcov.rake
14
15
  gem_tasks/website.rake
15
16
  lib/boss.rb
16
17
  lib/boss/api.rb
data/README.textile CHANGED
@@ -1,14 +1,14 @@
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/
1
+ h1. RBoss Gem - Yahoo! Boss Search
6
2
 
7
3
  h2. DESCRIPTION:
8
4
 
9
5
  A handy gem to make using the Yahoo Boss API nice and easy in ruby.
10
6
 
11
- Bug Tracking: "http://eshopworks.lighthouseapp.com/projects/15732-rboss/overview":http://eshopworks.lighthouseapp.com/projects/15732-rboss/overview
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
12
 
13
13
  h2. FEATURES:
14
14
 
@@ -47,6 +47,12 @@ h2. USAGE:
47
47
  # lang = eng
48
48
  api.search('monkeys')
49
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
+
50
56
  #Search images, spelling, news and web
51
57
  api.search_images('monkeys')
52
58
  api.search_spelling('monkeys')
@@ -66,8 +72,86 @@ h2. USAGE:
66
72
  config.count = 5
67
73
  end
68
74
  </code></pre>
75
+
76
+ h3. Global Search Options
77
+
78
+ <pre><code>
79
+ api.search('monkeys') do |config|
80
+ config.start = 1
81
+ config.count = 10
82
+ config.lang = 'en'
83
+ config.region = 'us'
84
+ config.format = 'xml'
85
+ config.callback = ''
86
+ config.sites = 'abc.com,cnn.com'
87
+ end
88
+ </pre></code>
89
+
90
+ h3. Web Search Result
91
+
92
+ <pre><code>
93
+ results = api.search_web('monkeys')
94
+ results.each do |web|
95
+ puts web.abstract
96
+ puts web.date
97
+ puts web.dispurl #URL of document matching the query result.
98
+ puts web.clickurl #navigation URL that leads to the target URL
99
+ puts web.size #document’s size in bytes
100
+ puts web.title
101
+ puts web.url
102
+ end
103
+ </code></pre>
104
+
105
+ h3. News Search Result
106
+
107
+ <pre><code>
108
+ results = api.search_news('monkeys')
109
+ results.each do |news|
110
+ puts news.abstract
111
+ puts news.clickurl
112
+ puts news.title
113
+ puts news.language
114
+ puts news.date
115
+ puts news.time
116
+ puts news.source
117
+ puts news.sourceurl
118
+ puts news.url
119
+ end
120
+ </code></pre>
69
121
 
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
122
+ h3. Image Search Result
123
+
124
+ <pre><code>
125
+ results = api.search_image('monkeys')
126
+ results.each do |image|
127
+ puts image.abstract
128
+ puts image.clickurl
129
+ puts image.filename
130
+ puts image.size
131
+ puts image.format
132
+ puts image.height
133
+ puts image.date
134
+ puts image.mimetype
135
+ puts image.refererclickurl
136
+ puts image.refererurl
137
+ puts image.title
138
+ puts image.url
139
+ puts image.width
140
+ puts image.thumbnail_height
141
+ puts image.thumbnail_url
142
+ puts image.thumbnail_width
143
+ end
144
+ </code></pre>
145
+
146
+ h3. Spell Search Result
147
+
148
+ <pre><code>
149
+ results = api.search_spelling('monkeys')
150
+ results.each do |spell|
151
+ puts spell.suggestion
152
+ end
153
+ </code></pre>
154
+
71
155
 
72
156
  h2. LICENSE:
73
157
 
data/TODO.txt CHANGED
@@ -1,3 +1,4 @@
1
1
  == FEATURES/PROBLEMS:
2
2
 
3
- * Search all
3
+ * Search all
4
+ * TODO: cleanup encode_for_url
data/gem_tasks/rspec.rake CHANGED
@@ -18,4 +18,10 @@ desc "Run the specs under spec/models"
18
18
  Spec::Rake::SpecTask.new do |t|
19
19
  t.spec_opts = ['--options', "spec/spec.opts"]
20
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
21
27
  end
@@ -0,0 +1,7 @@
1
+ require 'rake'
2
+ require 'spec/rake/verify_rcov'
3
+
4
+ RCov::VerifyTask.new(:verify_rcov => :spec) do |t|
5
+ t.threshold = 99.6 # Make sure you have rcov 0.9 or higher!
6
+ t.index_html = 'coverage/index.html'
7
+ end
data/lib/boss/api.rb CHANGED
@@ -3,6 +3,8 @@ require 'rexml/document'
3
3
  require 'uri'
4
4
 
5
5
  require 'ostruct'
6
+ require 'cgi'
7
+
6
8
 
7
9
  module Boss
8
10
 
@@ -19,28 +21,35 @@ module Boss
19
21
 
20
22
  class Api
21
23
 
24
+ attr_accessor :endpoint
25
+
22
26
  def initialize(app_id)
23
27
  @app_id = app_id
24
28
  @endpoint = 'http://boss.yahooapis.com/ysearch/'
25
29
  end
26
30
 
31
+ def search(term, *conditions, &block)
32
+ search_boss term, SearchType::WEB, *conditions, &block
33
+ end
34
+
27
35
  def search_images(term, *conditions, &block)
28
- search term, SearchType::IMAGES, *conditions, &block
36
+ search_boss term, SearchType::IMAGES, *conditions, &block
29
37
  end
30
38
 
31
39
  def search_news(term, *conditions, &block)
32
- search term, SearchType::NEWS, *conditions, &block
40
+ search_boss term, SearchType::NEWS, *conditions, &block
33
41
  end
34
42
 
35
43
  def search_web(term, *conditions, &block)
36
- search term, SearchType::WEB, *conditions, &block
44
+ search_boss term, SearchType::WEB, *conditions, &block
37
45
  end
38
46
 
39
47
  def search_spelling(term, *conditions, &block)
40
- search term, SearchService::SPELL, *conditions, &block
48
+ search_boss term, SearchService::SPELL, *conditions, &block
41
49
  end
42
50
 
43
- def search(terms, search_type=SearchType::WEB, config = {})
51
+ private
52
+ def search_boss(terms, search_type=SearchType::WEB, config = {})
44
53
  config = config.empty? ? Config.new : Config.new(config)
45
54
  search_results = []
46
55
 
@@ -55,8 +64,9 @@ module Boss
55
64
 
56
65
  raise InvalidFormat unless (FORMATS.include? config.format)
57
66
  raise InvalidConfig unless (config.count>0)
58
-
59
- response = Net::HTTP.get_response(URI.parse(query_url(terms, search_type, config)))
67
+
68
+ request = query_url terms, search_type, config
69
+ response = Net::HTTP.get_response request
60
70
 
61
71
  case response.code
62
72
  when "200"
@@ -74,19 +84,24 @@ module Boss
74
84
  search_results
75
85
  end
76
86
 
87
+ #TODO: parse error responses
77
88
  def parse_error(data)
89
+ "Error contacting yahoo webservice"
78
90
  end
79
91
 
80
92
  protected
81
93
  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}"
94
+ #We could use URI.encode but it leaves things like ? unencoded which fails search.
95
+ encoded_terms = CGI.escape terms
96
+ # puts "#{@endpoint}#{search_type}/#{boss_version}/#{encoded_terms}?appid=#{@app_id}#{config.to_url}"
97
+ "#{@endpoint}#{search_type}/#{boss_version}/#{encoded_terms}?appid=#{@app_id}#{config.to_url}"
84
98
  end
85
99
 
100
+ protected
86
101
  def boss_version
87
102
  "v#{Boss::YAHOO_VERSION}"
88
103
  end
89
104
 
90
105
  end
91
106
 
92
- end
107
+ end
data/lib/boss/config.rb CHANGED
@@ -8,9 +8,9 @@ module Boss
8
8
  end
9
9
 
10
10
  def to_url
11
- self.marshal_dump.inject("") {|accum, key| accum+="&#{key[0]}=#{key[1]}" }
11
+ self.marshal_dump.inject("") {|accum, key| encoded_value=CGI.escape(key[1].to_s); accum+="&#{key[0]}=#{encoded_value}" }
12
12
  end
13
13
 
14
14
  end
15
15
 
16
- end
16
+ end
data/lib/boss/version.rb CHANGED
@@ -2,7 +2,7 @@ module Boss #:nodoc:
2
2
  class VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/rboss.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{rboss}
3
- s.version = "0.1.0"
3
+ s.version = "0.1.1"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Joseph Wilk"]
7
- s.date = %q{2008-08-19}
7
+ s.date = %q{2008-08-21}
8
8
  s.description = %q{Api wrapping Yahoo Boss search}
9
9
  s.email = ["joe@eshopworks.co.uk"]
10
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"]
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_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
12
  s.has_rdoc = true
13
13
  s.homepage = %q{http://github.com/eshopworks/rboss-gem}
14
14
  s.rdoc_options = ["--main", "README.txt"]
@@ -4,25 +4,25 @@ require File.dirname(__FILE__) + '/../spec_helper'
4
4
  describe Boss::Api do
5
5
 
6
6
  def mock_http_response(stubs={})
7
- mock('http_response', {:body => 'pretend:"json"', :code => "200"}.merge(stubs))
7
+ mock('http_response', {:body => '{"ysearchresponse":{}}', :code => "200"}.merge(stubs))
8
8
  end
9
9
 
10
10
  before(:each) do
11
11
  @api = Boss::Api.new( appid = 'test' )
12
+ @api.endpoint = 'http://www.example.com/'
12
13
  end
13
14
 
14
15
  describe "responding to spelling search" do
15
16
 
16
17
  it "should make a spelling request to yahoo service" do
17
18
  Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
18
- Boss::ResultFactory.stub!(:build)
19
19
 
20
20
  @api.search_spelling "girafes"
21
21
  end
22
22
 
23
23
  it "should build the spelling objects" do
24
24
  Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
25
- Boss::ResultFactory.should_receive(:build).with(Boss::SearchService::SPELL, 'pretend:"json"')
25
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchService::SPELL, '{"ysearchresponse":{}}')
26
26
 
27
27
  @api.search_spelling "girafes"
28
28
  end
@@ -32,14 +32,13 @@ describe Boss::Api do
32
32
  describe "responding to news search" do
33
33
  it "should make a news request to yahoo service" do
34
34
  Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
35
- Boss::ResultFactory.stub!(:build)
36
35
 
37
36
  @api.search_news "monkey"
38
37
  end
39
38
 
40
39
  it "should build the news objects" do
41
40
  Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
42
- Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::NEWS, 'pretend:"json"')
41
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::NEWS, '{"ysearchresponse":{}}')
43
42
 
44
43
  @api.search_news "monkey"
45
44
  end
@@ -48,14 +47,13 @@ describe Boss::Api do
48
47
  describe "responding to image search" do
49
48
  it "should make a image request to yahoo service" do
50
49
  Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
51
- Boss::ResultFactory.stub!(:build)
52
50
 
53
51
  @api.search_images "hippo"
54
52
  end
55
53
 
56
54
  it "should build the image objects" do
57
55
  Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
58
- Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::IMAGES, 'pretend:"json"')
56
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::IMAGES, '{"ysearchresponse":{}}')
59
57
 
60
58
  @api.search_images "hippo"
61
59
  end
@@ -65,13 +63,13 @@ describe Boss::Api do
65
63
 
66
64
  it "should make a web request to yahoo service" do
67
65
  Net::HTTP.should_receive(:get_response).and_return{ mock_http_response }
68
- Boss::ResultFactory.stub!(:build)
66
+
69
67
  @api.search_web "monkey"
70
68
  end
71
69
 
72
70
  it "should build the web objects" do
73
71
  Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
74
- Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::WEB, 'pretend:"json"')
72
+ Boss::ResultFactory.should_receive(:build).with(Boss::SearchType::WEB, '{"ysearchresponse":{}}')
75
73
 
76
74
  @api.search_web "monkey"
77
75
  end
@@ -88,20 +86,10 @@ describe Boss::Api do
88
86
 
89
87
  end
90
88
 
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
89
  describe "configuring search" do
101
90
 
102
91
  before(:each) do
103
92
  Net::HTTP.stub!(:get_response).and_return{ mock_http_response }
104
- Boss::ResultFactory.stub!(:build)
105
93
 
106
94
  @config = Boss::Config.new
107
95
  end
@@ -149,4 +137,24 @@ describe Boss::Api do
149
137
 
150
138
  end
151
139
 
152
- end
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
@@ -24,4 +24,10 @@ describe Boss::Config do
24
24
  config.to_url.should include("&mizaru=cannot_see")
25
25
  end
26
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
+
27
33
  end
@@ -10,6 +10,7 @@ describe Boss::ResultFactory do
10
10
 
11
11
  spelling_json_result = '{"ysearchresponse":{"responsecode":"200","totalhits":"1","count":"1","start":"0","resultset_spell":[{"suggestion":"giraffes"}]}}'
12
12
 
13
+ error_json_result = '{"Error":"true"}'
13
14
 
14
15
  it "should create a new news object from json" do
15
16
  Boss::Result::News.should_receive(:new).once
@@ -41,4 +42,8 @@ describe Boss::ResultFactory do
41
42
  Boss::ResultFactory.build(Boss::SearchType::SPELL, spelling_json_result)
42
43
  end
43
44
 
45
+ it "should raise an error if json result carries an error" do
46
+ lambda { Boss::ResultFactory.build(Boss::SearchType::WEB, error_json_result) }.should raise_error(Boss::BossError)
47
+ end
48
+
44
49
  end
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Wilk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-19 00:00:00 -07:00
12
+ date: 2008-08-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -74,6 +74,7 @@ files:
74
74
  - gem_tasks/fix_cr_lf.rake
75
75
  - gem_tasks/gemspec.rake
76
76
  - gem_tasks/rspec.rake
77
+ - gem_tasks/verify_rcov.rake
77
78
  - gem_tasks/website.rake
78
79
  - lib/boss.rb
79
80
  - lib/boss/api.rb