jpignata-bossman 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -1,9 +1,14 @@
1
- = BOSSMan -- Class for interaction with the Yahoo BOSS web service
1
+ = BOSSMan -- Gem for interaction with the Yahoo BOSS web service
2
2
 
3
3
  == Description
4
4
 
5
5
  BOSSMan can be used to perform image, web and news searches against Yahoo's index. For more information about BOSS (Build your Own Search Service) please refer to http://developer.yahoo.com/search/boss/.
6
6
 
7
+ == Bugs, Features, Feedback
8
+
9
+ Feedback would be really appreciated. You can send it to me at john.pignata@gmail.com -- tickets can
10
+ be submitted by using Lighthouse: http://pignata.lighthouseapp.com/projects/15761-bossman
11
+
7
12
  == Example Usage
8
13
 
9
14
  === Web
@@ -14,12 +19,12 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
14
19
 
15
20
  BOSSMan.application_id = <Your Application ID>
16
21
 
17
- prospectpark_web = BOSSMan::Search.web("prospect park", 0, 20)
22
+ return = BOSSMan::Search.web("prospect park", { :count => 5, :filter => "-hate" })
18
23
 
19
- puts "Number of results: #{madmen_web.totalhits}"
24
+ puts "Number of results: #{return.totalhits}"
20
25
  puts
21
26
 
22
- prospectpark_web.results.each do |result|
27
+ return.results.each do |result|
23
28
  puts "#{result.title}"
24
29
  puts "-" * 80
25
30
  puts "#{result.abstract}"
@@ -34,9 +39,9 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
34
39
 
35
40
  BOSSMan.application_id = <Your Application ID>
36
41
 
37
- brooklyn_news = BOSSMan::Search.news("brooklyn new york", 0, 20)
42
+ return = BOSSMan::Search.news("brooklyn new york", { :age => "7d" })
38
43
 
39
- brooklyn_news.results.each do |result|
44
+ return.results.each do |result|
40
45
  puts "#{result.title} [from #{result.source}]"
41
46
  puts "-" * 80
42
47
  puts "#{result.abstract}"
@@ -50,69 +55,91 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
50
55
 
51
56
  BOSSMan.application_id = <Your Application ID>
52
57
 
53
- dumbo_images = BOSSMan::Search.images("brooklyn dumbo", 0, 20)
58
+ dumbo = BOSSMan::Search.images("brooklyn dumbo", { :dimensions => "large" })
54
59
 
55
- dumbo_images.results.each do |result|
56
- puts "<img src=\"#{result.url}\" alt=\"#{result.abstract}\" /><br />"
60
+ return.results.each do |result|
61
+ puts "#{result.url}: #{result.abstract}"
57
62
  end
58
63
 
64
+ === Spelling
65
+
66
+ require 'rubygems'
67
+ require 'bossman'
68
+ include BOSSMan
69
+
70
+ BOSSMan.application_id = <Your Application ID>
71
+
72
+ return = BOSSMan::Search.spelling("Diabretes")
73
+
74
+ puts result.suggestion
59
75
 
60
76
  == Output Objects
61
77
 
78
+ Assuming an object returned called search:
79
+
80
+ search = BOSSMan::Search.web("staten island", 0, 20)
81
+
62
82
  === Common
63
83
 
64
- .responsecode : HTTP response code
65
- .nextpage : REST URL to next page of search results
66
- .count : Number of search results contained in response
67
- .start : Search result from which output starts
68
- .totalhits : De-duplicated total number of results search yielded
69
- .deephits : Total number of results search yielded
70
- .results[].clickurl : Tracking URL of result; must be used in user-facing anchor tags by BOSS TOU
71
- .results[].url : URL of result
84
+ search.responsecode : HTTP response code
85
+ search.nextpage : REST URL to next page of search results
86
+ search.count : Number of search results contained in response
87
+ search.start : Search result from which output starts
88
+ search.totalhits : De-duplicated total number of results search yielded
89
+ search.deephits : Total number of results search yielded
90
+ search.results[].clickurl : Tracking URL of result; must be used in user-facing
91
+ anchor tags by BOSS TOU
92
+ search.results[].url : URL of result
72
93
 
73
94
  === Web
74
95
 
