google_search 1.0.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/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +21 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/google_search.gemspec +60 -0
- data/lib/google_search.rb +24 -0
- data/spec/google_search_spec.rb +22 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +96 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2009 Sasa Brankovic
|
|
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,21 @@
|
|
|
1
|
+
= Google Search
|
|
2
|
+
|
|
3
|
+
Tiny wrapper for Google Search APIs.
|
|
4
|
+
|
|
5
|
+
== Usage
|
|
6
|
+
|
|
7
|
+
require 'google_search'
|
|
8
|
+
|
|
9
|
+
GoogleSearch.web :q => "pink floyd"
|
|
10
|
+
|
|
11
|
+
=> {"responseData"=>{"results"=>[{"GsearchResultClass"=>"GwebSearch", "title"=>"<b>Pink Floyd</b> | The Official Site",
|
|
12
|
+
"url"=>"http://www.pinkfloyd.com/", "cacheUrl"=>"http://www.google.com/search?q=cache:iFN1qQtvV7gJ:www.pinkfloyd.com",
|
|
13
|
+
"content"=>"", "visibleUrl"=>"www.pinkfloyd.com"...yaddayadda
|
|
14
|
+
|
|
15
|
+
You can also search videos, images, books etc. by calling <tt>GoogleSearch.[SEARCH TYPE]</tt> (e.g. GoogleSearch.images :q => "apple pie")
|
|
16
|
+
|
|
17
|
+
For documention on options and response formats see http://code.google.com/intl/hr/apis/ajaxsearch/documentation/reference.html#_intro_fonje
|
|
18
|
+
|
|
19
|
+
== Copyright
|
|
20
|
+
|
|
21
|
+
Copyright (c) 2010 Sasa Brankovic. See LICENSE for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
3
|
+
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "google_search"
|
|
8
|
+
gem.summary = %Q{Tiny wrapper for Google Search API}
|
|
9
|
+
# gem.description = %Q{TODO: longer description of your gem}
|
|
10
|
+
gem.email = "sasa@hakeraj.com"
|
|
11
|
+
gem.homepage = "http://github.com/fox/google_search"
|
|
12
|
+
gem.authors = ["Sasa Brankovic"]
|
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
|
14
|
+
gem.add_dependency "activesupport"
|
|
15
|
+
gem.add_dependency "addressable"
|
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
|
17
|
+
end
|
|
18
|
+
Jeweler::GemcutterTasks.new
|
|
19
|
+
rescue LoadError
|
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
require 'spec/rake/spectask'
|
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
|
32
|
+
spec.rcov = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
task :spec => :check_dependencies
|
|
36
|
+
task :default => :spec
|
|
37
|
+
|
|
38
|
+
require 'rake/rdoctask'
|
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
|
41
|
+
|
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
43
|
+
rdoc.title = "google_search #{version}"
|
|
44
|
+
rdoc.rdoc_files.include('README*')
|
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
46
|
+
end
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.0
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{google_search}
|
|
8
|
+
s.version = "1.0.0"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Sasa Brankovic"]
|
|
12
|
+
s.date = %q{2010-02-02}
|
|
13
|
+
s.email = %q{sasa@hakeraj.com}
|
|
14
|
+
s.extra_rdoc_files = [
|
|
15
|
+
"LICENSE",
|
|
16
|
+
"README.rdoc"
|
|
17
|
+
]
|
|
18
|
+
s.files = [
|
|
19
|
+
".document",
|
|
20
|
+
".gitignore",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"README.rdoc",
|
|
23
|
+
"Rakefile",
|
|
24
|
+
"VERSION",
|
|
25
|
+
"google_search.gemspec",
|
|
26
|
+
"lib/google_search.rb",
|
|
27
|
+
"spec/google_search_spec.rb",
|
|
28
|
+
"spec/spec.opts",
|
|
29
|
+
"spec/spec_helper.rb"
|
|
30
|
+
]
|
|
31
|
+
s.homepage = %q{http://github.com/fox/google_search}
|
|
32
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
33
|
+
s.require_paths = ["lib"]
|
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
|
35
|
+
s.summary = %q{Tiny wrapper for Google Search API}
|
|
36
|
+
s.test_files = [
|
|
37
|
+
"spec/google_search_spec.rb",
|
|
38
|
+
"spec/spec_helper.rb"
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
if s.respond_to? :specification_version then
|
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
43
|
+
s.specification_version = 3
|
|
44
|
+
|
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
46
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
|
47
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
|
48
|
+
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
|
49
|
+
else
|
|
50
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
51
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
|
52
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
|
53
|
+
end
|
|
54
|
+
else
|
|
55
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
|
56
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
|
57
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
require 'open-uri'
|
|
3
|
+
require 'addressable/uri'
|
|
4
|
+
|
|
5
|
+
module GoogleSearch
|
|
6
|
+
@@default_options = {}
|
|
7
|
+
|
|
8
|
+
def self.default_options(options = {})
|
|
9
|
+
@@default_options = options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.method_missing(method, args)
|
|
13
|
+
raise unless [:web, :local, :video, :blogs, :news, :books, :images, :patent].include?(method)
|
|
14
|
+
self.query(method, args)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
def self.query(type, options)
|
|
19
|
+
uri = Addressable::URI.parse("http://ajax.googleapis.com/ajax/services/search/#{type}")
|
|
20
|
+
options[:v] = "1.0"
|
|
21
|
+
uri.query_values = @@default_options.merge(options)
|
|
22
|
+
ActiveSupport::JSON.decode(open(uri).read)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "Google search" do
|
|
4
|
+
context "Doing a query" do
|
|
5
|
+
require 'google_search'
|
|
6
|
+
|
|
7
|
+
before :all do
|
|
8
|
+
GoogleSearch.default_options :hl => "hr"
|
|
9
|
+
@result = GoogleSearch.web :q => "Michael Jackson"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it do
|
|
13
|
+
@result.should be_a_kind_of Hash
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should have expected values" do
|
|
17
|
+
@result.should have_key "responseData"
|
|
18
|
+
@result["responseData"].should have_key "results"
|
|
19
|
+
@result["responseData"]["results"].should_not be_empty
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: google_search
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sasa Brankovic
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-02-02 00:00:00 +01:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: rspec
|
|
17
|
+
type: :development
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: 1.2.9
|
|
24
|
+
version:
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: activesupport
|
|
27
|
+
type: :runtime
|
|
28
|
+
version_requirement:
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: "0"
|
|
34
|
+
version:
|
|
35
|
+
- !ruby/object:Gem::Dependency
|
|
36
|
+
name: addressable
|
|
37
|
+
type: :runtime
|
|
38
|
+
version_requirement:
|
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: "0"
|
|
44
|
+
version:
|
|
45
|
+
description:
|
|
46
|
+
email: sasa@hakeraj.com
|
|
47
|
+
executables: []
|
|
48
|
+
|
|
49
|
+
extensions: []
|
|
50
|
+
|
|
51
|
+
extra_rdoc_files:
|
|
52
|
+
- LICENSE
|
|
53
|
+
- README.rdoc
|
|
54
|
+
files:
|
|
55
|
+
- .document
|
|
56
|
+
- .gitignore
|
|
57
|
+
- LICENSE
|
|
58
|
+
- README.rdoc
|
|
59
|
+
- Rakefile
|
|
60
|
+
- VERSION
|
|
61
|
+
- google_search.gemspec
|
|
62
|
+
- lib/google_search.rb
|
|
63
|
+
- spec/google_search_spec.rb
|
|
64
|
+
- spec/spec.opts
|
|
65
|
+
- spec/spec_helper.rb
|
|
66
|
+
has_rdoc: true
|
|
67
|
+
homepage: http://github.com/fox/google_search
|
|
68
|
+
licenses: []
|
|
69
|
+
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options:
|
|
72
|
+
- --charset=UTF-8
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: "0"
|
|
80
|
+
version:
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: "0"
|
|
86
|
+
version:
|
|
87
|
+
requirements: []
|
|
88
|
+
|
|
89
|
+
rubyforge_project:
|
|
90
|
+
rubygems_version: 1.3.5
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 3
|
|
93
|
+
summary: Tiny wrapper for Google Search API
|
|
94
|
+
test_files:
|
|
95
|
+
- spec/google_search_spec.rb
|
|
96
|
+
- spec/spec_helper.rb
|