googler 0.0.1
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/lib/googler.rb +59 -0
- metadata +46 -0
data/lib/googler.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
#API DOC https://developers.google.com/web-search/docs/
|
6
|
+
|
7
|
+
class Google
|
8
|
+
|
9
|
+
attr_accessor :api_key
|
10
|
+
|
11
|
+
ENDPOINT = "http://ajax.googleapis.com/ajax/services/search/web?gl=en"
|
12
|
+
|
13
|
+
# Create a new instance of Google with your Google api key
|
14
|
+
#
|
15
|
+
# Example:
|
16
|
+
#
|
17
|
+
# >> require 'googler'
|
18
|
+
# => true
|
19
|
+
# >> bing = Google.new('your-api-key')
|
20
|
+
# => #<Google:0x1af10 @api_key="your-api-key">
|
21
|
+
#
|
22
|
+
# Arguments:
|
23
|
+
#
|
24
|
+
# @param (String) api_key - you specify a key (Application ID) and such key will be used to authenticate the request.
|
25
|
+
def initialize(api_key)
|
26
|
+
@api_key = api_key
|
27
|
+
end
|
28
|
+
|
29
|
+
# Sending a request HTTP GET to the Endpoint.
|
30
|
+
#
|
31
|
+
# A request to the HTTP endpoint consists of a HTTP GET request to the approriate URI. There are two URLs, one for XML results and one for JSON results.
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# Example:
|
35
|
+
#
|
36
|
+
# >> google.search(query="MooTools")
|
37
|
+
# => Anatomy of a result set
|
38
|
+
# =>
|
39
|
+
# =>
|
40
|
+
# =>
|
41
|
+
|
42
|
+
# Arguments:
|
43
|
+
# @param (String) q - The query parameter is the textof the query you want the API to execute. example: query=mootools
|
44
|
+
# @param (String) sources - The sources parameter is one or more values indicating the SourceType or SourceTypes from which you want to request results.
|
45
|
+
# The "web" Source type returns a set of results from the WEB SourceType, "Image" searches for images on the WEB, "News" searches news stories
|
46
|
+
# @param (Hash) optional - page/offset
|
47
|
+
def search(q="",sources="",optional=nil)
|
48
|
+
|
49
|
+
params = {"hl"=>"en","v"=>1.0,"start"=>0, "rsz"=>8, "q"=>q}
|
50
|
+
|
51
|
+
params.merge!(optional) if optional
|
52
|
+
params = URI.encode_www_form( params )
|
53
|
+
|
54
|
+
url = URI("#{ENDPOINT}?Appid=#{api_key}&#{params}")
|
55
|
+
|
56
|
+
return JSON.parse(Net::HTTP.get(url))
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: googler
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adrian Statescu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A simple gem that provides a client to Google Web Search API ( https://developers.google.com/web-search/docs/
|
15
|
+
)
|
16
|
+
email: mergesortv@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/googler.rb
|
22
|
+
homepage: https://github.com/thinkphp/googler
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.24
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Bing!
|
46
|
+
test_files: []
|