bossman 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +172 -0
- data/lib/bossman.rb +17 -0
- data/lib/bossman/base_value_object.rb +20 -0
- data/lib/bossman/boss.rb +42 -0
- data/lib/bossman/result.rb +15 -0
- data/lib/bossman/result_set.rb +49 -0
- data/lib/bossman/search.rb +20 -0
- metadata +71 -0
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.md
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
# BOSSMan -- Gem for interaction with the Yahoo BOSS web service
|
2
|
+
|
3
|
+
## Description
|
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/.
|
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 GitHub issues.
|
11
|
+
|
12
|
+
## Example Usage
|
13
|
+
|
14
|
+
### Web
|
15
|
+
|
16
|
+
require 'bossman'
|
17
|
+
include BOSSMan
|
18
|
+
|
19
|
+
BOSSMan.application_id = <Your Application ID>
|
20
|
+
|
21
|
+
boss = BOSSMan::Search.web("prospect park", { :count => 5, :filter => "-hate" })
|
22
|
+
|
23
|
+
puts "Number of results: #{boss.totalhits}"
|
24
|
+
puts
|
25
|
+
|
26
|
+
boss.results.each do |result|
|
27
|
+
puts "#{result.title}"
|
28
|
+
puts "-" * 80
|
29
|
+
puts "#{result.abstract}"
|
30
|
+
puts
|
31
|
+
end
|
32
|
+
|
33
|
+
### News
|
34
|
+
|
35
|
+
require 'bossman'
|
36
|
+
include BOSSMan
|
37
|
+
|
38
|
+
BOSSMan.application_id = <Your Application ID>
|
39
|
+
|
40
|
+
boss = BOSSMan::Search.news("brooklyn new york", { :age => "7d" })
|
41
|
+
|
42
|
+
boss.results.each do |result|
|
43
|
+
puts "#{result.title} [from #{result.source}]"
|
44
|
+
puts "-" * 80
|
45
|
+
puts "#{result.abstract}"
|
46
|
+
puts
|
47
|
+
|
48
|
+
### Images
|
49
|
+
|
50
|
+
require 'bossman'
|
51
|
+
include BOSSMan
|
52
|
+
|
53
|
+
BOSSMan.application_id = <Your Application ID>
|
54
|
+
|
55
|
+
boss = BOSSMan::Search.images("brooklyn dumbo", { :dimensions => "large" })
|
56
|
+
|
57
|
+
boss.results.each do |result|
|
58
|
+
puts "#{result.url}: #{result.abstract}"
|
59
|
+
end
|
60
|
+
|
61
|
+
### Spelling
|
62
|
+
|
63
|
+
require 'bossman'
|
64
|
+
include BOSSMan
|
65
|
+
|
66
|
+
BOSSMan.application_id = <Your Application ID>
|
67
|
+
|
68
|
+
boss = BOSSMan::Search.spelling("Diabretes")
|
69
|
+
|
70
|
+
puts boss.suggestion
|
71
|
+
|
72
|
+
## Output Objects
|
73
|
+
|
74
|
+
Assuming an object bossed called search:
|
75
|
+
|
76
|
+
search = BOSSMan::Search.web("cobble hill", 0, 20)
|
77
|
+
|
78
|
+
### Common
|
79
|
+
|
80
|
+
- search.responsecode : HTTP response code
|
81
|
+
- search.nextpage : REST URL to next page of search results
|
82
|
+
- search.count : Number of search results contained in response
|
83
|
+
- search.start : Search result from which output starts
|
84
|
+
- search.totalhits : De-duplicated total number of results search yielded
|
85
|
+
- search.deephits : Total number of results search yielded
|
86
|
+
- search.results[].clickurl : Tracking URL of result; must be used in user-facing anchor tags by BOSS TOU
|
87
|
+
- search.results[].url : URL of result
|
88
|
+
|
89
|
+
### Web
|
90
|
+
|
91
|
+
- search.results[].abstract : Description of result with keywords emboldened
|
92
|
+
- search.results[].title : Document title with keywords emboldened
|
93
|
+
- search.results[].dispurl : Display URL of result
|
94
|
+
- search.results[].size : Size of result in bytes
|
95
|
+
- search.results[].date : Date result was indexed
|
96
|
+
|
97
|
+
### News
|
98
|
+
|
99
|
+
- search.results[].abstract : Description of news story
|
100
|
+
- search.results[].title : Title of news story
|
101
|
+
- search.results[].language : Language of news story
|
102
|
+
- search.results[].date : Last publication date of news story
|
103
|
+
- search.results[].time : Last publication time of news story
|
104
|
+
- search.results[].source : Source of news story
|
105
|
+
- search.results[].sourceurl : URL of source publication
|
106
|
+
|
107
|
+
### Images
|
108
|
+
|
109
|
+
- search.results[].abstract : Description of image
|
110
|
+
- search.results[].filename : Filename of image
|
111
|
+
- search.results[].size : Size of image
|
112
|
+
- search.results[].format : Format of image
|
113
|
+
- search.results[].height : Height of full-size image
|
114
|
+
- search.results[].date : Last modification date of image (yyyy/mm/dd)
|
115
|
+
- search.results[].mimetype : MIME type of image
|
116
|
+
- search.results[].refererclickurl : Link to page where image was found
|
117
|
+
- search.results[].refererurl : Link to page where image was found
|
118
|
+
- search.results[].title : Title of image (usually the filename)
|
119
|
+
- search.results[].width : Width of full-size image
|
120
|
+
- search.results[].thumbnail_url : URL of thumbnail image
|
121
|
+
- search.results[].thumbnail_height : Height of thumbnail image
|
122
|
+
- search.results[].thumbnail_width : Width of thumbnail image
|
123
|
+
|
124
|
+
### Spelling
|
125
|
+
|
126
|
+
- search.suggestion : Returns spelling suggestion from BOSS
|
127
|
+
|
128
|
+
### Raw dump formats
|
129
|
+
|
130
|
+
Result sets can be dumped as JSON, XML and YAML by use of to_json, to_xml, to_yaml respectively.
|
131
|
+
|
132
|
+
- search.to_xml : dumps XML of the result set
|
133
|
+
- search.to_json : dumps JSON of the result set
|
134
|
+
- search.to_yaml : dumps YAML of the result set
|
135
|
+
- search.results[3] : dumps XML of one search result
|
136
|
+
- search.results[3].to_json : dumps JSON of one search result
|
137
|
+
- search.results[3].to_yaml : dumps YAML of one search result
|
138
|
+
|
139
|
+
## Installation
|
140
|
+
|
141
|
+
jp@populuxe:~/code/ruby$ gem sources -a http://gems.github.com
|
142
|
+
jp@populuxe:~/code/ruby$ gem install jpignata-bossman
|
143
|
+
|
144
|
+
## Requirements
|
145
|
+
|
146
|
+
- Active Support >= 2.1
|
147
|
+
- FakeWeb (in order to run the specs)
|
148
|
+
|
149
|
+
## LICENSE:
|
150
|
+
|
151
|
+
(The MIT License)
|
152
|
+
|
153
|
+
Copyright (c) 2008 Jay Pignata
|
154
|
+
|
155
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
156
|
+
a copy of this software and associated documentation files (the
|
157
|
+
'Software'), to deal in the Software without restriction, including
|
158
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
159
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
160
|
+
permit persons to whom the Software is furnished to do so, subject to
|
161
|
+
the following conditions:
|
162
|
+
|
163
|
+
The above copyright notice and this permission notice shall be
|
164
|
+
included in all copies or substantial portions of the Software.
|
165
|
+
|
166
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
167
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
168
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
169
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
170
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
171
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
172
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/bossman.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
Dir["#{File.dirname(__FILE__)}/bossman/*.rb"].sort.each { |bossman_lib| require bossman_lib }
|
6
|
+
|
7
|
+
module BOSSMan
|
8
|
+
API_VERSION = :v1
|
9
|
+
API_BASEURI = "http://boss.yahooapis.com/ysearch"
|
10
|
+
|
11
|
+
attr_accessor :application_id
|
12
|
+
module_function :application_id, :application_id=
|
13
|
+
|
14
|
+
class MissingConfiguration < StandardError; end
|
15
|
+
class InvalidParameter < StandardError; end
|
16
|
+
class BOSSError < StandardError; end
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class BaseValueObject
|
3
|
+
def set_parameter(key, value)
|
4
|
+
instance_variable_set("@#{key}", value)
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_yaml
|
8
|
+
@response.to_yaml
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_json
|
12
|
+
ActiveSupport::JSON.encode(@response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(*args)
|
16
|
+
method = args.first
|
17
|
+
instance_variable_get("@#{method}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/bossman/boss.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class BOSS
|
3
|
+
|
4
|
+
def initialize(method, query, options)
|
5
|
+
@options = options
|
6
|
+
validate_parameters
|
7
|
+
|
8
|
+
@uri = URI.parse(URI.encode("#{API_BASEURI}/#{method}/#{API_VERSION}/#{query}"))
|
9
|
+
@uri.query = @options.to_query
|
10
|
+
@request = Net::HTTP::Get.new(@uri.request_uri)
|
11
|
+
end
|
12
|
+
|
13
|
+
def get
|
14
|
+
query_api
|
15
|
+
parse_response
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
def query_api
|
20
|
+
@response = Net::HTTP.new(@uri.host).request(@request)
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_response
|
24
|
+
case @response
|
25
|
+
when Net::HTTPSuccess
|
26
|
+
ResultSet.new(ActiveSupport::JSON.decode(@response.body))
|
27
|
+
else
|
28
|
+
raise BOSSError, "Error occurred while querying API: #{@response.body}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate_parameters
|
33
|
+
unless BOSSMan.application_id
|
34
|
+
raise MissingConfiguration, "Application ID must be set prior to making a service call."
|
35
|
+
end
|
36
|
+
|
37
|
+
if @options[:count] <= 0
|
38
|
+
raise InvalidParameter, "Invalid count. Count must be > 0."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class Result < BaseValueObject
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
response.each { |key, value| set_parameter(key, value) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xml
|
10
|
+
@response.to_xml(:root => 'result')
|
11
|
+
end
|
12
|
+
|
13
|
+
alias to_s to_xml
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class ResultSet < BaseValueObject
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
process_response
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_xml
|
10
|
+
@response['ysearchresponse'].to_xml(:root => 'resultset')
|
11
|
+
end
|
12
|
+
|
13
|
+
def _dump(level)
|
14
|
+
@response.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
def self._load(string)
|
18
|
+
ResultSet.new(ActiveSupport::JSON.decode(string))
|
19
|
+
end
|
20
|
+
|
21
|
+
alias to_s to_xml
|
22
|
+
|
23
|
+
private
|
24
|
+
def process_response
|
25
|
+
@response["ysearchresponse"].each do |key, value|
|
26
|
+
case key
|
27
|
+
when "resultset_spell"
|
28
|
+
process_spelling_result
|
29
|
+
when /resultset/
|
30
|
+
process_resultset(key)
|
31
|
+
else
|
32
|
+
set_parameter(key, value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def process_spelling_result
|
38
|
+
set_parameter("suggestion", @response["ysearchresponse"]["resultset_spell"].first["suggestion"])
|
39
|
+
end
|
40
|
+
|
41
|
+
def process_resultset(key)
|
42
|
+
results = @response["ysearchresponse"][key].map do |result|
|
43
|
+
Result.new(result)
|
44
|
+
end
|
45
|
+
|
46
|
+
set_parameter("results", results)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BOSSMan
|
2
|
+
class Search
|
3
|
+
DEFAULT_COUNT = 10
|
4
|
+
DEFAULT_START = 0
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def method_missing(*args)
|
8
|
+
method, query, options = args
|
9
|
+
super unless [:web, :images, :news, :spelling].include?(method)
|
10
|
+
boss = BOSS.new(method, query, options_defaults.merge!(options))
|
11
|
+
boss.get
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def self.options_defaults
|
17
|
+
{:appid => BOSSMan.application_id, :count => DEFAULT_COUNT, :start => DEFAULT_START }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bossman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jay Pignata
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-20 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.1.0
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: john.pignata@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
33
|
+
files:
|
34
|
+
- lib/bossman.rb
|
35
|
+
- lib/bossman/base_value_object.rb
|
36
|
+
- lib/bossman/boss.rb
|
37
|
+
- lib/bossman/result.rb
|
38
|
+
- lib/bossman/result_set.rb
|
39
|
+
- lib/bossman/search.rb
|
40
|
+
- README.md
|
41
|
+
- LICENSE
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/jpignata/bossman-gem
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Gem for interaction with the Yahoo BOSS web service.
|
70
|
+
test_files: []
|
71
|
+
|