daimpi-google-rest 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-11-04
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,35 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ github-test.rb
7
+ google-rest.gemspec
8
+ lib/google-rest.rb
9
+ lib/google-rest/google_result.rb
10
+ lib/google-rest/google_result_set.rb
11
+ lib/google-rest/google_search.rb
12
+ nbproject/private/private.properties
13
+ nbproject/project.properties
14
+ nbproject/project.xml
15
+ pkg/google-rest-0.0.2.gem
16
+ pkg/google-rest-0.0.2.tgz
17
+ pkg/google-rest-0.0.2/History.txt
18
+ pkg/google-rest-0.0.2/Manifest.txt
19
+ pkg/google-rest-0.0.2/PostInstall.txt
20
+ pkg/google-rest-0.0.2/README.rdoc
21
+ pkg/google-rest-0.0.2/Rakefile
22
+ pkg/google-rest-0.0.2/lib/google-rest.rb
23
+ pkg/google-rest-0.0.2/lib/google-rest/google_result.rb
24
+ pkg/google-rest-0.0.2/lib/google-rest/google_result_set.rb
25
+ pkg/google-rest-0.0.2/lib/google-rest/google_search.rb
26
+ pkg/google-rest-0.0.2/script/console
27
+ pkg/google-rest-0.0.2/script/destroy
28
+ pkg/google-rest-0.0.2/script/generate
29
+ pkg/google-rest-0.0.2/test/test_google-rest.rb
30
+ pkg/google-rest-0.0.2/test/test_helper.rb
31
+ script/console
32
+ script/destroy
33
+ script/generate
34
+ test/test_google-rest.rb
35
+ test/test_helper.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,6 @@
1
+ Remember it's not the size of the hammer, it's the angle you swing it at.
2
+
3
+
4
+ For more information on google-rest, see http://google-rest.rubyforge.org
5
+
6
+
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
1
+ = google-rest
2
+
3
+ * http://daimpi.co.za
4
+
5
+ == DESCRIPTION:
6
+
7
+ A Simple Ruby wrapper for the Google REST API
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ No Problems.. my programs are perfect :P
12
+
13
+ == SYNOPSIS:
14
+
15
+ require 'rubygems'
16
+ require 'google-rest'
17
+ google = GoogleSearch.new
18
+
19
+ google.search(:q => "the answer to the universe")
20
+ # yeah thats bout it, then you get a resultset back which you can iterate through and do with what you want
21
+
22
+
23
+ == REQUIREMENTS:
24
+
25
+ Be smarter than a goldfish
26
+
27
+ == INSTALL:
28
+
29
+ Waiting for rubyforge aproval, github gem generation not working for some strange reason
30
+
31
+ == LICENSE:
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2008 Hendrik F. Louw
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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-rest'
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-rest', GoogleRest::VERSION) do |p|
7
+ p.developer('Hendrik 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,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{google-rest}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Hendrik Louw"]
9
+ s.date = %q{2008-11-09}
10
+ s.description = %q{A Simple Ruby wrapper for the Google REST API}
11
+ s.email = ["hflouw@gmail.com"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "pkg/google-rest-0.0.2/History.txt", "pkg/google-rest-0.0.2/Manifest.txt", "pkg/google-rest-0.0.2/PostInstall.txt", "pkg/google-rest-0.0.2/README.rdoc"]
13
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "github-test.rb", "google-rest.gemspec", "lib/google-rest.rb", "lib/google-rest/google_result.rb", "lib/google-rest/google_result_set.rb", "lib/google-rest/google_search.rb", "nbproject/private/private.properties", "nbproject/project.properties", "nbproject/project.xml", "pkg/google-rest-0.0.2.gem", "pkg/google-rest-0.0.2.tgz", "pkg/google-rest-0.0.2/History.txt", "pkg/google-rest-0.0.2/Manifest.txt", "pkg/google-rest-0.0.2/PostInstall.txt", "pkg/google-rest-0.0.2/README.rdoc", "pkg/google-rest-0.0.2/Rakefile", "pkg/google-rest-0.0.2/lib/google-rest.rb", "pkg/google-rest-0.0.2/lib/google-rest/google_result.rb", "pkg/google-rest-0.0.2/lib/google-rest/google_result_set.rb", "pkg/google-rest-0.0.2/lib/google-rest/google_search.rb", "pkg/google-rest-0.0.2/script/console", "pkg/google-rest-0.0.2/script/destroy", "pkg/google-rest-0.0.2/script/generate", "pkg/google-rest-0.0.2/test/test_google-rest.rb", "pkg/google-rest-0.0.2/test/test_helper.rb", "script/console", "script/destroy", "script/generate", "test/test_google-rest.rb", "test/test_helper.rb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://daimpi.co.za}
16
+ s.post_install_message = %q{PostInstall.txt}
17
+ s.rdoc_options = ["--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{google-rest}
20
+ s.rubygems_version = %q{1.3.1}
21
+ s.summary = %q{A Simple Ruby wrapper for the Google REST API}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_development_dependency(%q<newgem>, [">= 1.0.7"])
29
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
30
+ else
31
+ s.add_dependency(%q<newgem>, [">= 1.0.7"])
32
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<newgem>, [">= 1.0.7"])
36
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
37
+ end
38
+ end
@@ -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,9 @@
1
+ class GoogleResultSet < Array
2
+
3
+ # Expects an array outputs an enhanced array
4
+ def initialize(results)
5
+ results['responseData']['results'].each do |result|
6
+ self.push(GoogleResult.new(result))
7
+ end
8
+ end
9
+ 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
@@ -0,0 +1,9 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'google-rest/google_search'
5
+ require 'google-rest/google_result'
6
+ require 'google-rest/google_result_set'
7
+ module GoogleRest
8
+ VERSION = '0.0.2'
9
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/google-rest.rb'}"
9
+ puts "Loading google-rest gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daimpi-google-rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Hendrik Louw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-09 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.7
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: hoe
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 1.8.0
32
+ version:
33
+ description: A Simple Ruby wrapper for the Google REST API
34
+ email:
35
+ - hflouw@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - History.txt
42
+ - Manifest.txt
43
+ - PostInstall.txt
44
+ - README.rdoc
45
+ - pkg/google-rest-0.0.2/History.txt
46
+ - pkg/google-rest-0.0.2/Manifest.txt
47
+ - pkg/google-rest-0.0.2/PostInstall.txt
48
+ - pkg/google-rest-0.0.2/README.rdoc
49
+ files:
50
+ - History.txt
51
+ - Manifest.txt
52
+ - PostInstall.txt
53
+ - README.rdoc
54
+ - Rakefile
55
+ - github-test.rb
56
+ - google-rest.gemspec
57
+ - lib/google-rest.rb
58
+ - lib/google-rest/google_result.rb
59
+ - lib/google-rest/google_result_set.rb
60
+ - lib/google-rest/google_search.rb
61
+ - nbproject/private/private.properties
62
+ - nbproject/project.properties
63
+ - nbproject/project.xml
64
+ - pkg/google-rest-0.0.2.gem
65
+ - pkg/google-rest-0.0.2.tgz
66
+ - pkg/google-rest-0.0.2/History.txt
67
+ - pkg/google-rest-0.0.2/Manifest.txt
68
+ - pkg/google-rest-0.0.2/PostInstall.txt
69
+ - pkg/google-rest-0.0.2/README.rdoc
70
+ - pkg/google-rest-0.0.2/Rakefile
71
+ - pkg/google-rest-0.0.2/lib/google-rest.rb
72
+ - pkg/google-rest-0.0.2/lib/google-rest/google_result.rb
73
+ - pkg/google-rest-0.0.2/lib/google-rest/google_result_set.rb
74
+ - pkg/google-rest-0.0.2/lib/google-rest/google_search.rb
75
+ - pkg/google-rest-0.0.2/script/console
76
+ - pkg/google-rest-0.0.2/script/destroy
77
+ - pkg/google-rest-0.0.2/script/generate
78
+ - pkg/google-rest-0.0.2/test/test_google-rest.rb
79
+ - pkg/google-rest-0.0.2/test/test_helper.rb
80
+ - script/console
81
+ - script/destroy
82
+ - script/generate
83
+ - test/test_google-rest.rb
84
+ - test/test_helper.rb
85
+ has_rdoc: true
86
+ homepage: http://daimpi.co.za
87
+ post_install_message: PostInstall.txt
88
+ rdoc_options:
89
+ - --main
90
+ - README.rdoc
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project: google-rest
108
+ rubygems_version: 1.2.0
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: A Simple Ruby wrapper for the Google REST API
112
+ test_files: []
113
+