jpignata-bossman 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README +15 -1
- data/bossman.gemspec +1 -1
- data/lib/bossman/basevalueobject.rb +8 -0
- data/lib/bossman/rest.rb +4 -2
- data/lib/bossman/result.rb +9 -2
- data/lib/bossman/resultset.rb +10 -2
- data/lib/bossman.rb +1 -8
- metadata +1 -1
data/README
CHANGED
@@ -41,7 +41,7 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
|
|
41
41
|
puts "-" * 80
|
42
42
|
puts "#{result.abstract}"
|
43
43
|
puts
|
44
|
-
|
44
|
+
|
45
45
|
=== Images
|
46
46
|
|
47
47
|
require 'rubygems'
|
@@ -56,6 +56,7 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
|
|
56
56
|
puts "<img src=\"#{result.url}\" alt=\"#{result.abstract}\" /><br />"
|
57
57
|
end
|
58
58
|
|
59
|
+
|
59
60
|
== Output Objects
|
60
61
|
|
61
62
|
=== Common
|
@@ -104,11 +105,24 @@ BOSSMan can be used to perform image, web and news searches against Yahoo's inde
|
|
104
105
|
.results[].thumbnail_height : Height of thumbnail image
|
105
106
|
.results[].thumbnail_width : Width of thumbnail image
|
106
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
|
116
|
+
|
107
117
|
== Installation
|
108
118
|
|
109
119
|
jp@populuxe:~/code/ruby$ gem sources -a http://gems.github.com
|
110
120
|
jp@populuxe:~/code/ruby$ gem install jpignata-bossman
|
111
121
|
|
122
|
+
== Requirements
|
123
|
+
|
124
|
+
* Active Support >= 2.1
|
125
|
+
|
112
126
|
== LICENSE:
|
113
127
|
|
114
128
|
(The MIT License)
|
data/bossman.gemspec
CHANGED
data/lib/bossman/rest.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
module BOSSMan
|
2
2
|
class REST
|
3
|
-
|
3
|
+
|
4
4
|
def self.get(method, query, options)
|
5
5
|
validate_parameters(options)
|
6
6
|
uri = URI.parse(URI.encode("#{API_BASEURI}/#{method}/#{API_VERSION}/#{query}"))
|
7
7
|
uri.query = options.to_query
|
8
8
|
request = Net::HTTP::Get.new(uri.request_uri)
|
9
9
|
response = Net::HTTP.new(uri.host).request(request)
|
10
|
+
|
10
11
|
case response
|
11
12
|
when Net::HTTPSuccess
|
12
13
|
return ResultSet.new(ActiveSupport::JSON.decode(response.body))
|
13
14
|
else
|
14
15
|
raise BOSSError, parse_error(response.body)
|
15
|
-
end
|
16
|
+
end
|
16
17
|
end
|
17
18
|
|
18
19
|
def self.parse_error(response_string)
|
@@ -27,6 +28,7 @@ module BOSSMan
|
|
27
28
|
unless BOSSMan.application_id
|
28
29
|
raise MissingConfiguration, "Application ID must be set prior to making a service call."
|
29
30
|
end
|
31
|
+
|
30
32
|
unless options[:count] > 0
|
31
33
|
raise InvalidParameter, "Invalid count. Count must be > 0."
|
32
34
|
end
|
data/lib/bossman/result.rb
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
module BOSSMan
|
2
2
|
class Result < BaseValueObject
|
3
3
|
|
4
|
-
def initialize(
|
5
|
-
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
6
|
+
response.each { |key, value| set_parameter(key, value) }
|
6
7
|
end
|
7
8
|
|
9
|
+
def to_xml
|
10
|
+
@response.to_xml(:root => 'result')
|
11
|
+
end
|
12
|
+
|
13
|
+
alias to_s to_xml
|
14
|
+
|
8
15
|
end
|
9
16
|
end
|
data/lib/bossman/resultset.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
module BOSSMan
|
2
2
|
class ResultSet < BaseValueObject
|
3
|
+
|
4
|
+
def initialize(response)
|
5
|
+
@response = response
|
3
6
|
|
4
|
-
|
5
|
-
response["ysearchresponse"].each do |key, value|
|
7
|
+
@response["ysearchresponse"].each do |key, value|
|
6
8
|
if key.include? "resultset"
|
7
9
|
results = Array.new
|
8
10
|
response["ysearchresponse"][key].each { |result| results << Result.new(result) }
|
@@ -12,6 +14,12 @@ module BOSSMan
|
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
17
|
+
|
18
|
+
def to_xml
|
19
|
+
@response['ysearchresponse'].to_xml(:root => 'resultset')
|
20
|
+
end
|
21
|
+
|
22
|
+
alias to_s to_xml
|
15
23
|
|
16
24
|
end
|
17
25
|
end
|
data/lib/bossman.rb
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'active_support'
|
3
3
|
|
4
|
-
|
5
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
6
|
-
|
7
|
-
require 'bossman/search'
|
8
|
-
require 'bossman/rest'
|
9
|
-
require 'bossman/basevalueobject'
|
10
|
-
require 'bossman/resultset'
|
11
|
-
require 'bossman/result'
|
4
|
+
Dir["#{File.dirname(__FILE__)}/bossman/*.rb"].each { |bossman_lib| require bossman_lib }
|
12
5
|
|
13
6
|
module BOSSMan
|
14
7
|
API_VERSION = :v1
|