yboss 0.2.0
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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +24 -0
- data/README.rdoc +168 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/yboss.rb +26 -0
- data/lib/yboss/base.rb +85 -0
- data/lib/yboss/blogs.rb +8 -0
- data/lib/yboss/config.rb +15 -0
- data/lib/yboss/images.rb +8 -0
- data/lib/yboss/limitedweb.rb +8 -0
- data/lib/yboss/news.rb +8 -0
- data/lib/yboss/oauth.rb +107 -0
- data/lib/yboss/related.rb +8 -0
- data/lib/yboss/result/base.rb +30 -0
- data/lib/yboss/result/item.rb +27 -0
- data/lib/yboss/spelling.rb +8 -0
- data/lib/yboss/web.rb +8 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/yboss_spec.rb +7 -0
- metadata +152 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Copyright (c) 2013, Tobias Begalke
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
* Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
* Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
* Neither the name of the author nor the names of its contributors may
|
12
|
+
be used to endorse or promote products derived from this software without
|
13
|
+
specific prior written permission.
|
14
|
+
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
16
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
17
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
19
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
20
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
21
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
22
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
23
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
24
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
= yboss
|
2
|
+
|
3
|
+
yboss is a ruby library for the Yahoo BOSS API (http://developer.yahoo.com/boss/search/)
|
4
|
+
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
=== Configuration
|
8
|
+
|
9
|
+
require 'yboss'
|
10
|
+
|
11
|
+
YBoss::Config.instance.oauth_key = 'your consumer_key here'
|
12
|
+
YBoss::Config.instance.oauth_secret = 'your consumer_secret here'
|
13
|
+
|
14
|
+
# in case you need to use a proxy
|
15
|
+
#
|
16
|
+
YBoss::Config.instance.proxy = 'http://your.proxy-address.com:3128/'
|
17
|
+
|
18
|
+
=== Parameters
|
19
|
+
|
20
|
+
You may use the same parameter names that are documented in the Boss
|
21
|
+
API Guide at http://developer.yahoo.com/boss/search/boss_api_guide/.
|
22
|
+
|
23
|
+
=== The web search service
|
24
|
+
|
25
|
+
res = YBoss.web('q' => 'tuscany')
|
26
|
+
|
27
|
+
res.responsecode
|
28
|
+
> 200
|
29
|
+
res.start
|
30
|
+
> 0
|
31
|
+
res.count
|
32
|
+
> 20
|
33
|
+
res.totalresults
|
34
|
+
> 576
|
35
|
+
|
36
|
+
res.items.each do |i|
|
37
|
+
puts "#{i.url}: #{i.title}, #{i.abstract}"
|
38
|
+
puts " date: #{i.date}"
|
39
|
+
puts " clickurl: #{i.clickurl}"
|
40
|
+
puts " dispurl: #{i.dispurl}"
|
41
|
+
end
|
42
|
+
|
43
|
+
=== The limitedweb search service
|
44
|
+
|
45
|
+
res = YBoss.limitedweb('q' => 'tuscany')
|
46
|
+
|
47
|
+
The result has the same methods as the web result
|
48
|
+
|
49
|
+
=== The image search service
|
50
|
+
|
51
|
+
res = YBoss.images('q' => 'ford mustang')
|
52
|
+
|
53
|
+
res.responsecode
|
54
|
+
> 200
|
55
|
+
res.start
|
56
|
+
> 0
|
57
|
+
res.count
|
58
|
+
> 35
|
59
|
+
res.totalresults
|
60
|
+
> 19400
|
61
|
+
|
62
|
+
res.items.each do |i|
|
63
|
+
puts "#{i.url}: #{i.title} (#{i.size}, #{i.format})"
|
64
|
+
puts " size: #{i.width}x#{i.height}"
|
65
|
+
puts " clickurl: #{i.clickurl}"
|
66
|
+
puts " refererclickurl: #{i.refererclickurl}"
|
67
|
+
puts " refererurl: #{i.refererurl}"
|
68
|
+
puts " thumbnailheight: #{i.thumbnailheight}"
|
69
|
+
puts " thumbnailurl: #{i.thumbnailurl}"
|
70
|
+
end
|
71
|
+
|
72
|
+
=== The news search service
|
73
|
+
|
74
|
+
res = YBoss.news('q' => 'Mercedes Benz')
|
75
|
+
|
76
|
+
res.responsecode
|
77
|
+
> 200
|
78
|
+
res.start
|
79
|
+
> 0
|
80
|
+
res.count
|
81
|
+
> 50
|
82
|
+
res.totalresults
|
83
|
+
> 492
|
84
|
+
|
85
|
+
res.items.each do |i|
|
86
|
+
puts "#{i.url}: #{i.title}"
|
87
|
+
puts " abstract: #{i.abstract}"
|
88
|
+
puts " clickurl: #{i.clickurl}"
|
89
|
+
puts " language: #{i.language}"
|
90
|
+
puts " date: #{Time.at(i.date)}"
|
91
|
+
puts " source: #{i.source}"
|
92
|
+
puts " sourceurl: #{i.sourceurl}"
|
93
|
+
end
|
94
|
+
|
95
|
+
=== The blog search service
|
96
|
+
|
97
|
+
res = YBoss.blogs('q' => 'Mercedes Benz')
|
98
|
+
|
99
|
+
res.responsecode
|
100
|
+
> 200
|
101
|
+
res.start
|
102
|
+
> 0
|
103
|
+
res.count
|
104
|
+
> 20
|
105
|
+
res.totalresults
|
106
|
+
> 17016
|
107
|
+
|
108
|
+
res.items.each do |i|
|
109
|
+
puts "#{i.dispurl}: #{i.title}"
|
110
|
+
puts " abstract: #{i.abstract}"
|
111
|
+
puts " clickurl: #{i.clickurl}"
|
112
|
+
puts " keyterms: #{i.keyterms}"
|
113
|
+
puts " date: #{i.date}"
|
114
|
+
puts " author: #{i.author}"
|
115
|
+
puts " icon: #{i.icon}"
|
116
|
+
puts " score: #{i.score}"
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
=== The spelling service
|
121
|
+
|
122
|
+
res = YBoss.spelling('q' => 'gruffaloe')
|
123
|
+
|
124
|
+
res.responsecode
|
125
|
+
> 200
|
126
|
+
res.start
|
127
|
+
> 0
|
128
|
+
res.count
|
129
|
+
> 1
|
130
|
+
res.totalresults
|
131
|
+
> 1
|
132
|
+
|
133
|
+
res.items.each do |i|
|
134
|
+
puts i.suggestion
|
135
|
+
end
|
136
|
+
|
137
|
+
=== The related [also try] service
|
138
|
+
|
139
|
+
res = YBoss.related('q' => 'gruffalo')
|
140
|
+
|
141
|
+
res.responsecode
|
142
|
+
> 200
|
143
|
+
res.start
|
144
|
+
> 0
|
145
|
+
res.count
|
146
|
+
> 4
|
147
|
+
res.totalresults
|
148
|
+
> 4
|
149
|
+
|
150
|
+
res.items.each do |i|
|
151
|
+
puts i.suggestion
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
== Contributing to yboss
|
156
|
+
|
157
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
158
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
159
|
+
* Fork the project.
|
160
|
+
* Start a feature/bugfix branch.
|
161
|
+
* Commit and push until you are happy with your contribution.
|
162
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
163
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
164
|
+
|
165
|
+
== Copyright
|
166
|
+
|
167
|
+
Copyright (c) 2013 Tobias Begalke. See LICENSE.txt for further details.
|
168
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "yboss"
|
18
|
+
gem.homepage = "http://github.com/elcamino/yboss"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Yahoo BOSS library}
|
21
|
+
gem.description = %Q{yboss is a ruby library for the Yahoo BOSS API}
|
22
|
+
gem.email = "tob@spyz.org"
|
23
|
+
gem.authors = ["Tobias Begalke"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "yboss #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/lib/yboss.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'yboss/config'
|
2
|
+
|
3
|
+
module YBoss
|
4
|
+
SERVICE_PREFIX = 'http://yboss.yahooapis.com/ysearch/'
|
5
|
+
|
6
|
+
|
7
|
+
def self.method_missing(sym, *args, &block)
|
8
|
+
clazz_name = 'YBoss::' + sym.to_s.split(/_/).map { |w| w[0].upcase + w[1..w.length] }.join('::')
|
9
|
+
lib_name = 'yboss/' + sym.to_s.gsub(/_/, '/')
|
10
|
+
require lib_name
|
11
|
+
|
12
|
+
clazz = class_from_string(clazz_name)
|
13
|
+
return clazz.new(args[0]).call
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def self.class_from_string(str)
|
18
|
+
str.split('::').inject(Object) do |mod, class_name|
|
19
|
+
mod.const_get(class_name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
class ArgumentException < Exception ; end
|
25
|
+
|
26
|
+
end
|
data/lib/yboss/base.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module YBoss
|
2
|
+
class Base
|
3
|
+
require 'yboss/oauth'
|
4
|
+
require 'yboss/config'
|
5
|
+
require 'yboss/result/base'
|
6
|
+
require 'net/http'
|
7
|
+
require 'json'
|
8
|
+
require 'uri'
|
9
|
+
|
10
|
+
attr_reader :credits, :options
|
11
|
+
|
12
|
+
def initialize(options = {})
|
13
|
+
if options.is_a?(Hash)
|
14
|
+
options.delete('format')
|
15
|
+
end
|
16
|
+
|
17
|
+
@options = {
|
18
|
+
'format' => 'json',
|
19
|
+
}.merge(options)
|
20
|
+
|
21
|
+
@oauth = YBoss::Oauth.new
|
22
|
+
@oauth.consumer_key = YBoss::Config.instance.oauth_key
|
23
|
+
@oauth.consumer_secret = YBoss::Config.instance.oauth_secret
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(options = {})
|
27
|
+
data = fetch(@options.merge(options))
|
28
|
+
|
29
|
+
clazz = YBoss.class_from_string(self.class.to_s + '::Result')
|
30
|
+
clazz.new(data)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def fetch(options = {})
|
35
|
+
@options.merge!(options)
|
36
|
+
|
37
|
+
url = base_uri + '?'
|
38
|
+
url += @options.find_all { |k,v| ! v.nil? }.map { |k,v| "#{k}=#{URI.escape(v)}" }.join('&')
|
39
|
+
|
40
|
+
parsed_url = URI.parse(url)
|
41
|
+
url += "?" + @oauth.sign(parsed_url).query_string
|
42
|
+
|
43
|
+
data = nil
|
44
|
+
|
45
|
+
if YBoss::Config.instance.proxy
|
46
|
+
proxy_uri = URI.parse(YBoss::Config.instance.proxy)
|
47
|
+
|
48
|
+
Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port).start(parsed_url.host) { | http |
|
49
|
+
req = Net::HTTP::Get.new "#{ parsed_url.path }?" + @oauth.sign(parsed_url).query_string
|
50
|
+
response = http.request(req)
|
51
|
+
if ! response.is_a?(Net::HTTPSuccess)
|
52
|
+
raise FetchError.new("Got error while fetching #{url}: #{response.code} #{response.message}")
|
53
|
+
end
|
54
|
+
|
55
|
+
data = JSON.parse(response.read_body)
|
56
|
+
}
|
57
|
+
else
|
58
|
+
Net::HTTP.start( parsed_url.host ) { | http |
|
59
|
+
req = Net::HTTP::Get.new "#{ parsed_url.path }?" + @oauth.sign(parsed_url).query_string
|
60
|
+
response = http.request(req)
|
61
|
+
if ! response.is_a?(Net::HTTPSuccess)
|
62
|
+
raise FetchError.new("Got error while fetching #{url}: #{response.code} #{response.message}")
|
63
|
+
end
|
64
|
+
|
65
|
+
data = JSON.parse(response.read_body)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
data
|
71
|
+
end
|
72
|
+
|
73
|
+
def method_name
|
74
|
+
# derive the method name from the class name
|
75
|
+
#
|
76
|
+
self.class.to_s.downcase.split(/::/).last
|
77
|
+
end
|
78
|
+
|
79
|
+
def base_uri
|
80
|
+
::YBoss::SERVICE_PREFIX + method_name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class FetchError < Exception ; end
|
85
|
+
end
|
data/lib/yboss/blogs.rb
ADDED
data/lib/yboss/config.rb
ADDED
data/lib/yboss/images.rb
ADDED
data/lib/yboss/news.rb
ADDED
data/lib/yboss/oauth.rb
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
# A utility for signing an url using OAuth in a way that's convenient for debugging
|
2
|
+
# Note: the standard Ruby OAuth lib is here http://github.com/mojodna/oauth
|
3
|
+
# License: http://gist.github.com/375593
|
4
|
+
# Usage: see example.rb below
|
5
|
+
|
6
|
+
require 'uri'
|
7
|
+
require 'cgi'
|
8
|
+
require 'openssl'
|
9
|
+
require 'base64'
|
10
|
+
|
11
|
+
module YBoss
|
12
|
+
class Oauth
|
13
|
+
|
14
|
+
attr_accessor :consumer_key, :consumer_secret, :token, :token_secret, :req_method,
|
15
|
+
:sig_method, :oauth_version, :callback_url, :params, :req_url, :base_str
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@consumer_key = ''
|
19
|
+
@consumer_secret = ''
|
20
|
+
@token = ''
|
21
|
+
@token_secret = ''
|
22
|
+
@req_method = 'GET'
|
23
|
+
@sig_method = 'HMAC-SHA1'
|
24
|
+
@oauth_version = '1.0'
|
25
|
+
@callback_url = ''
|
26
|
+
end
|
27
|
+
|
28
|
+
# openssl::random_bytes returns non-word chars, which need to be removed. using alt method to get length
|
29
|
+
# ref http://snippets.dzone.com/posts/show/491
|
30
|
+
def nonce
|
31
|
+
Array.new( 5 ) { rand(256) }.pack('C*').unpack('H*').first
|
32
|
+
end
|
33
|
+
|
34
|
+
def percent_encode( string )
|
35
|
+
|
36
|
+
# ref http://snippets.dzone.com/posts/show/1260
|
37
|
+
return URI.escape( string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]") ).gsub('*', '%2A')
|
38
|
+
end
|
39
|
+
|
40
|
+
# @ref http://oauth.net/core/1.0/#rfc.section.9.2
|
41
|
+
def signature
|
42
|
+
key = percent_encode( @consumer_secret ) + '&' + percent_encode( @token_secret )
|
43
|
+
|
44
|
+
# ref: http://blog.nathanielbibler.com/post/63031273/openssl-hmac-vs-ruby-hmac-benchmarks
|
45
|
+
digest = OpenSSL::Digest::Digest.new( 'sha1' )
|
46
|
+
hmac = OpenSSL::HMAC.digest( digest, key, @base_str )
|
47
|
+
|
48
|
+
# ref http://groups.google.com/group/oauth-ruby/browse_thread/thread/9110ed8c8f3cae81
|
49
|
+
Base64.encode64( hmac ).chomp.gsub( /\n/, '' )
|
50
|
+
end
|
51
|
+
|
52
|
+
# sort (very important as it affects the signature), concat, and percent encode
|
53
|
+
# @ref http://oauth.net/core/1.0/#rfc.section.9.1.1
|
54
|
+
# @ref http://oauth.net/core/1.0/#9.2.1
|
55
|
+
# @ref http://oauth.net/core/1.0/#rfc.section.A.5.1
|
56
|
+
def query_string
|
57
|
+
pairs = []
|
58
|
+
@params.sort.each { | key, val |
|
59
|
+
pairs.push( "#{ percent_encode( key ) }=#{ percent_encode( val.to_s ) }" )
|
60
|
+
}
|
61
|
+
pairs.join '&'
|
62
|
+
end
|
63
|
+
|
64
|
+
# organize params & create signature
|
65
|
+
def sign( parsed_url )
|
66
|
+
|
67
|
+
@params = {
|
68
|
+
'oauth_consumer_key' => @consumer_key,
|
69
|
+
'oauth_nonce' => nonce,
|
70
|
+
'oauth_signature_method' => @sig_method,
|
71
|
+
'oauth_timestamp' => Time.now.to_i.to_s,
|
72
|
+
'oauth_version' => @oauth_version
|
73
|
+
}
|
74
|
+
|
75
|
+
# if url has query, merge key/values into params obj overwriting defaults
|
76
|
+
if parsed_url.query
|
77
|
+
CGI.parse( parsed_url.query ).each do |k,v|
|
78
|
+
if v.is_a?(Array) && v.count == 1
|
79
|
+
@params[k] = v.first
|
80
|
+
else
|
81
|
+
@params[k] = v
|
82
|
+
end
|
83
|
+
end
|
84
|
+
# @params.merge! CGI.parse( parsed_url.query )
|
85
|
+
end
|
86
|
+
|
87
|
+
# @ref http://oauth.net/core/1.0/#rfc.section.9.1.2
|
88
|
+
@req_url = parsed_url.scheme + '://' + parsed_url.host + parsed_url.path
|
89
|
+
|
90
|
+
# create base str. make it an object attr for ez debugging
|
91
|
+
# ref http://oauth.net/core/1.0/#anchor14
|
92
|
+
@base_str = [
|
93
|
+
@req_method,
|
94
|
+
percent_encode( req_url ),
|
95
|
+
|
96
|
+
# normalization is just x-www-form-urlencoded
|
97
|
+
percent_encode( query_string )
|
98
|
+
|
99
|
+
].join( '&' )
|
100
|
+
|
101
|
+
# add signature
|
102
|
+
@params[ 'oauth_signature' ] = signature
|
103
|
+
|
104
|
+
return self
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module YBoss
|
2
|
+
module Result
|
3
|
+
class Base
|
4
|
+
attr_reader :responsecode, :start, :count, :totalresults, :items
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
resp = data['bossresponse']
|
8
|
+
@responsecode = resp['responsecode']
|
9
|
+
lw = resp[self.class.to_s.split(/::/)[1].downcase]
|
10
|
+
@start = lw['start']
|
11
|
+
@count = lw['count']
|
12
|
+
@totalresults = lw['totalresults']
|
13
|
+
@items = []
|
14
|
+
|
15
|
+
clazz = YBoss.class_from_string(self.class.to_s + '::Item')
|
16
|
+
|
17
|
+
lw['results'].to_a.each do |r|
|
18
|
+
@items << clazz.new(r)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Item
|
23
|
+
require 'yboss/result/item'
|
24
|
+
include YBoss::Result::Item
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module YBoss
|
2
|
+
module Result
|
3
|
+
module Item
|
4
|
+
|
5
|
+
def initialize(data = {})
|
6
|
+
@data = data
|
7
|
+
end
|
8
|
+
|
9
|
+
def keys
|
10
|
+
@data.keys
|
11
|
+
end
|
12
|
+
|
13
|
+
def each(name, *args, &block)
|
14
|
+
yield @data
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
@data
|
19
|
+
end
|
20
|
+
|
21
|
+
def method_missing(name, *args, &block)
|
22
|
+
raise YBoss::ArgumentException.new("there is no data field called \"#{name}\" here!") unless @data.has_key?(name.to_s)
|
23
|
+
@data[name.to_s]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/yboss/web.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'yboss'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
data/spec/yboss_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yboss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tobias Begalke
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.8.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.12'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.12'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.0.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: jeweler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.4
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.8.4
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: yboss is a ruby library for the Yahoo BOSS API
|
95
|
+
email: tob@spyz.org
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files:
|
99
|
+
- LICENSE.txt
|
100
|
+
- README.rdoc
|
101
|
+
files:
|
102
|
+
- .document
|
103
|
+
- .rspec
|
104
|
+
- Gemfile
|
105
|
+
- LICENSE.txt
|
106
|
+
- README.rdoc
|
107
|
+
- Rakefile
|
108
|
+
- VERSION
|
109
|
+
- lib/yboss.rb
|
110
|
+
- lib/yboss/base.rb
|
111
|
+
- lib/yboss/blogs.rb
|
112
|
+
- lib/yboss/config.rb
|
113
|
+
- lib/yboss/images.rb
|
114
|
+
- lib/yboss/limitedweb.rb
|
115
|
+
- lib/yboss/news.rb
|
116
|
+
- lib/yboss/oauth.rb
|
117
|
+
- lib/yboss/related.rb
|
118
|
+
- lib/yboss/result/base.rb
|
119
|
+
- lib/yboss/result/item.rb
|
120
|
+
- lib/yboss/spelling.rb
|
121
|
+
- lib/yboss/web.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/yboss_spec.rb
|
124
|
+
homepage: http://github.com/elcamino/yboss
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
133
|
+
requirements:
|
134
|
+
- - ! '>='
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: 4540348285464655124
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ! '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 1.8.24
|
149
|
+
signing_key:
|
150
|
+
specification_version: 3
|
151
|
+
summary: Yahoo BOSS library
|
152
|
+
test_files: []
|