lita-wikipedia 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72e591050c1024e2dc4b514a9187cd59e415d395
4
- data.tar.gz: f32aa2df972accca079eafeb969c2fa64783fe02
3
+ metadata.gz: 2d9cb26b2791815d29c0b9fef782392ae751e19a
4
+ data.tar.gz: e22d2d03d1092036ba43290daca935e8ea390bbd
5
5
  SHA512:
6
- metadata.gz: 680a12419842dc1c8a4bd83e69fa3da774c55365e25d11ca1996bf9e8c505dfac83d1ca154ef255e59ea9c31cd1b0806512c0b119a201fc3a4388194fd858320
7
- data.tar.gz: 23a9e12371f4726dcd18210a03ef7b48b22f6a463784abc345730576ae77390fb34e66bedb4fdd27e54a7465abea1f6511fa06b5f9a22863faa066620b5a6ec7
6
+ metadata.gz: 990e981768a235d23bbc3a65cd0a82577763982ff06f4977c5f89c2df61c9102fbee8f5147f63c612223d74dae8fff007bca00f02706e785ebe18c0a35580b85
7
+ data.tar.gz: 2325bd1cff15074b518a15da708db111a1b66f2cd5606e4363ef7c5bb914d44a54057a639dfa4d805fe7b916449027136cb4d2fdf6b086f142622a495aa69cd2
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Tristan Chong
1
+ Copyright (c) 2015 Tristan Chong
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # lita-wikipedia
2
2
 
3
+ [![Build Status](https://travis-ci.org/tristaneuan/lita-wikipedia.png?branch=master)](https://travis-ci.org/tristaneuan/lita-wikipedia)
4
+ [![Coverage Status](https://coveralls.io/repos/tristaneuan/lita-wikipedia/badge.png)](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
- Lita: wiki ruby language
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: http://en.wikipedia.org/wiki/Ruby_(programming_language)
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.first.first
14
- search_url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=#{term}&format=json"
15
- search_result = JSON.parse(open(URI.parse(URI.encode(search_url.strip))).read)
16
- titles = search_result[1]
17
- if titles.empty?
18
- response.reply("No Wikipedia entry found for '#{term}'")
19
- else
20
- query_url = "http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&format=json&exintro=&inprop=url&titles=#{titles.first}&redirects="
21
- query_result = JSON.parse(open(URI.parse(URI.encode(query_url.strip))).read)
22
- page = query_result['query']['pages'].first[1]
23
- html = Nokogiri::HTML(page['extract'])
24
- extract = Sanitize.fragment(html.xpath('//p[1]').first).strip
25
- url = page['fullurl']
26
- response.reply(extract)
27
- response.reply("Source: #{url}")
28
- end
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
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-wikipedia"
3
- spec.version = "0.0.4"
3
+ spec.version = "0.1.0"
4
4
  spec.authors = ["Tristan Chong"]
5
5
  spec.email = ["ong@tristaneuan.ch"]
6
- spec.description = %q{A Lita handler that returns a requested Wikipedia article.}
7
- spec.summary = %q{A Lita handler that returns a requested Wikipedia article.}
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 'Source: http://en.wikipedia.org/wiki/Ruby_(programming_language)'
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[1]).to match 'Source: http://en.wikipedia.org/wiki/Indio,_California'
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[0]).not_to include 'redirects here'
22
- expect(replies[1]).to match 'Source: http://en.wikipedia.org/wiki/Gabriola_Island'
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[0]).to match 'The phrase 12th Man or Twelfth Man can refer to:'
28
- expect(replies[1]).to match 'Source: http://en.wikipedia.org/wiki/12th_Man'
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
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-04-11 00:00:00.000000000 Z
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