google-search 1.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/History.rdoc +8 -0
- data/Manifest +70 -0
- data/README.rdoc +95 -0
- data/Rakefile +16 -0
- data/examples/image.rb +21 -0
- data/examples/images.html +1 -0
- data/examples/web.rb +28 -0
- data/google-search.gemspec +33 -0
- data/lib/google-search.rb +29 -0
- data/lib/google-search/item.rb +10 -0
- data/lib/google-search/item/base.rb +78 -0
- data/lib/google-search/item/blog.rb +34 -0
- data/lib/google-search/item/book.rb +40 -0
- data/lib/google-search/item/image.rb +40 -0
- data/lib/google-search/item/local.rb +107 -0
- data/lib/google-search/item/news.rb +46 -0
- data/lib/google-search/item/patent.rb +40 -0
- data/lib/google-search/item/video.rb +46 -0
- data/lib/google-search/item/web.rb +22 -0
- data/lib/google-search/response.rb +92 -0
- data/lib/google-search/search.rb +11 -0
- data/lib/google-search/search/base.rb +212 -0
- data/lib/google-search/search/blog.rb +14 -0
- data/lib/google-search/search/book.rb +8 -0
- data/lib/google-search/search/image.rb +93 -0
- data/lib/google-search/search/local.rb +8 -0
- data/lib/google-search/search/mixins.rb +4 -0
- data/lib/google-search/search/mixins/filter.rb +26 -0
- data/lib/google-search/search/mixins/order_by.rb +36 -0
- data/lib/google-search/search/mixins/safety_level.rb +40 -0
- data/lib/google-search/search/news.rb +66 -0
- data/lib/google-search/search/patent.rb +37 -0
- data/lib/google-search/search/video.rb +15 -0
- data/lib/google-search/search/web.rb +15 -0
- data/lib/google-search/version.rb +6 -0
- data/spec/fixtures/400-response.json +1 -0
- data/spec/fixtures/blog-response.json +1 -0
- data/spec/fixtures/book-response.json +1 -0
- data/spec/fixtures/image-response.json +1 -0
- data/spec/fixtures/invalid-response.json +1 -0
- data/spec/fixtures/local-response.json +1 -0
- data/spec/fixtures/news-response.json +1 -0
- data/spec/fixtures/patent-response.json +1 -0
- data/spec/fixtures/video-response.json +1 -0
- data/spec/fixtures/web-2-response.json +1 -0
- data/spec/fixtures/web-response.json +1 -0
- data/spec/item_blog_spec.rb +26 -0
- data/spec/item_book_spec.rb +18 -0
- data/spec/item_image_spec.rb +21 -0
- data/spec/item_local_spec.rb +30 -0
- data/spec/item_news_spec.rb +19 -0
- data/spec/item_patent_spec.rb +19 -0
- data/spec/item_spec.rb +10 -0
- data/spec/item_video_spec.rb +20 -0
- data/spec/item_web_spec.rb +18 -0
- data/spec/response_spec.rb +63 -0
- data/spec/search_blog_spec.rb +0 -0
- data/spec/search_book_spec.rb +0 -0
- data/spec/search_image_spec.rb +71 -0
- data/spec/search_local_spec.rb +0 -0
- data/spec/search_news_spec.rb +33 -0
- data/spec/search_patent_spec.rb +27 -0
- data/spec/search_spec.rb +89 -0
- data/spec/search_video_spec.rb +42 -0
- data/spec/search_web_spec.rb +42 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +13 -0
- data/tasks/docs.rake +18 -0
- data/tasks/gemspec.rake +3 -0
- data/tasks/spec.rake +25 -0
- metadata +168 -0
data/History.rdoc
ADDED
data/Manifest
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
examples/image.rb
|
2
|
+
examples/images.html
|
3
|
+
examples/web.rb
|
4
|
+
google-search.gemspec
|
5
|
+
History.rdoc
|
6
|
+
lib/google-search/item/base.rb
|
7
|
+
lib/google-search/item/blog.rb
|
8
|
+
lib/google-search/item/book.rb
|
9
|
+
lib/google-search/item/image.rb
|
10
|
+
lib/google-search/item/local.rb
|
11
|
+
lib/google-search/item/news.rb
|
12
|
+
lib/google-search/item/patent.rb
|
13
|
+
lib/google-search/item/video.rb
|
14
|
+
lib/google-search/item/web.rb
|
15
|
+
lib/google-search/item.rb
|
16
|
+
lib/google-search/response.rb
|
17
|
+
lib/google-search/search/base.rb
|
18
|
+
lib/google-search/search/blog.rb
|
19
|
+
lib/google-search/search/book.rb
|
20
|
+
lib/google-search/search/image.rb
|
21
|
+
lib/google-search/search/local.rb
|
22
|
+
lib/google-search/search/mixins/filter.rb
|
23
|
+
lib/google-search/search/mixins/order_by.rb
|
24
|
+
lib/google-search/search/mixins/safety_level.rb
|
25
|
+
lib/google-search/search/mixins.rb
|
26
|
+
lib/google-search/search/news.rb
|
27
|
+
lib/google-search/search/patent.rb
|
28
|
+
lib/google-search/search/video.rb
|
29
|
+
lib/google-search/search/web.rb
|
30
|
+
lib/google-search/search.rb
|
31
|
+
lib/google-search/version.rb
|
32
|
+
lib/google-search.rb
|
33
|
+
Manifest
|
34
|
+
Rakefile
|
35
|
+
README.rdoc
|
36
|
+
spec/fixtures/400-response.json
|
37
|
+
spec/fixtures/blog-response.json
|
38
|
+
spec/fixtures/book-response.json
|
39
|
+
spec/fixtures/image-response.json
|
40
|
+
spec/fixtures/invalid-response.json
|
41
|
+
spec/fixtures/local-response.json
|
42
|
+
spec/fixtures/news-response.json
|
43
|
+
spec/fixtures/patent-response.json
|
44
|
+
spec/fixtures/video-response.json
|
45
|
+
spec/fixtures/web-2-response.json
|
46
|
+
spec/fixtures/web-response.json
|
47
|
+
spec/item_blog_spec.rb
|
48
|
+
spec/item_book_spec.rb
|
49
|
+
spec/item_image_spec.rb
|
50
|
+
spec/item_local_spec.rb
|
51
|
+
spec/item_news_spec.rb
|
52
|
+
spec/item_patent_spec.rb
|
53
|
+
spec/item_spec.rb
|
54
|
+
spec/item_video_spec.rb
|
55
|
+
spec/item_web_spec.rb
|
56
|
+
spec/response_spec.rb
|
57
|
+
spec/search_blog_spec.rb
|
58
|
+
spec/search_book_spec.rb
|
59
|
+
spec/search_image_spec.rb
|
60
|
+
spec/search_local_spec.rb
|
61
|
+
spec/search_news_spec.rb
|
62
|
+
spec/search_patent_spec.rb
|
63
|
+
spec/search_spec.rb
|
64
|
+
spec/search_video_spec.rb
|
65
|
+
spec/search_web_spec.rb
|
66
|
+
spec/spec.opts
|
67
|
+
spec/spec_helper.rb
|
68
|
+
tasks/docs.rake
|
69
|
+
tasks/gemspec.rake
|
70
|
+
tasks/spec.rake
|
data/README.rdoc
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
= Google Search
|
3
|
+
|
4
|
+
Fast, feature rich Google Search client. Search web results, images,
|
5
|
+
books, local, patents, blogs and news using an elegant Ruby API with
|
6
|
+
only a single dependency.
|
7
|
+
|
8
|
+
== Dependencies
|
9
|
+
|
10
|
+
* json gem
|
11
|
+
|
12
|
+
== Features
|
13
|
+
|
14
|
+
* Fast
|
15
|
+
* Lazy Enumeration (requests more results from google, not all at once)
|
16
|
+
* Populates Google::Search::Item's blog, book, image, local, news, patent, video, and web
|
17
|
+
* Clean, well documented source code
|
18
|
+
* Full test coverage
|
19
|
+
|
20
|
+
== Classes
|
21
|
+
|
22
|
+
- Google::Search | superclass of all other search classes. Is Enumerable
|
23
|
+
- Google::Search::Web | web search.
|
24
|
+
- Google::Search::Blog | blog search.
|
25
|
+
- Google::Search::Book | book search.
|
26
|
+
- Google::Search::Image | image search.
|
27
|
+
- Google::Search::Local | local search.
|
28
|
+
- Google::Search::News | news search.
|
29
|
+
- Google::Search::Patent | patent search.
|
30
|
+
- Google::Search::Video | video search.
|
31
|
+
- Google::Search::Response | single request response, containing items. Is Enumerable
|
32
|
+
- Google::Search::Item | single item, superclass of all other items.
|
33
|
+
- Google::Search::Item::Web | single item containing web specific data.
|
34
|
+
- Google::Search::Item::Blog | single item containing blog specific data.
|
35
|
+
- Google::Search::Item::Book | single item containing book specific data.
|
36
|
+
- Google::Search::Item::Image | single item containing image specific data.
|
37
|
+
- Google::Search::Item::Local | single item containing local specific data.
|
38
|
+
- Google::Search::Item::News | single item containing news specific data.
|
39
|
+
- Google::Search::Item::Patent | single item containing patent specific data.
|
40
|
+
- Google::Search::Item::Video | single item containing video specific data.
|
41
|
+
|
42
|
+
== Arbitrary Query String Support
|
43
|
+
|
44
|
+
Arbitrary key / value pairs may be passed to Google::Search.new, all options
|
45
|
+
passed that are not assigned (deleted) will pass on to be part of the query string.
|
46
|
+
|
47
|
+
For argument reference visit: http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_web
|
48
|
+
|
49
|
+
== Items
|
50
|
+
|
51
|
+
Each item type (web, image, etc) is a subclass of Google::Search::Item,
|
52
|
+
whose constant is Google::Search::Item::{Web, Image, Blog, etc}. Every aspect
|
53
|
+
of google-search is well documented, so poke around to learn more or view
|
54
|
+
spec/item_spec.rb for item attributes.
|
55
|
+
|
56
|
+
== Image example
|
57
|
+
|
58
|
+
Below we simply create a new :image search, and pass a :query string.
|
59
|
+
Query strings are urlencoded when Search#get_uri is called, so there
|
60
|
+
is no reason to do so manually.
|
61
|
+
|
62
|
+
File.open('path/to/images.html', 'w+') do |file|
|
63
|
+
Google::Search::Image.new(:query => 'Cookies').each do |image|
|
64
|
+
file.write %(<img src="#{image.uri}">)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
== More Information
|
69
|
+
|
70
|
+
* View the source :)
|
71
|
+
|
72
|
+
== License:
|
73
|
+
|
74
|
+
(The MIT License)
|
75
|
+
|
76
|
+
Copyright (c) 2009 TJ Holowaychuk <tj@vision-media.ca>
|
77
|
+
|
78
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
79
|
+
a copy of this software and associated documentation files (the
|
80
|
+
'Software'), to deal in the Software without restriction, including
|
81
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
82
|
+
distribute, sublicense, an d/or sell copies of the Software, and to
|
83
|
+
permit persons to whom the Software is furnished to do so, subject to
|
84
|
+
the following conditions:
|
85
|
+
|
86
|
+
The above copyright notice and this permission notice shall be
|
87
|
+
included in all copies or substantial portions of the Software.
|
88
|
+
|
89
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
90
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
91
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
92
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
93
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
94
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
95
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
$:.unshift 'lib'
|
3
|
+
require 'google-search'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'rake'
|
6
|
+
require 'echoe'
|
7
|
+
|
8
|
+
Echoe.new "google-search", Google::Search::VERSION do |p|
|
9
|
+
p.author = "TJ Holowaychuk"
|
10
|
+
p.email = "tj@vision-media.ca"
|
11
|
+
p.summary = "Google Search API"
|
12
|
+
p.url = "http://github.com/visionmedia/google-search"
|
13
|
+
p.runtime_dependencies << 'json'
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir['tasks/**/*.rake'].sort.each { |f| load f }
|
data/examples/image.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'google-search'
|
5
|
+
require 'rext/all'
|
6
|
+
|
7
|
+
HTML = File.dirname(__FILE__) + '/images.html'
|
8
|
+
|
9
|
+
File.open(HTML, 'w+') do |file|
|
10
|
+
Google::Search::Image.new(:query => 'Cookies', :image_size => :icon).each do |image|
|
11
|
+
file.write %(<img src="#{image.uri}">)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
begin
|
16
|
+
`open -a Safari #{HTML}`
|
17
|
+
rescue
|
18
|
+
puts "Not on OSX? wtf? open #{HTML} in your browser to view the images"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
<img src="http://i222.photobucket.com/albums/dd203/I_never_said_I_lie_and_wait_4ever/lmao.gif"><img src="http://www.kde-look.org/CONTENT/user-pics/0/cookies.gif"><img src="http://games2flash.net/files/image/cookiesJS1.gif"><img src="http://www.learnairbrush.com/forums/images/commerce/items/cookies-48x48.png"><img src="http://www.bigmoneyarcade.com/games/images/cooking-cookies-game.gif"><img src="http://icons.iconarchive.com/icons/fasticon/coffee-break/cookies-icon.jpg"><img src="http://i257.photobucket.com/albums/hh236/h3llokitty2/ICONATOR_1e3e3e686ed961a0b9009d3c3e.gif"><img src="http://farm4.static.flickr.com/3069/buddyicons/29481597%40N08.jpg"><img src="http://1.gravatar.com/avatar/1df546cd37482d661c0a10d36ad83af5%3Fs%3D48%26d%3Didenticon%26r%3DG"><img src="http://www.arcadeonline.com/games/other/cooking-cookies/cooking1.gif"><img src="http://blueberry.ipaula.com/affiliates/cookies.gif"><img src="http://farm1.static.flickr.com/73/buddyicons/26768826%40N00.jpg"><img src="http://www.adiumxtras.com/images/thumbs/cookies_7_3204_2847_thumb.png"><img src="http://www.educationcanada.com/images/cookies.gif"><img src="http://z.hubpages.com/u/10745_50.jpg"><img src="http://www.wowcoolstuff.com/v/vspfiles/photos/Fortune-cookies-0.jpg"><img src="http://z.hubpages.com/u/11745_50.jpg"><img src="http://profile.ak.facebook.com/object2/609/0/q8611607717_7269.jpg"><img src="http://images.allrecipes.com/site/allrecipes/holidays/easter09/cutest_cookies.jpg"><img src="http://www.pendletonsoccer.org/pysa/modules/Your_Account/images/warning.gif"><img src="http://ocanada.com.au/shop/media/catalog/product/cache/1/thumbnail/50x/5e06319eda06f020e43594a9c230972d/O/h/OhHenryCookies218g_Lge.gif"><img src="http://farm4.static.flickr.com/3044/buddyicons/31781247%40N03.jpg"><img src="http://home.nordnet.fr/~pmdevigne/Images/CookiesManager/cm48x48.gif"><img src="http://www.epicurious.com/images/articlesguides/howtocook/dishes/cookies_46.jpg"><img src="http://musicremedy.com/webfiles/artists/CasperandtheCookies/CasperandtheCookies-06-small.jpg"><img src="http://www.monkeydoit.com/content_images/icon-cookies.gif"><img src="http://img.alibaba.com/photo/233843288/Pastry_Homemade_Cookies_Mixed_12_OZ.summ.jpg"><img src="http://www.somethingmorestore.com/Images/BeanPod/OatMlCkies.jpg"><img src="http://z.hubpages.com/u/94731_50.jpg"><img src="http://images.meredith.com/bhg/images/ecards/50sq_ecardCmasCookies100176327.jpg"><img src="http://filesll.fluxstatic.com/FFFFD99501A67167000295D9FFFF/TN1/Jpg/B-9835/AR50x50,Crop/633696919200000000"><img src="http://farm2.static.flickr.com/1155/buddyicons/8292289%40N08.jpg"><img src="http://ocanada.com.au/shop/media/catalog/product/cache/1/thumbnail/50x/5e06319eda06f020e43594a9c230972d/M/a/Maplecream_Cookies.jpg"><img src="http://www.traderscity.com/board/userpixthumbs6/5280-entertainment-fortune-cookies-1.jpg"><img src="http://www.traderscity.com/board/userpixthumbs6/5280-birthday-fortune-cookies-1.jpg"><img src="http://www.avonandsomerset.police.uk/community_safety/internet_advice/images/cookies_pli.jpg"><img src="http://www.source-promotional-products.co.uk/images/adv_50.gif"><img src="http://img.afullcup.com/assets/images/coupondb/chips-cookies-crackers.png"><img src="http://www.calebseyes.com/_wizardimages/Cookies.gif"><img src="http://ecx.images-amazon.com/images/I/51RZQE-D1pL._SL75_PIsitb-sticker-arrow-st,TopRight,8,-14_OU02_SS50_.jpg"><img src="http://ecx.images-amazon.com/images/I/51OehUjVyuL._SL75_PIsitb-sticker-arrow-st,TopRight,8,-14_OU01_SS50_.jpg"><img src="http://farm1.static.flickr.com/139/buddyicons/23514648%40N00.jpg"><img src="http://ocanada.com.au/shop/media/catalog/product/cache/1/thumbnail/50x/5e06319eda06f020e43594a9c230972d/R/e/ReeseCookies198g_Lge.gif"><img src="http://www.madame-chocolat.com/media/catalog/product/cache/1/thumbnail/50x/5e06319eda06f020e43594a9c230972d/c/h/chocolate_chip_cookies.jpg"><img src="http://www.traderscity.com/board/userpixthumbs6/5280-love-fortune-cookies-1.jpg"><img src="http://popcdn.zoovy.lg1.simplecdn.net/img/orangeonions/W50-H50-Bffffff/C/chocolate_chip_cookies.jpg"><img src="http://my.opera.com/community/users/avatar.pl/1587122"><img src="http://www.snackordie.com/2008/12/22/ffblackmagecookieicon.jpg"><img src="http://www.snackordie.com/2009/02/02/bubblebobblecookieicon.jpg"><img src="http://my.opera.com/community/users/avatar.pl/1492038"><img src="http://ecx.images-amazon.com/images/I/51zObsVkTSL._SL75_PIsitb-sticker-arrow-st,TopRight,8,-14_OU02_SS50_.jpg"><img src="http://farm1.static.flickr.com/52/buddyicons/88876166%40N00.jpg"><img src="http://www.peanutfreeplanet.com/v/vspfiles/photos/HomeFreeOatmealCookies-0.gif"><img src="http://www.instructables.com/files/deriv/F9P/HL0V/C8LEWH1IWZM/F9PHL0VC8LEWH1IWZM.TINY.jpg"><img src="http://www.peanutfreeplanet.com/v/vspfiles/photos/HomeFreeOrganicCChipCookies-0.gif"><img src="http://img.amazon.ca/images/I/51LKzjFp7WL._SL75_PIsitb-sticker-arrow-st,TopRight,8,-14_OU15_SS50_.jpg"><img src="http://cdn.cloudfiles.mosso.com/c28492/321251-1243940713.gif"><img src="http://www.iconarchive.com/icons/fasticon/coffee-break/cookies-48x48.png"><img src="http://brh.numbera.com/experiments/images/icons/pixel-cookies-48.jpg"><img src="http://www.rjjulia.com/media/catalog/product/cache/1/thumbnail//50x/c/o/cookies.jpg"><img src="http://www.kevinmccaughey.com/wp-content/uploads/fortune-cookie.jpg"><img src="http://farm1.static.flickr.com/232/buddyicons/8207661%40N06.jpg"><img src="http://www.softlist.net/images/icons/expired_cookies_cleaner_network___internet_browser_tools-8179.gif"><img src="http://forums.superantispyware.com/download/file.php%3Favatar%3D3913_1235515286.jpg">
|
data/examples/web.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'google-search'
|
5
|
+
|
6
|
+
def find_item uri, query
|
7
|
+
search = Google::Search::Web.new do |search|
|
8
|
+
search.query = query
|
9
|
+
search.size = :large
|
10
|
+
search.each_response { print '.'; $stdout.flush }
|
11
|
+
end
|
12
|
+
search.find { |item| item.uri =~ uri }
|
13
|
+
end
|
14
|
+
|
15
|
+
def rank_for query
|
16
|
+
print "%35s " % query
|
17
|
+
if item = find_item(/vision\-media\.ca/, query)
|
18
|
+
puts " #%d" % (item.index + 1)
|
19
|
+
else
|
20
|
+
puts " Not found"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
rank_for 'Victoria Web Training'
|
25
|
+
rank_for 'Victoria Web School'
|
26
|
+
rank_for 'Victoria Web Design'
|
27
|
+
rank_for 'Victoria Drupal'
|
28
|
+
rank_for 'Victoria Drupal Development'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{google-search}
|
5
|
+
s.version = "1.0.2"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["TJ Holowaychuk"]
|
9
|
+
s.date = %q{2009-07-30}
|
10
|
+
s.description = %q{Google Search API}
|
11
|
+
s.email = %q{tj@vision-media.ca}
|
12
|
+
s.extra_rdoc_files = ["lib/google-search/item/base.rb", "lib/google-search/item/blog.rb", "lib/google-search/item/book.rb", "lib/google-search/item/image.rb", "lib/google-search/item/local.rb", "lib/google-search/item/news.rb", "lib/google-search/item/patent.rb", "lib/google-search/item/video.rb", "lib/google-search/item/web.rb", "lib/google-search/item.rb", "lib/google-search/response.rb", "lib/google-search/search/base.rb", "lib/google-search/search/blog.rb", "lib/google-search/search/book.rb", "lib/google-search/search/image.rb", "lib/google-search/search/local.rb", "lib/google-search/search/mixins/filter.rb", "lib/google-search/search/mixins/order_by.rb", "lib/google-search/search/mixins/safety_level.rb", "lib/google-search/search/mixins.rb", "lib/google-search/search/news.rb", "lib/google-search/search/patent.rb", "lib/google-search/search/video.rb", "lib/google-search/search/web.rb", "lib/google-search/search.rb", "lib/google-search/version.rb", "lib/google-search.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["examples/image.rb", "examples/images.html", "examples/web.rb", "google-search.gemspec", "History.rdoc", "lib/google-search/item/base.rb", "lib/google-search/item/blog.rb", "lib/google-search/item/book.rb", "lib/google-search/item/image.rb", "lib/google-search/item/local.rb", "lib/google-search/item/news.rb", "lib/google-search/item/patent.rb", "lib/google-search/item/video.rb", "lib/google-search/item/web.rb", "lib/google-search/item.rb", "lib/google-search/response.rb", "lib/google-search/search/base.rb", "lib/google-search/search/blog.rb", "lib/google-search/search/book.rb", "lib/google-search/search/image.rb", "lib/google-search/search/local.rb", "lib/google-search/search/mixins/filter.rb", "lib/google-search/search/mixins/order_by.rb", "lib/google-search/search/mixins/safety_level.rb", "lib/google-search/search/mixins.rb", "lib/google-search/search/news.rb", "lib/google-search/search/patent.rb", "lib/google-search/search/video.rb", "lib/google-search/search/web.rb", "lib/google-search/search.rb", "lib/google-search/version.rb", "lib/google-search.rb", "Manifest", "Rakefile", "README.rdoc", "spec/fixtures/400-response.json", "spec/fixtures/blog-response.json", "spec/fixtures/book-response.json", "spec/fixtures/image-response.json", "spec/fixtures/invalid-response.json", "spec/fixtures/local-response.json", "spec/fixtures/news-response.json", "spec/fixtures/patent-response.json", "spec/fixtures/video-response.json", "spec/fixtures/web-2-response.json", "spec/fixtures/web-response.json", "spec/item_blog_spec.rb", "spec/item_book_spec.rb", "spec/item_image_spec.rb", "spec/item_local_spec.rb", "spec/item_news_spec.rb", "spec/item_patent_spec.rb", "spec/item_spec.rb", "spec/item_video_spec.rb", "spec/item_web_spec.rb", "spec/response_spec.rb", "spec/search_blog_spec.rb", "spec/search_book_spec.rb", "spec/search_image_spec.rb", "spec/search_local_spec.rb", "spec/search_news_spec.rb", "spec/search_patent_spec.rb", "spec/search_spec.rb", "spec/search_video_spec.rb", "spec/search_web_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
14
|
+
s.homepage = %q{http://github.com/visionmedia/google-search}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Google-search", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{google-search}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Google Search API}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<json>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<json>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2009 2009 TJ Holowaychuk <tj@vision-media.ca>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require 'json'
|
25
|
+
require 'open-uri'
|
26
|
+
require 'google-search/version'
|
27
|
+
require 'google-search/item'
|
28
|
+
require 'google-search/response'
|
29
|
+
require 'google-search/search'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
require 'google-search/item/base'
|
3
|
+
require 'google-search/item/web'
|
4
|
+
require 'google-search/item/blog'
|
5
|
+
require 'google-search/item/book'
|
6
|
+
require 'google-search/item/image'
|
7
|
+
require 'google-search/item/local'
|
8
|
+
require 'google-search/item/news'
|
9
|
+
require 'google-search/item/video'
|
10
|
+
require 'google-search/item/patent'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
module Google
|
3
|
+
class Search
|
4
|
+
class Item
|
5
|
+
|
6
|
+
##
|
7
|
+
# Index.
|
8
|
+
|
9
|
+
attr_reader :index
|
10
|
+
|
11
|
+
##
|
12
|
+
# Unformatted page title.
|
13
|
+
|
14
|
+
attr_reader :title
|
15
|
+
|
16
|
+
##
|
17
|
+
# Absolute uri.
|
18
|
+
|
19
|
+
attr_reader :uri
|
20
|
+
|
21
|
+
##
|
22
|
+
# Visible uri.
|
23
|
+
|
24
|
+
attr_reader :visible_uri
|
25
|
+
|
26
|
+
##
|
27
|
+
# Thumbnail uri.
|
28
|
+
|
29
|
+
attr_reader :thumbnail_uri
|
30
|
+
|
31
|
+
##
|
32
|
+
# Thumbnail width in pixels.
|
33
|
+
|
34
|
+
attr_reader :thumbnail_width
|
35
|
+
|
36
|
+
##
|
37
|
+
# Thumbnail height in pixels.
|
38
|
+
|
39
|
+
attr_reader :thumbnail_height
|
40
|
+
|
41
|
+
##
|
42
|
+
# Contents.
|
43
|
+
|
44
|
+
attr_reader :content
|
45
|
+
|
46
|
+
##
|
47
|
+
# Initialize with _hash_.
|
48
|
+
|
49
|
+
def initialize hash
|
50
|
+
@index = hash['index']
|
51
|
+
@title = hash['titleNoFormatting'] || hash['title']
|
52
|
+
@uri = hash['unescapedUrl'] || hash['url'] || hash['postUrl']
|
53
|
+
@content = hash['contentNoFormatting'] || hash['content']
|
54
|
+
@thumbnail_uri = hash['tbUrl']
|
55
|
+
@thumbnail_width = hash['tbWidth'].to_i
|
56
|
+
@thumbnail_height = hash['tbHeight'].to_i
|
57
|
+
@visible_uri = hash['visibleUrl']
|
58
|
+
end
|
59
|
+
|
60
|
+
##
|
61
|
+
# Return class for _google_class_ string formatted
|
62
|
+
# as 'GwebSearch', 'GbookSearch', etc.
|
63
|
+
|
64
|
+
def self.class_for google_class
|
65
|
+
case google_class
|
66
|
+
when 'GwebSearch' ; Web
|
67
|
+
when 'GlocalSearch' ; Local
|
68
|
+
when 'GbookSearch' ; Book
|
69
|
+
when 'GimageSearch' ; Image
|
70
|
+
when 'GvideoSearch' ; Video
|
71
|
+
when 'GpatentSearch' ; Patent
|
72
|
+
when 'GnewsSearch' ; News
|
73
|
+
when 'GblogSearch' ; Blog
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module Google
|
3
|
+
class Search
|
4
|
+
class Item
|
5
|
+
class Blog < self
|
6
|
+
|
7
|
+
##
|
8
|
+
# Blog base uri.
|
9
|
+
|
10
|
+
attr_reader :blog_uri
|
11
|
+
|
12
|
+
##
|
13
|
+
# Author name.
|
14
|
+
|
15
|
+
attr_reader :author
|
16
|
+
|
17
|
+
##
|
18
|
+
# Published DateTime.
|
19
|
+
|
20
|
+
attr_reader :published
|
21
|
+
|
22
|
+
##
|
23
|
+
# Initialize with _hash_.
|
24
|
+
|
25
|
+
def initialize hash
|
26
|
+
super
|
27
|
+
@author = hash['author']
|
28
|
+
@blog_uri = hash['blogUrl']
|
29
|
+
@published = DateTime.parse hash['publishedDate']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
module Google
|
3
|
+
class Search
|
4
|
+
class Item
|
5
|
+
class Book < self
|
6
|
+
|
7
|
+
##
|
8
|
+
# Book id.
|
9
|
+
|
10
|
+
attr_reader :id
|
11
|
+
|
12
|
+
##
|
13
|
+
# Author name(s).
|
14
|
+
|
15
|
+
attr_reader :author
|
16
|
+
|
17
|
+
##
|
18
|
+
# Published year.
|
19
|
+
|
20
|
+
attr_reader :published_year
|
21
|
+
|
22
|
+
##
|
23
|
+
# Page count.
|
24
|
+
|
25
|
+
attr_reader :pages
|
26
|
+
|
27
|
+
##
|
28
|
+
# Initialize with _hash_.
|
29
|
+
|
30
|
+
def initialize hash
|
31
|
+
super
|
32
|
+
@author = hash['authors']
|
33
|
+
@published_year = hash['publishedYear'].to_i
|
34
|
+
@id = hash['bookId']
|
35
|
+
@pages = hash['pageCount'].to_i
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|