boss 0.1

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.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README +131 -0
  3. data/Rakefile +38 -0
  4. data/lib/boss.rb +295 -0
  5. metadata +65 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Jamie Hoover
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/README ADDED
@@ -0,0 +1,131 @@
1
+ BOSS (Build your Own Search Service)
2
+
3
+ Install
4
+ -------
5
+
6
+ sudo gem install boss
7
+
8
+
9
+ Examples
10
+ --------
11
+
12
+ require 'boss'
13
+
14
+ boss.appid = 'Bossdemo' # Set the BOSS appid to what Yahoo assigned you.
15
+
16
+ image_example = boss.images.new('soccer', :count => 30) # Sets a new images resultset of 30 matching 'soccer'.
17
+ image_example.resultset.each do |r| # Gets current images resultset.
18
+ r.abstract # Now we don't know Crawford from Adam but he's a good friend of WCP-occasional-contributor Beans and he somewhat has a point, or at least made us laugh while making it.
19
+ r.clickurl # http://us.lrd.yahoo.com/_ylc=X3oDMTFkNXVldGJyBGFwcGlkA2Jvc3NkZW1vBHBvcwMwBHNlcnZpY2UDWVNlYXJjaARzcmNwdmlkAw --/SIG=12f47a1hh/**http%3A//wickedchopspoker.blogs.com/my_weblog/images/why_men_love_soccer.jpg
20
+ r.date # 2006/06/09
21
+ r.filename # why_men_love_soccer.jpg
22
+ r.format # jpeg
23
+ r.height # 213
24
+ r.mimetype # image/jpeg
25
+ r.refererclickur # http://wickedchopspoker.blogs.com/my_weblog/2006/06/world_cup_musin.html
26
+ r.refererurl # http://wickedchopspoker.blogs.com/my_weblog/2006/06/world_cup_musin.html
27
+ r.size # 31500
28
+ r.thumbnail_height # 120
29
+ r.thumbnail_url # http://re3.yt-thm-a01.yimg.com/image/25/m7/3979077535
30
+ r.thumbnail_width # 130
31
+ r.title # why_men_love_soccer.jpg
32
+ r.url # http://wickedchopspoker.blogs.com/my_weblog/images/why_men_love_soccer.jpg
33
+ r.width # 230
34
+ end
35
+ image_example.nextpage # Returns string for next images resultset.
36
+
37
+ news_example = boss.news.new('soccer') # Sets a new news resultset matching 'soccer'.
38
+ news_example.resultset.each do |r| # Gets current news resultset.
39
+ r.abstract # June 16 (Bloomberg) -- Adidas AG , the world's second - largest sporting-goods maker, will ``clearly exceed'' its full-year sales target for soccer-related goods and gain share in all major markets, Chief Executive Officer Herbert Hainer said.
40
+ r.clickurl # http://www.bloomberg.com/apps/news?pid=20601100&sid=aSSf0jMZtvBU
41
+ r.date # 2008/06/16
42
+ r.language # en english
43
+ r.source # Bloomberg.com
44
+ r.sourceurl # http://www.bloomberg.com/
45
+ r.time # 14:21:15
46
+ r.title # Adidas Will `Clearly Exceed' Soccer Sales Target, Hainer Says
47
+ r.url # http://www.bloomberg.com/apps/news?pid=20601100&sid=aSSf0jMZtvBU
48
+ end
49
+ news_example.nextpage # Returns string for next news resultset.
50
+
51
+ spelling_example = boss.spelling.new # Sets a new spelling resultset.
52
+ spelling_example.resultset.each do |r| # Gets current spelling resultset.
53
+ r.suggestion # monkeys giraffes
54
+ spelling_example.nextpage # Returns string for next spelling resultset.
55
+
56
+ web_example = boss.web.new # Sets a new web resultset.
57
+ web_example.resultset.each do |r| # Gets current web resultset.
58
+ r.abstract # <![CDATA[World <b>soccer</b> coverage from ESPN, including Premiership, Serie A, La Liga, and Major League <b>Soccer</b>. Get news headlines, live scores, stats, and tournament information.]]>
59
+ r.clickurl # http://us.lrd.yahoo.com/_ylc=X3oDMTFkNXVldGJyBGFwcGlkA2Jvc3NkZW1vBHBvcwMwBHNlcnZpY2UDWVNlYXJjaARzcmNwdmlkAw--/SIG=10u3e8260/**http%3A//www.soccernet.com/
60
+ r.date # 2008/06/08
61
+ r.dispurl # <![CDATA[www.<b>soccernet.com</b>]]>
62
+ r.size # 94650
63
+ r.title # ESPN Soccernet
64
+ r.url # http://www.soccernet.com/
65
+ end
66
+ web_example.nextpage # Returns string for next web resultset.
67
+
68
+
69
+ Universal Arguments (Image, News, Spelling, and Web)
70
+ ----------------------------------------------------
71
+
72
+ :callback => 'foobar()' # Name of callback function to wrap result.
73
+
74
+ :count => 10 # Total results to return. Maximum: 50.
75
+
76
+ :lang => 'en', :region => 'us' # Specifies the language and region (country) search product to query.
77
+ http://developer.yahoo.com/search/boss/boss_guide/supp_regions_lang.html
78
+
79
+ :sites => 'abc.com, cnn.com' # Restrict to certain site(s). Note: Images do not yet support multiple sites.
80
+
81
+ :start => 0 # Ordinal position of first result.
82
+
83
+
84
+ Image Arguments
85
+ ---------------
86
+
87
+ :dimensions => # Only images of certain size.
88
+ 'all' # Default
89
+ 'small' # Small images are generally thumbnail or icon sized.
90
+ 'medium' # Medium sized images are average sized; usually not exceeding an average screen size.
91
+ 'large' # Large images are screen size or larger.
92
+ 'wallpaper'
93
+ 'widewallpaper'
94
+
95
+ :filter => # Offensive Content Reduction filter.
96
+ 'no' #
97
+ 'yes' # Default, content marked as offensive is omitted.
98
+
99
+
100
+ :refererurl => 'http://foo.com' # Only image objects with this referring URL.
101
+
102
+ :url => 'http://foo.com/images/bar.gif' # Exact image result.
103
+
104
+
105
+ News Argument
106
+ -------------
107
+
108
+ :age => '7d' # String of integer and one of letters "s", "m", "h", "d" and "w" (seconds, minutes, hours, days and weeks)
109
+
110
+
111
+ Web Arguments
112
+ -------------
113
+
114
+ :filter => # Filter out adult or hate content.
115
+ '-hate' # U.S. only.
116
+ '-porn'
117
+ '-hate, -porn' # U.S. only.
118
+
119
+ :type => # Specifies document formats (pdf, msoffice,etc).
120
+ 'html'
121
+ 'pdf' # Adobe Portable Document Format
122
+ 'msoffice' # xl, msword, ppt
123
+ 'msword' # Microsoft Word
124
+ 'nonhtml' # text, pdf, xl, msword, ppt
125
+ 'ppt' # Microsoft Power Point
126
+ 'text'
127
+ 'xl' # Microsoft Excel: xls, xla, xl
128
+ 'msoffice, -ppt' # Specify a format group then exclude an item.
129
+ 'html, msoffice, -pdf' # Combine inclusion, exclusion, document types, and type groups.
130
+
131
+ :view => 'keyterms' # Retrieve related words and phrases for each search result.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ spec = Gem::Specification.new do |s|
5
+ s.add_dependency 'json'
6
+ s.author = 'UiPoet'
7
+ s.email = 'dont.tase@me.com'
8
+ s.files = FileList['lib/boss.rb', '[A-Z]*'].to_a
9
+ s.has_rdoc = true
10
+ s.homepage = 'http://uipoet.com'
11
+ s.name = 'boss'
12
+ s.rubyforge_project = 'uipoet'
13
+ s.summary = 'Yahoo BOSS for Ruby'
14
+ s.version = '0.1'
15
+ end
16
+
17
+ Rake::GemPackageTask.new(spec) do |pkg|
18
+ pkg.gem_spec = spec
19
+ end
20
+
21
+ desc 'Create gemspec'
22
+ task :gemspec do
23
+ File.open("#{spec.name}.gemspec", 'w') do |file|
24
+ file.puts spec.to_ruby
25
+ end
26
+ end
27
+
28
+ desc 'Release gem to rubyforge.org'
29
+ task :release do
30
+ require 'rubyforge'
31
+ sh 'sudo rake package'
32
+ begin
33
+ sh 'rubyforge login'
34
+ sh "rubyforge add_release #{spec.rubyforge_project} #{spec.name} #{spec.version} pkg/#{spec.name}-#{spec.version}.gem"
35
+ rescue Exception => e
36
+ puts "Release failed: #{e.message}"
37
+ end
38
+ end
data/lib/boss.rb ADDED
@@ -0,0 +1,295 @@
1
+ require 'rubygems'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module Boss
7
+
8
+ def self.appid=(a)
9
+ @@appid = a
10
+ end
11
+
12
+ def self.appid
13
+ @@appid || 'Bossdemo'
14
+ end
15
+
16
+ module Resultset
17
+
18
+ def initialize(q, a = {})
19
+ @query = URI.encode(q)
20
+ @arguments = arguments(a)
21
+ end
22
+
23
+ def nextpage
24
+ ysearchresponse['nextpage']
25
+ end
26
+
27
+ def response
28
+ ysearchresponse["resultset_#{service}"]
29
+ end
30
+
31
+ private
32
+
33
+ def arguments(a = {})
34
+ "appid=#{Boss.appid}&format=json" + a.collect{|n, v| "&#{n}=#{v}"}.to_s
35
+ end
36
+
37
+ def hostname
38
+ 'boss.yahooapis.com'
39
+ end
40
+
41
+ def page
42
+ "/ysearch/#{service}/v#{version}/#{@query}?#{@arguments}"
43
+ end
44
+
45
+ def service
46
+ self.class.to_s.split('::').last.downcase
47
+ end
48
+
49
+ def uri
50
+ URI.parse("http://#{hostname}#{page}")
51
+ end
52
+
53
+ def version
54
+ 1
55
+ end
56
+
57
+ def ysearchresponse
58
+ JSON.parse(Net::HTTP.get_response(uri).body)['ysearchresponse']
59
+ end
60
+
61
+ end
62
+
63
+ class Images
64
+
65
+ include Resultset
66
+
67
+ def resultset
68
+ response.collect{|r| Result.new(r)}
69
+ end
70
+
71
+ class Result
72
+
73
+ attr_accessor :result
74
+
75
+ def initialize(r)
76
+ @result = r
77
+ end
78
+
79
+ def abstract
80
+ @result['abstract']
81
+ end
82
+
83
+ def clickurl
84
+ @result['clickurl']
85
+ end
86
+
87
+ def date
88
+ @result['date']
89
+ end
90
+
91
+ def filename
92
+ @result['filename']
93
+ end
94
+
95
+ def format
96
+ @result['format']
97
+ end
98
+
99
+ def height
100
+ @result['height'].to_i
101
+ end
102
+
103
+ def mimetype
104
+ @result['mimetype']
105
+ end
106
+
107
+ def refererclickurl
108
+ @result['refererclickurl']
109
+ end
110
+
111
+ def refererurl
112
+ @result['refererurl']
113
+ end
114
+
115
+ def size
116
+ @result['size'].to_i
117
+ end
118
+
119
+ def thumbnail_height
120
+ @result['thumbnail_height'].to_i
121
+ end
122
+
123
+ def thumbnail_url
124
+ @result['thumbnail_url']
125
+ end
126
+
127
+ def thumbnail_width
128
+ @result['thumbnail_width'].to_i
129
+ end
130
+
131
+ def title
132
+ @result['title']
133
+ end
134
+
135
+ def url
136
+ @result['url']
137
+ end
138
+
139
+ def width
140
+ @result['width'].to_i
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+
147
+ class News
148
+
149
+ include Resultset
150
+
151
+ def resultset
152
+ response.collect{|r| Result.new(r)}
153
+ end
154
+
155
+ class Result
156
+
157
+ attr_accessor :result
158
+
159
+ def initialize(r)
160
+ @result = r
161
+ end
162
+
163
+ def abstract
164
+ @result['abstract']
165
+ end
166
+
167
+ def clickurl
168
+ @result['clickurl']
169
+ end
170
+
171
+ def date
172
+ @result['date']
173
+ end
174
+
175
+ def language
176
+ @result['language']
177
+ end
178
+
179
+ def source
180
+ @result['source']
181
+ end
182
+
183
+ def sourceurl
184
+ @result['sourceurl']
185
+ end
186
+
187
+ def time
188
+ @result['time']
189
+ end
190
+
191
+ def title
192
+ @result['title']
193
+ end
194
+
195
+ def url
196
+ @result['url']
197
+ end
198
+
199
+ end
200
+
201
+ end
202
+
203
+ class Spelling
204
+
205
+ include Resultset
206
+
207
+ def resultset
208
+ response.collect{|r| Result.new(r)}
209
+ end
210
+
211
+ class Result
212
+
213
+ attr_accessor :result
214
+
215
+ def initialize(r)
216
+ @result = r
217
+ end
218
+
219
+ def suggestion
220
+ @result['suggestion']
221
+ end
222
+
223
+ end
224
+
225
+ end
226
+
227
+ class Web
228
+
229
+ include Resultset
230
+
231
+ def resultset
232
+ response.collect{|r| Result.new(r)}
233
+ end
234
+
235
+ class Result
236
+
237
+ attr_accessor :result
238
+
239
+ def initialize(r)
240
+ @result = r
241
+ end
242
+
243
+ def abstract
244
+ @result['abstract']
245
+ end
246
+
247
+ def clickurl
248
+ @result['clickurl']
249
+ end
250
+
251
+ def date
252
+ @result['date']
253
+ end
254
+
255
+ def dispurl
256
+ @result['dispurl']
257
+ end
258
+
259
+ def size
260
+ @result['size'].to_i
261
+ end
262
+
263
+ def title
264
+ @result['title']
265
+ end
266
+
267
+ def url
268
+ @result['url']
269
+ end
270
+
271
+ end
272
+
273
+ end
274
+
275
+ def self.images
276
+ Images
277
+ end
278
+
279
+ def self.news
280
+ News
281
+ end
282
+
283
+ def self.spelling
284
+ Spelling
285
+ end
286
+
287
+ def self.web
288
+ Web
289
+ end
290
+
291
+ end
292
+
293
+ def boss
294
+ Boss
295
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boss
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - UiPoet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: dont.tase@me.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/boss.rb
35
+ - LICENSE
36
+ - Rakefile
37
+ - README
38
+ has_rdoc: true
39
+ homepage: http://uipoet.com
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project: uipoet
60
+ rubygems_version: 1.3.1
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Yahoo BOSS for Ruby
64
+ test_files: []
65
+