daimpi-google-search 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +30 -0
- data/Rakefile +28 -0
- data/lib/google-search.rb +6 -0
- data/lib/google-search/google_result.rb +35 -0
- data/lib/google-search/google_result_set.rb +9 -0
- data/lib/google-search/google_search.rb +57 -0
- data/lib/google-search/version.rb +10 -0
- metadata +61 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
lib/google-search.rb
|
9
|
+
lib/google-search/google_result.rb
|
10
|
+
lib/google-search/google_result_set.rb
|
11
|
+
lib/google-search/google_search.rb
|
12
|
+
lib/google-search/version.rb
|
13
|
+
nbproject/private/private.properties
|
14
|
+
nbproject/project.properties
|
15
|
+
nbproject/project.xml
|
16
|
+
script/console
|
17
|
+
script/destroy
|
18
|
+
script/generate
|
19
|
+
script/txt2html
|
20
|
+
setup.rb
|
21
|
+
tasks/deployment.rake
|
22
|
+
tasks/environment.rake
|
23
|
+
tasks/website.rake
|
24
|
+
test/test_google-search.rb
|
25
|
+
test/test_helper.rb
|
26
|
+
website/index.html
|
27
|
+
website/index.txt
|
28
|
+
website/javascripts/rounded_corners_lite.inc.js
|
29
|
+
website/stylesheets/screen.css
|
30
|
+
website/template.html.erb
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
%w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
|
2
|
+
require File.dirname(__FILE__) + '/lib/google-search'
|
3
|
+
|
4
|
+
# Generate all the Rake tasks
|
5
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
6
|
+
$hoe = Hoe.new('google-search', GoogleSearch::VERSION) do |p|
|
7
|
+
p.developer('Hendrik F. Louw', 'hflouw@gmail.com')
|
8
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
9
|
+
p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
10
|
+
p.rubyforge_name = p.name # TODO this is default value
|
11
|
+
# p.extra_deps = [
|
12
|
+
# ['activesupport','>= 2.0.2'],
|
13
|
+
# ]
|
14
|
+
p.extra_dev_deps = [
|
15
|
+
['newgem', ">= #{::Newgem::VERSION}"]
|
16
|
+
]
|
17
|
+
|
18
|
+
p.clean_globs |= %w[**/.DS_Store tmp *.log]
|
19
|
+
path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
|
20
|
+
p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
|
21
|
+
p.rsync_args = '-av --delete --ignore-errors'
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'newgem/tasks' # load /tasks/*.rake
|
25
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
26
|
+
|
27
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
28
|
+
# task :default => [:spec, :features]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class GoogleResult
|
2
|
+
|
3
|
+
@@attributes = [:g_search_result_class, :unescaped_url, :url,
|
4
|
+
:visible_url, :cache_url, :title, :title_no_formatting, :content]
|
5
|
+
|
6
|
+
@@attributes.each do |attr|
|
7
|
+
attr_reader attr
|
8
|
+
end
|
9
|
+
|
10
|
+
# {
|
11
|
+
# "GsearchResultClass": "GwebSearch",
|
12
|
+
# "unescapedUrl": "http://en.wikipedia.org/wiki/Paris_Hilton",
|
13
|
+
# "url": "http://en.wikipedia.org/wiki/Paris_Hilton",
|
14
|
+
# "visibleUrl": "en.wikipedia.org",
|
15
|
+
# "cacheUrl": "http://www.google.com/search?q\u003dcache:TwrPfhd22hYJ:en.wikipedia.org",
|
16
|
+
# "title": "\u003cb\u003eParis Hilton\u003c/b\u003e - Wikipedia, the free encyclopedia",
|
17
|
+
# "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia",
|
18
|
+
# "content": "In 2006, she released her debut album \u003cb\u003eParis\u003c/b\u003e..."
|
19
|
+
# }
|
20
|
+
def initialize(result)
|
21
|
+
result.each do |key, value|
|
22
|
+
string = "#{underscore(key.to_s)}='#{value}'"
|
23
|
+
eval "@#{string}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def underscore(camel_cased_word)
|
29
|
+
camel_cased_word.to_s.gsub(/::/, '/').
|
30
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
31
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
32
|
+
tr("-", "_").
|
33
|
+
downcase
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'json'
|
3
|
+
require 'net/http'
|
4
|
+
|
5
|
+
# Simple class for wrapping the google REST API as given on
|
6
|
+
# http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
|
7
|
+
# into a more Ruby-ish library
|
8
|
+
# Please read previous links but just for a quick view of what this little baby
|
9
|
+
# can do I've copied the main types of searches for you
|
10
|
+
# Web Search http://ajax.googleapis.com/ajax/services/search/web
|
11
|
+
# Local Search http://ajax.googleapis.com/ajax/services/search/local
|
12
|
+
# Video Search http://ajax.googleapis.com/ajax/services/search/video
|
13
|
+
# Blog Search http://ajax.googleapis.com/ajax/services/search/blogs
|
14
|
+
# News Search http://ajax.googleapis.com/ajax/services/search/news
|
15
|
+
# Book Search http://ajax.googleapis.com/ajax/services/search/books
|
16
|
+
# Image Search http://ajax.googleapis.com/ajax/services/search/images
|
17
|
+
# Patent Search http://ajax.googleapis.com/ajax/services/search/patent
|
18
|
+
|
19
|
+
|
20
|
+
class GoogleSearch
|
21
|
+
BASE_URL = "http://ajax.googleapis.com/ajax/services/search"
|
22
|
+
attr_accessor :cached_result
|
23
|
+
attr_accessor :cached_response
|
24
|
+
|
25
|
+
# All you need to do is specify a :type => 'web' or :type => 'local' or whatever
|
26
|
+
# type of search you want to do.
|
27
|
+
# And you also need to pass a query through :q => "Awesomeness".
|
28
|
+
# Any other optional parameters can be specified with a hash key value pair
|
29
|
+
# in the method call of search ie
|
30
|
+
#
|
31
|
+
# search(:type => 'web', :q => 'somequery', :rsz => 'big')
|
32
|
+
# this would return a web search with the query 'somequery' and return a big resultset
|
33
|
+
def search(options = {})
|
34
|
+
# Do a reverse_merge!, but since ruby doesn't have it built in do it like this
|
35
|
+
# if I use it again I'll move reverse_merge into its own little extension library
|
36
|
+
defaults = {:v => "1.0", :type => "web"}
|
37
|
+
options.replace(defaults.merge(options))
|
38
|
+
|
39
|
+
url = "#{BASE_URL}/#{options[:type]}?q=#{URI.encode(options[:q])}"
|
40
|
+
|
41
|
+
options.delete(:type)
|
42
|
+
options.delete(:q)
|
43
|
+
|
44
|
+
options.each do |key, value|
|
45
|
+
url += "&#{key.to_s}=#{URI.encode(value.to_s)}"
|
46
|
+
end
|
47
|
+
url = URI.parse(url)
|
48
|
+
|
49
|
+
@cached_response = Net::HTTP.get_response url
|
50
|
+
@cached_result = JSON.parse(@cached_response.body)
|
51
|
+
if @cached_result['responseStatus'] == 200
|
52
|
+
return @cached_result['responseData']['results']
|
53
|
+
else
|
54
|
+
raise @cached_result['responseDetails']
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: daimpi-google-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hendrik F. Louw
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-11-02 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: google-search is a simple wrapper around Google's RESTful API
|
17
|
+
email: hflouw@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- History.txt
|
26
|
+
- Manifest.txt
|
27
|
+
- README.txt
|
28
|
+
- Rakefile
|
29
|
+
- lib/google-search.rb
|
30
|
+
- lib/google-search/google_result.rb
|
31
|
+
- lib/google-search/google_result_set.rb
|
32
|
+
- lib/google-search/google_search.rb
|
33
|
+
- lib/google-search/version.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://daimpi.co.za
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: "0"
|
52
|
+
version:
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 1.2.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 2
|
59
|
+
summary: A simple wrapper to the google RESTful API
|
60
|
+
test_files: []
|
61
|
+
|