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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d7a4b0b1a9e02e1cd16d926732544161225143c
4
- data.tar.gz: 7c58e5072db8990a2bbf1a992c6aa0747544a102
3
+ metadata.gz: 40b8f40a3e943e471aecad7d9b0456a23f8ea769
4
+ data.tar.gz: bc09c63e6a5c07ad198289c638aafbfb2fa8cd1b
5
5
  SHA512:
6
- metadata.gz: f193331786e2a15fdf77aa2a8a9c0ca4dd3555a5c14025d36d113514cb9122aa496460acab713109b7cbe0f7a28b9c8ea6624a9c8f76055fc356ca9da242ef55
7
- data.tar.gz: b3542a293b98b39fca8dd8fe6ce30b25ee0433739f4dc278064857e7ab3d20eb8221b31459af380bc0226b2a8abffca0663c096bc499ef422c037b3697a558db
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
- response.reply("Source: #{url}")
31
+ if url != nil
32
+ response.reply("Source: #{url}")
33
+ end
29
34
  end
30
35
  end
31
36
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-wikipedia"
3
- spec.version = "0.0.2"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-wikipedia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Chong