75
- .results[].abstract : Description of result with keywords emboldened
76
- .results[].title : Document title with keywords emboldened
77
- .results[].dispurl : Display URL of result
78
- .results[].size : Size of result in bytes
79
- .results[].date : Date result was indexed
96
+ search.results[].abstract : Description of result with keywords emboldened
97
+ search.results[].title : Document title with keywords emboldened
98
+ search.results[].dispurl : Display URL of result
99
+ search.results[].size : Size of result in bytes
100
+ search.results[].date : Date result was indexed
80
101
 
81
102
  === News
82
103
 
83
- .results[].abstract : Description of news story
84
- .results[].title : Title of news story
85
- .results[].language : Language of news story
86
- .results[].date : Last publication date of news story
87
- .results[].time : Last publication time of news story
88
- .results[].source : Source of news story
89
- .results[].sourceurl : URL of source publication
104
+ search.results[].abstract : Description of news story
105
+ search.results[].title : Title of news story
106
+ search.results[].language : Language of news story
107
+ search.results[].date : Last publication date of news story
108
+ search.results[].time : Last publication time of news story
109
+ search.results[].source : Source of news story
110
+ search.results[].sourceurl : URL of source publication
90
111
 
91
112
  === Images
92
113
 
93
- .results[].abstract : Description of image
94
- .results[].filename : Filename of image
95
- .results[].size : Size of image
96
- .results[].format : Format of image
97
- .results[].height : Height of full-size image
98
- .results[].date : Last modification date of image (YYYY/MM/DD)
99
- .results[].mimetype : MIME type of image
100
- .results[].refererclickurl : Link to page where image was found
101
- .results[].refererurl : Link to page where image was found
102
- .results[].title : Title of image (usually the filename)
103
- .results[].width : Width of full-size image
104
- .results[].thumbnailurl : URL of thumbnail image
105
- .results[].thumbnail_height : Height of thumbnail image
106
- .results[].thumbnail_width : Width of thumbnail image
107
-
108
- === Format
109
-
110
- Results are dumpable in JSON, XML and YAML by use of to_json, to_xml (or to_s), to_yaml respectively.
111
-
112
- puts websearch : dumps XML
113
- puts websearch.to_json : dumps JSON
114
- puts websearch.to_yaml : dumps YAML
115
- puts websearch.results[3].to_xml : dumps XML for third search result
114
+ search.results[].abstract : Description of image
115
+ search.results[].filename : Filename of image
116
+ search.results[].size : Size of image
117
+ search.results[].format : Format of image
118
+ search.results[].height : Height of full-size image
119
+ search.results[].date : Last modification date of image (YYYY/MM/DD)
120
+ search.results[].mimetype : MIME type of image
121
+ search.results[].refererclickurl : Link to page where image was found
122
+ search.results[].refererurl : Link to page where image was found
123
+ search.results[].title : Title of image (usually the filename)
124
+ search.results[].width : Width of full-size image
125
+ search.results[].thumbnailurl : URL of thumbnail image
126
+ search.results[].thumbnail_height : Height of thumbnail image
127
+ search.results[].thumbnail_width : Width of thumbnail image
128
+
129
+ === Spelling
130
+
131
+ search.suggestion : Returns spelling suggestion from BOSS
132
+
133
+ === Raw dump formats
134
+
135
+ Resultsets are returnable in JSON, XML and YAML by use of to_json, to_xml (or to_s), to_yaml respectively.
136
+
137
+ search : dumps XML of entire resultset
138
+ search.to_json : dumps JSON of entire resultset
139
+ search.to_yaml : dumps YAML of entire resultset
140
+ search.results[3] : dumps XML of one search result
141
+ search.results[3].to_json : dumps JSON of one search result
142
+ search.results[3].to_yaml : dumps YAML of one search result
116
143
 
117
144
  == Installation
118
145
 
@@ -146,4 +173,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
146
173
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
147
174
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
148
175
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
149
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
176
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bossman.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "bossman"
3
- s.version = "0.0.5"
4
- s.date = "2008-08-17"
3
+ s.version = "0.1.0"
4
+ s.date = "2008-08-27"
5
5
  s.summary = "Class for interaction with the Yahoo BOSS web service."
