lita-wikipedia 0.0.4 → 0.1.0
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/.coveralls.yml +1 -0
- data/LICENSE +1 -1
- data/README.md +6 -3
- data/lib/lita/handlers/wikipedia.rb +28 -18
- data/lita-wikipedia.gemspec +3 -3
- data/spec/lita/handlers/wikipedia_spec.rb +15 -6
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d9cb26b2791815d29c0b9fef782392ae751e19a
|
4
|
+
data.tar.gz: e22d2d03d1092036ba43290daca935e8ea390bbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 990e981768a235d23bbc3a65cd0a82577763982ff06f4977c5f89c2df61c9102fbee8f5147f63c612223d74dae8fff007bca00f02706e785ebe18c0a35580b85
|
7
|
+
data.tar.gz: 2325bd1cff15074b518a15da708db111a1b66f2cd5606e4363ef7c5bb914d44a54057a639dfa4d805fe7b916449027136cb4d2fdf6b086f142622a495aa69cd2
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# lita-wikipedia
|
2
2
|
|
3
|
+
[](https://travis-ci.org/tristaneuan/lita-wikipedia)
|
4
|
+
[](https://coveralls.io/r/tristaneuan/lita-wikipedia)
|
5
|
+
|
3
6
|
**lita-wikipedia** is a handler for [Lita](https://github.com/jimmycuadra/lita) that returns a requested Wikipedia article.
|
4
7
|
|
5
8
|
## Installation
|
@@ -15,9 +18,9 @@ gem "lita-wikipedia"
|
|
15
18
|
To request a Wikipedia article:
|
16
19
|
|
17
20
|
```
|
18
|
-
|
19
|
-
Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
|
20
|
-
Source:
|
21
|
+
<me> lita: wiki ruby language
|
22
|
+
<lita> Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
|
23
|
+
<lita> Source: https://en.wikipedia.org/wiki/Ruby_(programming_language)
|
21
24
|
```
|
22
25
|
|
23
26
|
## License
|
@@ -1,31 +1,41 @@
|
|
1
|
-
require "json"
|
2
1
|
require "nokogiri"
|
3
|
-
require "open-uri"
|
4
2
|
require "sanitize"
|
5
3
|
|
6
4
|
module Lita
|
7
5
|
module Handlers
|
8
6
|
class Wikipedia < Handler
|
7
|
+
|
8
|
+
API_URL = "https://en.wikipedia.org/w/api.php"
|
9
|
+
|
9
10
|
route(/^(?:wiki|wikipedia)\s+(.*)/i, :wikipedia, command: true,
|
10
11
|
help: { t("help.wikipedia_key") => t("help.wikipedia_value")})
|
11
12
|
|
12
13
|
def wikipedia(response)
|
13
|
-
term = response.matches
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
term = response.matches[0][0]
|
15
|
+
search = http.get(
|
16
|
+
API_URL,
|
17
|
+
search: term,
|
18
|
+
action: "opensearch",
|
19
|
+
format: "json"
|
20
|
+
)
|
21
|
+
titles = MultiJson.load(search.body)[1]
|
22
|
+
return response.reply("No Wikipedia entry found for '#{term}'") if titles.empty?
|
23
|
+
query = http.get(
|
24
|
+
API_URL,
|
25
|
+
titles: titles[0],
|
26
|
+
action: "query",
|
27
|
+
prop: "extracts|info",
|
28
|
+
exintro: nil,
|
29
|
+
inprop: "url",
|
30
|
+
redirects: nil,
|
31
|
+
format: "json"
|
32
|
+
)
|
33
|
+
page = MultiJson.load(query.body)["query"]["pages"].values[0]
|
34
|
+
html = Nokogiri::HTML(page["extract"])
|
35
|
+
extract = Sanitize.fragment(html.xpath("//p[1]")[0]).strip
|
36
|
+
url = page["fullurl"]
|
37
|
+
response.reply(extract)
|
38
|
+
response.reply("Source: #{url}")
|
29
39
|
end
|
30
40
|
|
31
41
|
end
|
data/lita-wikipedia.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-wikipedia"
|
3
|
-
spec.version = "0.0
|
3
|
+
spec.version = "0.1.0"
|
4
4
|
spec.authors = ["Tristan Chong"]
|
5
5
|
spec.email = ["ong@tristaneuan.ch"]
|
6
|
-
spec.description =
|
7
|
-
spec.summary =
|
6
|
+
spec.description = "A Lita handler that returns a requested Wikipedia article."
|
7
|
+
spec.summary = "A Lita handler that returns a requested Wikipedia article."
|
8
8
|
spec.homepage = "https://github.com/tristaneuan/lita-wikipedia"
|
9
9
|
spec.license = "MIT"
|
10
10
|
spec.metadata = { "lita_plugin_type" => "handler" }
|
@@ -1,36 +1,45 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lita::Handlers::Wikipedia, lita_handler: true do
|
4
|
+
|
4
5
|
it { is_expected.to route_command("wikipedia ruby language").to(:wikipedia) }
|
5
6
|
it { is_expected.to route_command("wiki ruby language").to(:wikipedia) }
|
6
7
|
|
7
8
|
describe "#wikipedia" do
|
9
|
+
|
8
10
|
it "returns the 1st paragraph & link to the Wikipedia entry for a query" do
|
9
11
|
send_command "wikipedia ruby language"
|
12
|
+
expect(replies.count).to eq 2
|
10
13
|
expect(replies[0]).to match 'Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.'
|
11
|
-
expect(replies[1]).to match
|
14
|
+
expect(replies[1]).to match "Source: https://en.wikipedia.org/wiki/Ruby_(programming_language)"
|
12
15
|
end
|
13
16
|
|
14
17
|
it "handles commas in queries correctly" do
|
15
18
|
send_command "wiki indio, ca"
|
16
|
-
expect(replies
|
19
|
+
expect(replies.count).to eq 2
|
20
|
+
expect(replies[1]).to match 'Source: https://en.wikipedia.org/wiki/Indio,_California'
|
17
21
|
end
|
18
22
|
|
19
23
|
it "handles lowercase queries and articles with templates correctly" do
|
20
24
|
send_command "wiki gabriola island"
|
21
|
-
expect(replies
|
22
|
-
expect(replies[
|
25
|
+
expect(replies.count).to eq 2
|
26
|
+
expect(replies[0]).not_to include "redirects here"
|
27
|
+
expect(replies[1]).to match "Source: https://en.wikipedia.org/wiki/Gabriola_Island"
|
23
28
|
end
|
24
29
|
|
25
30
|
it "responds with the disambiguation page on appropriate queries" do
|
26
31
|
send_command "wiki 12th man"
|
27
|
-
expect(replies
|
28
|
-
expect(replies[
|
32
|
+
expect(replies.count).to eq 2
|
33
|
+
expect(replies[0]).to match "The phrase 12th Man or Twelfth Man can refer to:"
|
34
|
+
expect(replies[1]).to match "Source: https://en.wikipedia.org/wiki/12th_Man"
|
29
35
|
end
|
30
36
|
|
31
37
|
it "returns an error message if no article is found" do
|
32
38
|
send_command "wiki asdfasdfa"
|
39
|
+
expect(replies.count).to eq 1
|
33
40
|
expect(replies.first).to match "No Wikipedia entry found for 'asdfasdfa'"
|
34
41
|
end
|
42
|
+
|
35
43
|
end
|
44
|
+
|
36
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-wikipedia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -129,6 +129,7 @@ executables: []
|
|
129
129
|
extensions: []
|
130
130
|
extra_rdoc_files: []
|
131
131
|
files:
|
132
|
+
- ".coveralls.yml"
|
132
133
|
- ".gitignore"
|
133
134
|
- ".travis.yml"
|
134
135
|
- Gemfile
|