lita-web-title 1.0.3 → 1.0.4

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: 2f705b31124e81a12d6ffa776252eca2909733f8
4
- data.tar.gz: f20cbeaf3fcbebb65d0cdbf2559d211c9ca1eba2
3
+ metadata.gz: 01b22e197b9e136251e32f40b706778afd97594a
4
+ data.tar.gz: 6d2d77eda40cd75f4325087942ff7ce2702ff9f6
5
5
  SHA512:
6
- metadata.gz: 4a43eadc289198c480e6b347218f0a2ab257476fac81755092b066f26cf4998b10566fa421e499a9c7ce284d8971bf92861ed7d087cc3521c292d428e120a0ba
7
- data.tar.gz: 5b773ce37ef85a80b3f6563caf0b1e948a107d9925a9db80816ed652d59be46b7ae919d3ff7442dae191ece08fc1fd19cd079c626dd47fbda32670fc4aef71ae
6
+ metadata.gz: adbdd916513838a6fa0b8410e6f9cfd9f9b1b1ebdf2bffd9561874977e1e6a38f6b21646152bf11cb57d59a30c4cf697c340b308893814caf866b91cd10fa964
7
+ data.tar.gz: 71377ad35b300bc9f7f79705698add5a64a947f75dfd37200af38e8df2cd042f5cd35321cebec220c885e477d0cc9a520f626acd45c7a6fa7a9b5d37c7bbff77
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -3,22 +3,23 @@ require "nokogiri"
3
3
  module Lita
4
4
  module Handlers
5
5
  class WebTitle < Handler
6
- route(URI.regexp(["http", "https"]), :parse_uri_request, help: {
6
+ URI_PROTOCOLS = %w( http https )
7
+ route(URI.regexp(URI_PROTOCOLS), :parse_uri_request, help: {
7
8
  "URL" => "Responds with the title of the web page at URL"
8
9
  })
9
10
 
10
11
  def parse_uri_request(request)
11
- requestUri = URI::extract(request.message.body, ["http", "https"])
12
- result = parse_uri(requestUri[0])
13
- result.delete!("\n").strip!
14
- request.reply(result) unless result.nil?
12
+ requestUri = URI::extract(request.message.body, URI_PROTOCOLS).first
13
+ result = parse_uri(requestUri)
14
+ request.reply(result.delete("\n").strip) unless result.nil?
15
15
  end
16
16
 
17
17
  def parse_uri(uriString)
18
18
  httpRequest = http.get(uriString)
19
19
  if httpRequest.status == 200 then
20
+ return unless httpRequest.headers['Content-Type'] =~ %r{text/x?html}
20
21
  page = Nokogiri::HTML(httpRequest.body)
21
- page.css("title")[0].text
22
+ page.css("title").first.text
22
23
  elsif [300, 301, 302, 303].include? httpRequest.status then
23
24
  parse_uri httpRequest.headers["Location"]
24
25
  else
@@ -26,6 +27,7 @@ module Lita
26
27
  end
27
28
  rescue Exception => msg
28
29
  log.error("lita-web-title: Exception attempting to load URL: #{msg}")
30
+ nil
29
31
  end
30
32
  end
31
33
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-web-title"
3
- spec.version = "1.0.3"
3
+ spec.version = "1.0.4"
4
4
  spec.authors = ["Chris Baker"]
5
5
  spec.email = ["dosman711@gmail.com"]
6
6
  spec.description = "A Lita plugin to parse URIs and post the <title> of the page"
@@ -1,4 +1,35 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::WebTitle, lita_handler: true do
4
+ let(:robot) { Lita::Robot.new(registry) }
5
+ subject(:handler) { described_class.new(robot) }
6
+
7
+ describe 'routing' do
8
+ it { is_expected.to route('I like http://github.com/').to(:parse_uri_request) }
9
+ end
10
+
11
+ describe 'messages' do
12
+ it 'returns the title for a mentioned URL' do
13
+ send_command('I search on http://google.com/ a lot.')
14
+ expect(replies.last).to match(/Google/)
15
+ end
16
+
17
+ it 'returns the title for only the first mentioned URL' do
18
+ send_command('I search on http://google.com/ and http://yahoo.com/ a lot.')
19
+ expect(replies.last).to match(/Google/)
20
+ expect(replies.last).to_not match(/yahoo/i)
21
+ end
22
+
23
+ it 'returns nothing for URLs that are not HTML' do
24
+ send_command('This is the logo https://www.google.com/images/srpr/logo11w.png')
25
+ expect(replies.last).to be_nil
26
+ end
27
+ end
28
+
29
+ describe '.parse_uri' do
30
+ it 'returns the title' do
31
+ expect(handler.parse_uri('https://google.com/'))
32
+ .to match(/Google/)
33
+ end
34
+ end
4
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-web-title
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-30 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".rspec"
119
120
  - ".travis.yml"
120
121
  - Gemfile
121
122
  - LICENSE