eshopworks-rboss 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === Version 0.1.3
2
+ * Fix for duplicate information being storied in the ResultCollection
3
+
1
4
  === Version 0.1.2
2
5
  * Maintain search result data in ResultCollection
3
6
 
data/README.textile CHANGED
@@ -71,9 +71,13 @@ h2. USAGE:
71
71
  config.format = 'xml'
72
72
  config.count = 5
73
73
  end
74
+
75
+ #Access general search result information
76
+ results = api.search('monkeys', :count => 5)
77
+ puts results.totalhits
74
78
  </code></pre>
75
79
 
76
- h3. Global Search Options
80
+ h3. Global Search Options (applies to news/images/web search)
77
81
 
78
82
  <pre><code>
79
83
  api.search('monkeys') do |config|
@@ -87,10 +91,23 @@ h3. Global Search Options
87
91
  end
88
92
  </pre></code>
89
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
+
90
106
  h3. Web Search Result
91
107
 
92
108
  <pre><code>
93
- results = api.search_web('monkeys')
109
+ #We filter here to exclude certain types of content
110
+ results = api.search_web('monkeys', :filter => '-porn')
94
111
  results.each do |web|
95
112
  puts web.abstract
96
113
  puts web.date
@@ -105,7 +122,8 @@ h3. Web Search Result
105
122
  h3. News Search Result
106
123
 
107
124
  <pre><code>
108
- results = api.search_news('monkeys')
125
+ #We retrieve documents by age (possible options: [1-30]d )
126
+ results = api.search_news('monkeys', :age => '7d')
109
127
  results.each do |news|
110
128
  puts news.abstract
111
129
  puts news.clickurl
@@ -122,7 +140,9 @@ h3. News Search Result
122
140
  h3. Image Search Result
123
141
 
124
142
  <pre><code>
125
- results = api.search_image('monkeys')
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')
126
146
  results.each do |image|
127
147
  puts image.abstract
128
148
  puts image.clickurl
@@ -152,7 +172,6 @@ h3. Spell Search Result
152
172
  end
153
173
  </code></pre>
154
174
 
155
-
156
175
  h2. LICENSE:
157
176
 
158
177
  Copyright (c) 2008 eShopworks
data/TODO.txt CHANGED
@@ -1,4 +1,3 @@
1
1
  == FEATURES/PROBLEMS:
2
2
 
3
- * Search all
4
- * Clean up ResultCollection, we store hash result in ResultCollection aswell as objects.
3
+ * Search all
data/lib/boss/api.rb CHANGED
@@ -85,7 +85,7 @@ module Boss
85
85
 
86
86
  #TODO: parse error responses
87
87
  def parse_error(data)
88
- "Error contacting yahoo webservice"
88
+ "Error contacting Yahoo Boss web-service"
89
89
  end
90
90
 
91
91
  protected
@@ -2,13 +2,14 @@ module Boss
2
2
  class ResultCollection
3
3
  include Enumerable
4
4
 
5
- def initialize(search_data)
6
- search_data.each do |name, value|
7
- instance_variable_set("@#{name}",value)
8
- instance_eval("def #{name}\n @#{name}\n end")
9
- end
5
+ def initialize
10
6
  @results=[]
11
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
12
13
 
13
14
  def each
14
15
  @results.each { |result| yield result }
@@ -15,39 +15,39 @@ module Boss
15
15
 
16
16
  json_hash = JSON.parse(data)
17
17
 
18
- if json_hash.has_key? 'Error'
19
- raise BossError, "Web service error"
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
20
  end
21
-
22
- result_collection = ResultCollection.new(json_hash[SEARCH_RESPONSE])
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
- result_collection << Result::Web.new(result)
31
- when SearchType::IMAGES
32
- result_collection << Result::Image.new(result)
33
- when SearchType::NEWS
34
- result_collection << Result::News.new(result)
35
- when SearchType::SPELL
36
- result_collection << Result::Spell.new(result)
37
- end
38
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)
39
44
  end
40
- end
41
45
 
46
+ end
42
47
  result_collection
43
48
  end
44
49
 
45
- def has_results?(json_hash, type={})
46
- !(json_hash[SEARCH_RESPONSE]["#{RESULT_SET}_#{type[:for]}"]).nil?
47
- end
48
-
49
50
  end
50
51
 
51
52
  end
52
-
53
- end
53
+ 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 = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/rboss.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{rboss}
3
- s.version = "0.1.2"
3
+ s.version = "0.1.3"
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-21}
7
+ s.date = %q{2008-08-22}
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"]
@@ -3,13 +3,14 @@ require File.dirname(__FILE__) + '/../spec_helper'
3
3
  describe Boss::ResultCollection do
4
4
 
5
5
  it "should dynamically set instance values given at creation" do
6
- collection = Boss::ResultCollection.new({:totalhits => "344"})
6
+ collection = Boss::ResultCollection.new
7
+ collection.set_instance_variable(:totalhits, "344")
7
8
 
8
9
  collection.totalhits.should eql("344")
9
10
  end
10
11
 
11
12
  it "should allow iterating over result collection" do
12
- collection = Boss::ResultCollection.new({})
13
+ collection = Boss::ResultCollection.new
13
14
 
14
15
  collection << 1
15
16
  collection << 2
@@ -12,11 +12,11 @@ describe Boss::ResultFactory do
12
12
 
13
13
  error_json_result = '{"Error":"true"}'
14
14
 
15
- it "should create a result collection" do
16
- news_hash = JSON.parse(news_json_result)
17
- result_collection = Boss::ResultCollection.new(news_hash)
18
- Boss::ResultCollection.should_receive(:new).once.with(news_hash['ysearchresponse']).and_return(result_collection)
19
-
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
20
  Boss::ResultFactory.build(Boss::SearchType::NEWS, news_json_result)
21
21
  end
22
22
 
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.2
4
+ version: 0.1.3
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-21 00:00:00 -07:00
12
+ date: 2008-08-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency