jpignata-bossman 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +125 -1
- data/bossman.gemspec +8 -6
- data/lib/bossman/basevalueobject.rb +10 -0
- data/lib/bossman/rest.rb +36 -0
- data/lib/bossman/result.rb +9 -0
- data/lib/bossman/resultset.rb +17 -0
- data/lib/bossman/search.rb +45 -0
- data/lib/bossman.rb +12 -83
- metadata +12 -6
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Jay Pignata
|
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 NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
CHANGED
@@ -2,10 +2,134 @@
|
|
2
2
|
|
3
3
|
== Description
|
4
4
|
|
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
|
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
|
+
|
7
|
+
== Example Usage
|
8
|
+
|
9
|
+
=== Web
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'bossman'
|
13
|
+
include BOSSMan
|
14
|
+
|
15
|
+
BOSSMan.application_id = <Your Application ID>
|
16
|
+
|
17
|
+
prospectpark_web = BOSSMan::Search.web("prospect park", 0, 20)
|
18
|
+
|
19
|
+
puts "Number of results: #{madmen_web.totalhits}"
|
20
|
+
puts
|
21
|
+
|
22
|
+
prospectpark_web.results.each do |result|
|
23
|
+
puts "#{result.title}"
|
24
|
+
puts "-" * 80
|
25
|
+
puts "#{result.abstract}"
|
26
|
+
puts
|
27
|
+
end
|
28
|
+
|
29
|
+
=== News
|
30
|
+
|
31
|
+
require 'rubygems'
|
32
|
+
require 'bossman'
|
33
|
+
include BOSSMan
|
34
|
+
|
35
|
+
BOSSMan.application_id = <Your Application ID>
|
36
|
+
|
37
|
+
brooklyn_news = BOSSMan::Search.news("brooklyn new york", 0, 20)
|
38
|
+
|
39
|
+
brooklyn_news.results.each do |result|
|
40
|
+
puts "#{result.title} [from #{result.source}]"
|
41
|
+
puts "-" * 80
|
42
|
+
puts "#{result.abstract}"
|
43
|
+
puts
|
44
|
+
|
45
|
+
=== Images
|
46
|
+
|
47
|
+
require 'rubygems'
|
48
|
+
require 'bossman'
|
49
|
+
include BOSSMan
|
50
|
+
|
51
|
+
BOSSMan.application_id = <Your Application ID>
|
52
|
+
|
53
|
+
dumbo_images = BOSSMan::Search.images("brooklyn dumbo", 0, 20)
|
54
|
+
|
55
|
+
dumbo_images.results.each do |result|
|
56
|
+
puts "<img src=\"#{result.url}\" alt=\"#{result.abstract}\" /><br />"
|
57
|
+
end
|
58
|
+
|
59
|
+
== Output Objects
|
60
|
+
|
61
|
+
=== Common
|
62
|
+
|
63
|
+
.responsecode : HTTP response code
|
64
|
+
.nextpage : REST URL to next page of search results
|
65
|
+
.count : Number of search results contained in response
|
66
|
+
.start : Search result from which output starts
|
67
|
+
.totalhits : De-duplicated total number of results search yielded
|
68
|
+
.deephits : Total number of results search yielded
|
69
|
+
.results[].clickurl : Tracking URL of result; must be used in user-facing anchor tags by BOSS TOU
|
70
|
+
.results[].url : URL of result
|
71
|
+
|
72
|
+
=== Web
|
73
|
+
|
74
|
+
.results[].abstract : Description of result with keywords emboldened
|
75
|
+
.results[].title : Document title with keywords emboldened
|
76
|
+
.results[].dispurl : Display URL of result
|
77
|
+
.results[].size : Size of result in bytes
|
78
|
+
.results[].date : Date result was indexed
|
79
|
+
|
80
|
+
=== News
|
81
|
+
|
82
|
+
.results[].abstract : Description of news story
|
83
|
+
.results[].title : Title of news story
|
84
|
+
.results[].language : Language of news story
|
85
|
+
.results[].date : Last publication date of news story
|
86
|
+
.results[].time : Last publication time of news story
|
87
|
+
.results[].source : Source of news story
|
88
|
+
.results[].sourceurl : URL of source publication
|
89
|
+
|
90
|
+
=== Images
|
91
|
+
|
92
|
+
.results[].abstract : Description of image
|
93
|
+
.results[].filename : Filename of image
|
94
|
+
.results[].size : Size of image
|
95
|
+
.results[].format : Format of image
|
96
|
+
.results[].height : Height of full-size image
|
97
|
+
.results[].date : Last modification date of image (YYYY/MM/DD)
|
98
|
+
.results[].mimetype : MIME type of image
|
99
|
+
.results[].refererclickurl : Link to page where image was found
|
100
|
+
.results[].refererurl : Link to page where image was found
|
101
|
+
.results[].title : Title of image (usually the filename)
|
102
|
+
.results[].width : Width of full-size image
|
103
|
+
.results[].thumbnailurl : URL of thumbnail image
|
104
|
+
.results[].thumbnail_height : Height of thumbnail image
|
105
|
+
.results[].thumbnail_width : Width of thumbnail image
|
6
106
|
|
7
107
|
== Installation
|
8
108
|
|
9
109
|
jp@populuxe:~/code/ruby$ gem sources -a http://gems.github.com
|
10
110
|
jp@populuxe:~/code/ruby$ gem install jpignata-bossman
|
11
111
|
|
112
|
+
== LICENSE:
|
113
|
+
|
114
|
+
(The MIT License)
|
115
|
+
|
116
|
+
Copyright (c) 2008 Jay Pignata
|
117
|
+
|
118
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
119
|
+
a copy of this software and associated documentation files (the
|
120
|
+
'Software'), to deal in the Software without restriction, including
|
121
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
122
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
123
|
+
permit persons to whom the Software is furnished to do so, subject to
|
124
|
+
the following conditions:
|
125
|
+
|
126
|
+
The above copyright notice and this permission notice shall be
|
127
|
+
included in all copies or substantial portions of the Software.
|
128
|
+
|
129
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
130
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
131
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
132
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
133
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
134
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
135
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bossman.gemspec
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "bossman"
|
3
|
-
s.version = "0.0.
|
4
|
-
s.date = "2008-08-
|
3
|
+
s.version = "0.0.4"
|
4
|
+
s.date = "2008-08-17"
|
5
5
|
s.summary = "Class for interaction with the Yahoo BOSS web service."
|
6
6
|
s.email = "jpignata@waterfrontmedia.com"
|
7
|
-
s.homepage = "http://github.com/jpignata/bossman"
|
8
|
-
s.authors = ["
|
9
|
-
s.files = [
|
10
|
-
|
7
|
+
s.homepage = "http://github.com/jpignata/bossman-gem"
|
8
|
+
s.authors = ["Jay Pignata"]
|
9
|
+
s.files = ['bossman.gemspec', 'lib/bossman.rb', 'lib/bossman/basevalueobject.rb',
|
10
|
+
'lib/bossman/rest.rb', 'lib/bossman/result.rb', 'lib/bossman/resultset.rb',
|
11
|
+
'lib/bossman/search.rb', 'README', 'LICENSE']
|
12
|
+
s.add_dependency("activesupport", [">= 2.1.0"])
|
11
13
|
s.has_rdoc = false
|
12
14
|
end
|
data/lib/bossman/rest.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class REST
|
3
|
+
|
4
|
+
def self.get(method, query, options)
|
5
|
+
validate_parameters(options)
|
6
|
+
uri = URI.parse(URI.encode("#{API_BASEURI}/#{method}/#{API_VERSION}/#{query}"))
|
7
|
+
uri.query = options.to_query
|
8
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
9
|
+
response = Net::HTTP.new(uri.host).request(request)
|
10
|
+
case response
|
11
|
+
when Net::HTTPSuccess
|
12
|
+
return ResultSet.new(ActiveSupport::JSON.decode(response.body))
|
13
|
+
else
|
14
|
+
raise BOSSError, parse_error(response.body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.parse_error(response_string)
|
19
|
+
response_document = REXML::Document.new(response_string)
|
20
|
+
error_code = REXML::XPath.first(response_document, '//yahoo:code').text
|
21
|
+
error_description = REXML::XPath.first(response_document, '//yahoo:description').text
|
22
|
+
error_detail = REXML::XPath.first(response_document, '//yahoo:detail').text
|
23
|
+
return "#{error_code} #{error_description}: #{error_detail}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.validate_parameters(options)
|
27
|
+
unless BOSSMan.application_id
|
28
|
+
raise MissingConfiguration, "Application ID must be set prior to making a service call."
|
29
|
+
end
|
30
|
+
unless options[:count] > 0
|
31
|
+
raise InvalidParameter, "Invalid count. Count must be > 0."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class ResultSet < BaseValueObject
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
response["ysearchresponse"].each do |key, value|
|
6
|
+
if key.include? "resultset"
|
7
|
+
results = Array.new
|
8
|
+
response["ysearchresponse"][key].each { |result| results << Result.new(result) }
|
9
|
+
set_parameter("results", results)
|
10
|
+
else
|
11
|
+
set_parameter(key, value)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class Search
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def web(query, start=0, count=10, filter=nil, type=nil, lang=nil, region=nil)
|
6
|
+
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
|
+
|
14
|
+
return REST.get(method, query, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def images(query, start=0, count=10, filter=nil, dimensions=nil, refererurl=nil, url=nil)
|
18
|
+
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
|
+
|
26
|
+
return REST.get(method, query, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def news(query, start=0, count=10, age=nil)
|
30
|
+
method = "news"
|
31
|
+
|
32
|
+
options = default_options(BOSSMan.application_id, count, start)
|
33
|
+
options[:age] = age if age
|
34
|
+
|
35
|
+
return REST.get(method, query, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def default_options(appid, count, start)
|
40
|
+
return {:appid => appid, :count => count, :start => start}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/bossman.rb
CHANGED
@@ -1,93 +1,22 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
1
|
require 'rubygems'
|
4
2
|
require 'active_support'
|
5
|
-
require 'rexml/xpath'
|
6
|
-
require 'rexml/document'
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
BASE_URI = "http://boss.yahooapis.com/ysearch"
|
11
|
-
|
12
|
-
def application_id(application_id=nil)
|
13
|
-
raise MissingConfiguration, "Application ID must be set prior to making a service call" unless @application_id || application_id
|
14
|
-
return @application_id unless application_id #get
|
15
|
-
@application_id = application_id #set
|
16
|
-
end
|
17
|
-
|
18
|
-
def web_search(query, start=0, count=10, filter=nil, type=nil, lang=nil, region=nil)
|
19
|
-
method = "web"
|
20
|
-
|
21
|
-
options = {
|
22
|
-
:appid => application_id,
|
23
|
-
:count => count,
|
24
|
-
:start => start
|
25
|
-
}
|
26
|
-
|
27
|
-
options[:filter] = filter if filter
|
28
|
-
options[:type] = type if type
|
29
|
-
options[:lang] = lang if lang
|
30
|
-
options[:region] = region if region
|
31
|
-
|
32
|
-
get_from_boss(method, query, options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def images_search(query, start=0, count=10, filter=nil, dimensions=nil, refererurl=nil, url=nil)
|
36
|
-
method = "images"
|
37
|
-
|
38
|
-
options = {
|
39
|
-
:appid => application_id,
|
40
|
-
:count => count,
|
41
|
-
:start => start
|
42
|
-
}
|
4
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
5
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
43
6
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
7
|
+
require 'bossman/search'
|
8
|
+
require 'bossman/rest'
|
9
|
+
require 'bossman/basevalueobject'
|
10
|
+
require 'bossman/resultset'
|
11
|
+
require 'bossman/result'
|
48
12
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def news_search(query, start=0, count=10, age=nil)
|
53
|
-
method = "news"
|
54
|
-
|
55
|
-
options = {
|
56
|
-
:appid => application_id,
|
57
|
-
:count => count,
|
58
|
-
:start => start
|
59
|
-
}
|
13
|
+
module BOSSMan
|
14
|
+
API_VERSION = :v1
|
15
|
+
API_BASEURI = "http://boss.yahooapis.com/ysearch"
|
60
16
|
|
61
|
-
|
62
|
-
|
63
|
-
get_from_boss(method, query, options)
|
64
|
-
end
|
65
|
-
|
66
|
-
private
|
67
|
-
def get_from_boss(method, query, options)
|
68
|
-
uri = URI.parse("#{BASE_URI}/#{method}/#{VERSION}/#{query}")
|
69
|
-
uri.query = options.to_query
|
17
|
+
attr_accessor :application_id
|
70
18
|
|
71
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
72
|
-
response = Net::HTTP.new(uri.host).request(request)
|
73
|
-
|
74
|
-
case response
|
75
|
-
when Net::HTTPSuccess
|
76
|
-
return ActiveSupport::JSON.decode(response.body)["ysearchresponse"]
|
77
|
-
else
|
78
|
-
raise BOSSError, parse_error(response.body)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def parse_error(response_string)
|
83
|
-
response_document = REXML::Document.new(response_string)
|
84
|
-
code = REXML::XPath.first(response_document, '//yahoo:code').text
|
85
|
-
description = REXML::XPath.first(response_document, '//yahoo:description').text
|
86
|
-
detail = REXML::XPath.first(response_document, '//yahoo:detail').text
|
87
|
-
return "#{code} #{description}: #{detail}"
|
88
|
-
end
|
89
|
-
|
90
19
|
class MissingConfiguration < StandardError; end
|
20
|
+
class InvalidParameter < StandardError; end
|
91
21
|
class BOSSError < StandardError; end
|
92
|
-
|
93
22
|
end
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jpignata-bossman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Jay Pignata
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-08-
|
12
|
+
date: 2008-08-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: activesupport
|
17
17
|
version_requirement:
|
18
18
|
version_requirements: !ruby/object:Gem::Requirement
|
19
19
|
requirements:
|
@@ -30,11 +30,17 @@ extensions: []
|
|
30
30
|
extra_rdoc_files: []
|
31
31
|
|
32
32
|
files:
|
33
|
-
- README
|
34
33
|
- bossman.gemspec
|
35
34
|
- lib/bossman.rb
|
35
|
+
- lib/bossman/basevalueobject.rb
|
36
|
+
- lib/bossman/rest.rb
|
37
|
+
- lib/bossman/result.rb
|
38
|
+
- lib/bossman/resultset.rb
|
39
|
+
- lib/bossman/search.rb
|
40
|
+
- README
|
41
|
+
- LICENSE
|
36
42
|
has_rdoc: false
|
37
|
-
homepage: http://github.com/jpignata/bossman
|
43
|
+
homepage: http://github.com/jpignata/bossman-gem
|
38
44
|
post_install_message:
|
39
45
|
rdoc_options: []
|
40
46
|
|