lita-wikipedia 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/lita/handlers/wikipedia.rb +6 -1
- data/lita-wikipedia.gemspec +1 -1
- data/spec/lita/handlers/wikipedia_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40b8f40a3e943e471aecad7d9b0456a23f8ea769
|
4
|
+
data.tar.gz: bc09c63e6a5c07ad198289c638aafbfb2fa8cd1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 487aa8c98c6f40fc139f3b4bf5cfa9a3bf93dece4b6c0114c53e3e782809ce999f8cf0be008bd326848aedfaf5d28101a51bf3fb1ed3f27497be1d4b2fc6efaf
|
7
|
+
data.tar.gz: cac8d98a51381107bb6c17822144b4b117a5eac31591fd4a84c60cb9de437fb3ab1ac80cee93f0b856d4a29242da0164156ca98df6ed2a849a8ee312c1afba68
|
@@ -5,6 +5,9 @@ def disambiguate(term)
|
|
5
5
|
url = "http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info|links|pageprops&format=json&exintro=&explaintext=&inprop=url&ppprop=disambiguation&titles=#{term}&redirects="
|
6
6
|
result = JSON.parse(open(URI.parse(URI.encode(url.strip))).read)
|
7
7
|
page = result['query']['pages'].first[1]
|
8
|
+
if not page.has_key? 'extract'
|
9
|
+
return ["No Wikipedia entry found for '#{term}'.", nil]
|
10
|
+
end
|
8
11
|
extract = page['extract'].split("\n").first
|
9
12
|
if page.fetch('pageprops', {}).has_key? 'disambiguation'
|
10
13
|
links = page['links'].map {
|
@@ -25,7 +28,9 @@ module Lita
|
|
25
28
|
def wikipedia(response)
|
26
29
|
extract, url = disambiguate(response.matches.first.first)
|
27
30
|
response.reply(extract)
|
28
|
-
|
31
|
+
if url != nil
|
32
|
+
response.reply("Source: #{url}")
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
data/lita-wikipedia.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-wikipedia"
|
3
|
-
spec.version = "0.0.
|
3
|
+
spec.version = "0.0.3"
|
4
4
|
spec.authors = ["Tristan Chong"]
|
5
5
|
spec.email = ["ong@tristaneuan.ch"]
|
6
6
|
spec.description = %q{A Lita handler that returns a requested Wikipedia article.}
|
@@ -21,6 +21,11 @@ describe Lita::Handlers::Wikipedia, lita_handler: true do
|
|
21
21
|
]
|
22
22
|
expect(responses).to include(replies[1])
|
23
23
|
end
|
24
|
+
|
25
|
+
it "returns an error message if no article is found" do
|
26
|
+
send_command "wiki asdfasdfa"
|
27
|
+
expect(replies.first).to match "No Wikipedia entry found for 'asdfasdfa'."
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
describe "#disambiguate" do
|