jumzies-google-mini 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/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/google-mini/google-mini.rb +20 -0
- data/lib/google-mini/keymatch.rb +8 -0
- data/lib/google-mini/result.rb +13 -0
- data/lib/google-mini/search.rb +55 -0
- data/lib/google-mini.rb +17 -0
- data/test/google-mini_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +76 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jimmy Baker
|
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
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= google-mini
|
2
|
+
|
3
|
+
* http://github.com/jumzies/google-mini
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
The Google Mini gem simply lets you query your Google Mini appliance with the ease you'd expect from a Ruby library.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Search Results
|
12
|
+
* Suggestions
|
13
|
+
* Synonyms
|
14
|
+
|
15
|
+
== SYNOPSIS:
|
16
|
+
|
17
|
+
require 'google-mini'
|
18
|
+
GoogleMini.search_url = "http://your_google_mini/search?output=xml_no_dtd&client=clientName&site=collectionName&num=100"
|
19
|
+
search = GoogleMini.search('some search term')
|
20
|
+
puts search.results.length
|
21
|
+
puts search.suggestions.length
|
22
|
+
puts search.synonyms.length
|
23
|
+
puts search.keymatches.length
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
* httparty (http://railstips.org/2008/7/29/it-s-an-httparty-and-everyone-is-invited)
|
28
|
+
|
29
|
+
== INSTALL:
|
30
|
+
|
31
|
+
sudo gem install google-mini --source=gems.github.com
|
32
|
+
|
33
|
+
== LICENSE:
|
34
|
+
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2009 Jimmy Baker
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "google-mini"
|
8
|
+
gem.summary = %Q{The Google Mini gem simply lets you query your Google Mini appliance with the ease you'd expect from a Ruby library.}
|
9
|
+
gem.email = "jimmybaker@me.com"
|
10
|
+
gem.homepage = "http://github.com/jumzies/google-mini"
|
11
|
+
gem.authors = ["Jimmy Baker"]
|
12
|
+
gem.add_dependency 'httparty'
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION.yml')
|
46
|
+
config = YAML.load(File.read('VERSION.yml'))
|
47
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
48
|
+
else
|
49
|
+
version = ""
|
50
|
+
end
|
51
|
+
|
52
|
+
rdoc.rdoc_dir = 'rdoc'
|
53
|
+
rdoc.title = "google-mini #{version}"
|
54
|
+
rdoc.rdoc_files.include('README*')
|
55
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
56
|
+
end
|
57
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module GoogleMini
|
2
|
+
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_accessor :search_url
|
6
|
+
|
7
|
+
def search(query, options={})
|
8
|
+
raise Exception.new("You must define a search url.") if @search_url.blank?
|
9
|
+
url = @search_url + "&q=#{url_escape(query)}"
|
10
|
+
Search.new(url, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def url_escape(string)
|
14
|
+
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
|
15
|
+
'%' + $1.unpack('H2' * $1.size).join('%').upcase
|
16
|
+
end.tr(' ', '+')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Search
|
2
|
+
include HTTParty
|
3
|
+
attr_reader :results, :suggestions, :synonyms, :keymatches
|
4
|
+
|
5
|
+
# takes a response hash from a google mini query
|
6
|
+
def initialize(url, options)
|
7
|
+
@results = []
|
8
|
+
@suggestions = []
|
9
|
+
@synonyms = []
|
10
|
+
@keymatches = []
|
11
|
+
|
12
|
+
# ask the google mini for search results
|
13
|
+
response = Search.get(url)
|
14
|
+
|
15
|
+
# results
|
16
|
+
if response['GSP'].has_key?('RES')
|
17
|
+
if response['GSP']['RES']['R'].kind_of?(Array)
|
18
|
+
response['GSP']['RES']['R'].map{ |res| @results << Result.new(res) }
|
19
|
+
else
|
20
|
+
@results << Result.new(response['GSP']['RES']['R'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# suggestions
|
25
|
+
if response['GSP'].has_key?('Spelling')
|
26
|
+
if response['GSP']['Spelling'].kind_of?(Array)
|
27
|
+
response['GSP']['Spelling'].map{ |sp| sp.map{ |k, v| @suggestions << v } }
|
28
|
+
else
|
29
|
+
response['GSP']['Spelling'].map{ |k,v| @suggestions << v }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# synonyms
|
34
|
+
if response['GSP'].has_key?('Synonyms')
|
35
|
+
if response['GSP']['Synonyms'].kind_of?(Array)
|
36
|
+
response['GSP']['Synonyms'].map{ |syn| syn.map{ |k, v| @synonyms << v } }
|
37
|
+
else
|
38
|
+
response['GSP']['Synonyms'].map{ |k,v| @synonyms << v }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# keymatches
|
43
|
+
if response['GSP'].has_key?('GM')
|
44
|
+
if response['GSP']['GM'].kind_of?(Array)
|
45
|
+
response['GSP']['GM'].each do |gm|
|
46
|
+
@keymatches << Keymatch.new(gm)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
@keymatches << Keymatch.new(response['GSP']['GM'])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/google-mini.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rubygems'
|
5
|
+
rescue LoadError
|
6
|
+
nil
|
7
|
+
end
|
8
|
+
|
9
|
+
module GoogleMini
|
10
|
+
VERSION = '0.0.1'
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'httparty'
|
14
|
+
require 'google-mini/google-mini'
|
15
|
+
require 'google-mini/result'
|
16
|
+
require 'google-mini/search'
|
17
|
+
require 'google-mini/keymatch'
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jumzies-google-mini
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jimmy Baker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-18 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: jimmybaker@me.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- lib/google-mini.rb
|
42
|
+
- lib/google-mini/google-mini.rb
|
43
|
+
- lib/google-mini/keymatch.rb
|
44
|
+
- lib/google-mini/result.rb
|
45
|
+
- lib/google-mini/search.rb
|
46
|
+
- test/google-mini_test.rb
|
47
|
+
- test/test_helper.rb
|
48
|
+
has_rdoc: false
|
49
|
+
homepage: http://github.com/jumzies/google-mini
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options:
|
52
|
+
- --charset=UTF-8
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "0"
|
66
|
+
version:
|
67
|
+
requirements: []
|
68
|
+
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.2.0
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: The Google Mini gem simply lets you query your Google Mini appliance with the ease you'd expect from a Ruby library.
|
74
|
+
test_files:
|
75
|
+
- test/google-mini_test.rb
|
76
|
+
- test/test_helper.rb
|