6
6
  s.email = "jpignata@waterfrontmedia.com"
7
7
  s.homepage = "http://github.com/jpignata/bossman-gem"
data/lib/bossman/rest.rb CHANGED
@@ -29,7 +29,7 @@ module BOSSMan
29
29
  raise MissingConfiguration, "Application ID must be set prior to making a service call."
30
30
  end
31
31
 
32
- unless options[:count] > 0
32
+ unless options[:count] > 0
33
33
  raise InvalidParameter, "Invalid count. Count must be > 0."
34
34
  end
35
35
  end
@@ -11,6 +11,5 @@ module BOSSMan
11
11
  end
12
12
 
13
13
  alias to_s to_xml
14
-
15
14
  end
16
15
  end
@@ -5,7 +5,9 @@ module BOSSMan
5
5
  @response = response
6
6
 
7
7
  @response["ysearchresponse"].each do |key, value|
8
- if key.include? "resultset"
8
+ if key.include? "resultset_spell"
9
+ set_parameter("suggestion", @response["ysearchresponse"]["resultset_spell"][0]["suggestion"])
10
+ elsif key.include? "resultset"
9
11
  results = Array.new
10
12
  response["ysearchresponse"][key].each { |result| results << Result.new(result) }
11
13
  set_parameter("results", results)
@@ -14,12 +16,19 @@ module BOSSMan
14
16
  end
15
17
  end
16
18
  end
17
-
19
+
18
20
  def to_xml
19
21
  @response['ysearchresponse'].to_xml(:root => 'resultset')
20
22
  end
21
-
23
+
24
+ def _dump(level)
25
+ @response.to_json
26
+ end
27
+
28
+ def self._load(string)
29
+ ResultSet.new(ActiveSupport::JSON.decode(string))
30
+ end
31
+
22
32
  alias to_s to_xml
23
-
24
33
  end
25
34
  end
@@ -1,43 +1,38 @@
1
1
  module BOSSMan
2
2
  class Search
3
3
  class << self
4
-
5
- def web(query, start=0, count=10, filter=nil, type=nil, lang=nil, region=nil)
4
+ DEFAULT_COUNT = 10
5
+ DEFAULT_START = 0
6
+
7
+ def web(query, options = {})
6
8
  method = "web"
7
-
8
- options = default_options(BOSSMan.application_id, count, start)
9
- options[:filter] = filter if filter
10
- options[:type] = type if type
11
- options[:lang] = lang if lang
12
- options[:region] = region if region
13
-
9
+ options.merge!(return_options(options))
14
10
  return REST.get(method, query, options)
15
11
  end
16
12
 
17
- def images(query, start=0, count=10, filter=nil, dimensions=nil, refererurl=nil, url=nil)
13
+ def images(query, options = {})
18
14
  method = "images"
19
-
20
- options = default_options(BOSSMan.application_id, count, start)
21
- options[:filter] = filter if filter
22
- options[:dimensions] = dimensions if dimensions
23
- options[:refererurl] = refererurl if refererurl
24
- options[:url] = url if url
25
-
15
+ options.merge!(return_options(options))
26
16
  return REST.get(method, query, options)
27
17
  end
28
18
 
29
- def news(query, start=0, count=10, age=nil)
19
+ def news(query, options = {})
30
20
  method = "news"
31
-
32
- options = default_options(BOSSMan.application_id, count, start)
33
- options[:age] = age if age
34
-
21
+ options.merge!(return_options(options))
35
22
  return REST.get(method, query, options)
36
23
  end
37
24
 
38
- private
39
- def default_options(appid, count, start)
40
- return {:appid => appid, :count => count, :start => start}
25
+ def spelling(query, options = {})
26
+ method = "spelling"
27
+ options.merge!(return_options(options))
28
+ return REST.get(method, query, options)
29
+ end
30
+
31
+ private
32
+ def return_options(options)
33
+ count = options[:count] ? options[:count] : DEFAULT_COUNT
34
+ start = options[:start] ? options[:start] : DEFAULT_START
35
+ return {:appid => BOSSMan.application_id, :count => count, :start => start }
41
36
  end
42
37
 
43
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpignata-bossman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Pignata
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-17 00:00:00 -07:00
12
+ date: 2008-08-27 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency