duck-duck-go 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +3 -0
- data/Rakefile +34 -1
- data/VERSION +1 -1
- data/duck-duck-go.gemspec +2 -2
- data/lib/duck_duck_go.rb +10 -2
- data/test/tc_live.rb +17 -0
- metadata +3 -3
data/CHANGES
CHANGED
data/Rakefile
CHANGED
@@ -20,7 +20,6 @@ begin
|
|
20
20
|
gem.authors = ["andrewrjones"]
|
21
21
|
gem.add_dependency('httpclient')
|
22
22
|
gem.add_dependency('json')
|
23
|
-
gem.files.exclude 'scripts'
|
24
23
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
25
24
|
end
|
26
25
|
Jeweler::GemcutterTasks.new
|
@@ -52,3 +51,37 @@ Rake::RDocTask.new do |rdoc|
|
|
52
51
|
rdoc.rdoc_files.include('LICENSE')
|
53
52
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
53
|
end
|
54
|
+
|
55
|
+
# dumps out the result of the query, in JSON and Ruby
|
56
|
+
# used during development
|
57
|
+
task :search_dump do
|
58
|
+
require 'rubygems'
|
59
|
+
require 'httpclient'
|
60
|
+
require 'json'
|
61
|
+
require 'pp'
|
62
|
+
|
63
|
+
unless ENV.include?("query")
|
64
|
+
raise "usage: rake search_dump query=___"
|
65
|
+
end
|
66
|
+
|
67
|
+
args = {
|
68
|
+
'q' => ENV['query'],
|
69
|
+
'o' => 'json'
|
70
|
+
}
|
71
|
+
if ENV.include?("skip_disambiguation")
|
72
|
+
args['d'] = 1
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
http = HTTPClient.new
|
77
|
+
json = http.get_content('http://api.duckduckgo.com/', args)
|
78
|
+
ruby = JSON.parse(json)
|
79
|
+
|
80
|
+
puts 'JSON'
|
81
|
+
puts '----'
|
82
|
+
puts json
|
83
|
+
puts
|
84
|
+
puts 'Ruby'
|
85
|
+
puts '----'
|
86
|
+
pp ruby
|
87
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/duck-duck-go.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{duck-duck-go}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["andrewrjones"]
|
12
|
-
s.date = %q{2011-04-
|
12
|
+
s.date = %q{2011-04-13}
|
13
13
|
s.description = %q{A Ruby library to access the DuckDuckGo Zero Click Info API.}
|
14
14
|
s.email = %q{andrew@arjones.co.uk}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/duck_duck_go.rb
CHANGED
@@ -33,8 +33,16 @@ module DuckDuckGo
|
|
33
33
|
|
34
34
|
# Run a query against Duck Duck Go
|
35
35
|
# Returns an instance of DuckDuckGo::ZeroClickInfo
|
36
|
-
def zeroclickinfo(query)
|
37
|
-
|
36
|
+
def zeroclickinfo(query, skip_disambiguation = false)
|
37
|
+
args = {
|
38
|
+
'q' => query,
|
39
|
+
'o' => 'json'
|
40
|
+
}
|
41
|
+
if(skip_disambiguation)
|
42
|
+
args['d'] = 1
|
43
|
+
end
|
44
|
+
|
45
|
+
data = @http.get_content(@url, args)
|
38
46
|
|
39
47
|
# parse the JSON and return an instance
|
40
48
|
# of the ZeroClickInfo class
|
data/test/tc_live.rb
CHANGED
@@ -30,6 +30,23 @@ class TestLive < Test::Unit::TestCase
|
|
30
30
|
assert_equal("A", zci.type)
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_skip_disambiguation
|
34
|
+
ddg = DuckDuckGo.new(nil, true)
|
35
|
+
zci = ddg.zci('Bill Gates')
|
36
|
+
|
37
|
+
assert_instance_of(DuckDuckGo::ZeroClickInfo, zci)
|
38
|
+
assert_equal("D", zci.type)
|
39
|
+
|
40
|
+
sleep(5)
|
41
|
+
|
42
|
+
zci = ddg.zci('Bill Gates', true)
|
43
|
+
|
44
|
+
assert_instance_of(DuckDuckGo::ZeroClickInfo, zci)
|
45
|
+
assert_equal("Bill Gates", zci.heading)
|
46
|
+
assert_equal("Wikipedia", zci.abstract_source)
|
47
|
+
assert_equal("A", zci.type)
|
48
|
+
end
|
49
|
+
|
33
50
|
# questions do not currently get a response on the api
|
34
51
|
def test_answer
|
35
52
|
ddg = DuckDuckGo.new
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.2
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- andrewrjones
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|