lita-howdoi 0.0.1 → 0.0.2

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: f0535a6257ca2a07da4a8c5cf0a74275fb1c1cee
4
- data.tar.gz: a3777d785c4e8a2331698973d098cbeb8fd2eb0b
3
+ metadata.gz: c56116b7c526963d01fc92219714341484088e75
4
+ data.tar.gz: 0fd161f94ddc87c3b2e371682924b3cd50a07990
5
5
  SHA512:
6
- metadata.gz: 6d7e0ae3270e9435c110195a124b9f09520077f4605f04d5e947cd60ecdba05f4e2ce01ceb59b2f556e93706cc1cbac3194e84de1a8ff4be84b3ba5cd2d241d8
7
- data.tar.gz: aaf2482961147295fb74be388d914f434f5312b2a63232e15b99b6427cbfb430a9d94e1e5dcf7dd32f75ad4175b544442c16c74451b8eab378c3bc585d3a74a0
6
+ metadata.gz: fec1243b2181645292bc9a453e7fe80783b1369b4107277804f0a438e09ec22251576f90a249ff215b42689158711d0bef7c5ea08df596dea7f329a124eb32cf
7
+ data.tar.gz: 6dfd96b880d6137c127c0b353d384b3806f768e7cf360e3d6a5dce023b44225367a31d0b2f453d2b49c1e4ce536dfeea85f12d51703138149cef90a02afd8eae
@@ -3,14 +3,14 @@ require 'nokogiri'
3
3
  module Lita
4
4
  module Handlers
5
5
  class Howdoi < Handler
6
- GOOGLE_SEARCH_URL = "http://www.google.com/search?q=site:stackoverflow.com+"
6
+ GOOGLE_SEARCH_URL = "http://stackoverflow.com/search"
7
7
 
8
8
  route(/^howdoi (.*)$/, :howdoi, command: true, help: {
9
9
  "howdoi QUERY" => "Searches Stack Overflow for the first answer it finds with a solution to QUERY.",
10
10
  })
11
11
 
12
- def get_url(url)
13
- http.get(url).body
12
+ def get_url(url, q="")
13
+ http.get(url, q: q).body
14
14
  end
15
15
 
16
16
  def is_question?(stackoverflow_url)
@@ -18,11 +18,11 @@ module Lita
18
18
  end
19
19
 
20
20
  def get_google_links(args)
21
- page = get_url(URI.escape(GOOGLE_SEARCH_URL + args.join("+")))
21
+ page = get_url(GOOGLE_SEARCH_URL, args)
22
22
  html = Nokogiri.HTML(page)
23
23
  posts = []
24
- html.css('.r a').each do |link|
25
- posts << link[:href].gsub("/url?q=", "").gsub(/&(.*)/, "") if is_question?(link[:href])
24
+ html.css('.result-link a').each do |link|
25
+ posts << "http://stackoverflow.com#{link[:href]}"
26
26
  end
27
27
  posts
28
28
  end
@@ -37,7 +37,7 @@ module Lita
37
37
  end
38
38
 
39
39
  def howdoi(chat)
40
- args = chat.matches[0].last.split
40
+ args = chat.matches[0].last.split.join("+")
41
41
  links = get_google_links(args)
42
42
  link = get_link_at_pos(links, 1)
43
43
 
@@ -51,10 +51,12 @@ module Lita
51
51
  collect(&:content).
52
52
  join(" " * 5 + '-' * 50 + "\n") ||
53
53
  ans.at_css("code").content
54
- if instruction
54
+
55
+ unless instruction.empty?
55
56
  chat.reply "```\n#{instruction}```"
56
57
  else
57
- chat.reply "```\n#{ans.at('.post-text').content}```"
58
+ p ans.at_css('.post-text').content
59
+ chat.reply "```\n#{ans.at_css('.post-text').content}```"
58
60
  end
59
61
  end
60
62
  else
data/lita-howdoi.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-howdoi"
3
- spec.version = "0.0.1"
3
+ spec.version = "0.0.2"
4
4
  spec.authors = ["Taylor Lapeyre"]
5
5
  spec.email = ["taylorlapeyre@gmail.com"]
6
6
  spec.description = "Crawls Stack Overflow for the first answer it finds with a solution to some query."
@@ -9,4 +9,9 @@ describe Lita::Handlers::Howdoi, lita_handler: true do
9
9
  send_command("howdoi split a string in ruby")
10
10
  expect(replies.last).to match /\.split/
11
11
  end
12
+
13
+ it "doesn't always return an answer" do
14
+ send_command("howdoi asdufkjhsdfjidsklf")
15
+ expect(replies.last).to match /Sorry/
16
+ end
12
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-howdoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre