jpignata-bossman 0.0.2
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.
- data/README +3 -0
- data/bossman.gemspec +13 -0
- data/lib/bossman.rb +89 -0
- metadata +63 -0
data/README
ADDED
data/bossman.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "bossman"
|
3
|
+
s.version = "0.0.2"
|
4
|
+
s.date = "2008-08-11"
|
5
|
+
s.summary = "Library for interaction with the Yahoo BOSS web service."
|
6
|
+
s.email = "jpignata@waterfrontmedia.com"
|
7
|
+
s.homepage = "http://github.com/jpignata/bossman"
|
8
|
+
s.description = "Library for interaction with the Yahoo BOSS web service."
|
9
|
+
s.authors = ["John Pignata"]
|
10
|
+
s.files = ["README", "bossman.gemspec", "lib/bossman.rb"]
|
11
|
+
s.add_dependency("rails", [">= 2.1.0"])
|
12
|
+
s.has_rdoc = false
|
13
|
+
end
|
data/lib/bossman.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'active_support'
|
5
|
+
require 'rexml/xpath'
|
6
|
+
require 'rexml/document'
|
7
|
+
|
8
|
+
module BOSSMan
|
9
|
+
VERSION = :v1
|
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
|
+
}
|
43
|
+
|
44
|
+
options[:filter] = filter if filter
|
45
|
+
options[:dimensions] = dimensions if dimensions
|
46
|
+
options[:refererurl] = refererurl if refererurl
|
47
|
+
options[:url] = url if url
|
48
|
+
|
49
|
+
get_from_boss(method, query, options)
|
50
|
+
end
|
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
|
+
}
|
60
|
+
|
61
|
+
options[:age] = age if age
|
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
|
70
|
+
|
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
|
+
response_document = REXML::Document.new(response.body)
|
79
|
+
code = REXML::XPath.first(response_document, '//yahoo:code').text
|
80
|
+
description = REXML::XPath.first(response_document, '//yahoo:description').text
|
81
|
+
detail = REXML::XPath.first(response_document, '//yahoo:detail').text
|
82
|
+
raise BOSSError, "#{code} #{description}: #{detail}"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class MissingConfiguration < StandardError; end
|
87
|
+
class BOSSError < StandardError; end
|
88
|
+
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jpignata-bossman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Pignata
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-11 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.0
|
23
|
+
version:
|
24
|
+
description: Library for interaction with the Yahoo BOSS web service.
|
25
|
+
email: jpignata@waterfrontmedia.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- README
|
34
|
+
- bossman.gemspec
|
35
|
+
- lib/bossman.rb
|
36
|
+
has_rdoc: false
|
37
|
+
homepage: http://github.com/jpignata/bossman
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: Library for interaction with the Yahoo BOSS web service.
|
62
|
+
test_files: []
|
63
|
+
|