ruboty-url 1.1.1 → 1.2.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: 81cd33b72d31b926cc1ed0dbb100bf97f33366a9
4
- data.tar.gz: 5220f5fca994bbf462f566731ac7f90a9ba16513
3
+ metadata.gz: bd9ad145142ab3c584b0af168992f0ba73a61f15
4
+ data.tar.gz: 482a30934a69c2c41f14c1c13d001c9869861785
5
5
  SHA512:
6
- metadata.gz: cb9cbb4ecca2aeb2a6e3735e427f38cb42c17ff986824231a75393eb21666b0d51ab9da263dc17f1ccdc4f0f7566c08d4007b2e01a6b2bbb3a1848c0402de65e
7
- data.tar.gz: fa0e987e074823ff585ce87d3022b618a24cd5daedd7d337268fc0b9dbf496b8ad1c891a5ef4b1a1b89d66db7e856bc694462725bc1a96e73c036789651e991e
6
+ metadata.gz: 9cab8fd7a066d2c5bb07312f1da03860f2a4a67f17a6c2fddb468d26dee968b0daffef83cccbe826b5322876f29b9f131d328cd45188bc64c2434e873d3b816b
7
+ data.tar.gz: f5597045b6aaccdbb98676eda753b3cf2aa0394981e4912f4a372747c4ada160f4c2694229fd185817e874b27e1147ba9e1ab432f0e1ba5416b0e72de04f2d99
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  [![Build Status](https://travis-ci.org/zeero/ruboty-url.svg?branch=master)](https://travis-ci.org/zeero/ruboty-url)
2
+ [![Gem Version](https://badge.fury.io/rb/ruboty-url.svg)](https://badge.fury.io/rb/ruboty-url)
3
+ [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE.txt)
2
4
 
3
5
  # Ruboty::Url
4
6
 
@@ -24,8 +26,6 @@ And then execute:
24
26
 
25
27
  This plugin responds with messages including specified URL (such as private URL), and shows HTML title.
26
28
 
27
- Reply style is Slack attachment. Please use with 'ruboty-slack_rtm' plugin.
28
-
29
29
  URL is specified by 'RUBOTY_URL_REGEXP' environmental variable, value is RegExp for url that you want to show HTML title with.
30
30
 
31
31
  ex:
@@ -34,6 +34,8 @@ ex:
34
34
  export RUBOTY_URL_REGEXP=(https://foo.com.*|http://bar.org.*)
35
35
  ```
36
36
 
37
+ When you use with 'ruboty-slack_rtm' plugin, Ruboty can reply by Slack attachment style.
38
+
37
39
  ## ENV
38
40
 
39
41
  |Name|Description|
@@ -44,7 +46,7 @@ export RUBOTY_URL_REGEXP=(https://foo.com.*|http://bar.org.*)
44
46
 
45
47
  |Name|Description|
46
48
  |:--|:--|
47
- |ruboty-slack_rtm|(required) 'ruboty-url' is supposed to work with 'ruboty-slack_rtm' - Ruboty Adapter for Slack Realtime API.|
49
+ |ruboty-slack_rtm|(recommended) Ruboty Adapter for Slack Realtime API.|
48
50
 
49
51
  ## Contributing
50
52
 
@@ -13,11 +13,14 @@ module Ruboty
13
13
  }
14
14
  open(url) do |f|
15
15
  html = Nokogiri::HTML(f)
16
- attachment[:title] = html.xpath('/html/head/title').text
16
+ title = html.xpath('/html/head/title').text
17
+
18
+ # guard slack_rtm
19
+ return message.reply(title) unless Ruboty.const_defined? 'Adapters::SlackRTM'
17
20
 
18
21
  # optional infos
19
22
  og_title = html.xpath('/html/head/meta[@property="og:title"]/@content').first
20
- attachment[:title] = og_title.text if og_title.present?
23
+ attachment[:title] = og_title.present? ? og_title.text : title
21
24
  og_site_name = html.xpath('/html/head/meta[@property="og:site_name"]/@content').first
22
25
  attachment[:author_name] = og_site_name.text if og_site_name.present?
23
26
  favicon_url = html.xpath('/html/head/link[@rel="icon"]/@href').first
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Url
3
- VERSION = '1.1.1'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
@@ -12,30 +12,32 @@ describe Ruboty::Url::Actions::Title do
12
12
  let(:url) { 'https://foo/' }
13
13
  let(:title) { "foo's title" }
14
14
 
15
- it 'should get HTML title' do
15
+ it 'should get HTML title (attachment)' do
16
16
  # stub
17
17
  mock_message.stubs(:[]).with(0).returns(url)
18
18
  OpenURI.stubs(:open_uri).yields(StringIO.new("<html><head><title>#{title}</title></head></html>"))
19
+ Ruboty.stubs(:const_defined?).with('Adapters::SlackRTM').returns(true)
19
20
  # mock
20
21
  attachments = [{
21
22
  color: '#E2E2E2',
22
23
  title_link: url,
23
- title: title,
24
+ title: title
24
25
  }]
25
26
  mock_message.expects(:reply).with(nil, attachments: attachments).once
26
27
  subject.call
27
28
  end
28
29
 
29
- let(:og_title) { "bar's title" }
30
- let(:og_site_name) { "bar's site name" }
31
- let(:favicon_url) { "https://bar.site/favicon.ico" }
32
- let(:og_description) { "bar's description." }
33
- let(:og_image) { "https://bar.site/image.png" }
30
+ let(:og_title) { 'bar\'s title' }
31
+ let(:og_site_name) { 'bar\'s site name' }
32
+ let(:favicon_url) { 'https://bar.site/favicon.ico' }
33
+ let(:og_description) { 'bar\'s description.' }
34
+ let(:og_image) { 'https://bar.site/image.png' }
34
35
 
35
36
  it 'should get optional infos' do
36
37
  # stub
37
38
  mock_message.stubs(:[]).with(0).returns(url)
38
39
  OpenURI.stubs(:open_uri).yields(StringIO.new("<html><head><meta property=\"og:image\" content=\"#{og_image}\" /><meta property=\"og:site_name\" content=\"#{og_site_name}\" /><meta property=\"og:type\" content=\"object\" /><meta property=\"og:title\" content=\"#{og_title}\" /><meta property=\"og:url\" content=\"https://github.com/zeero/ruboty-url\" /><meta property=\"og:description\" content=\"#{og_description}\" /><title>#{title}</title><link rel=\"icon\" type=\"image/x-icon\" class=\"js-site-favicon\" href=\"#{favicon_url}\"><link rel=\"icon\" type=\"image/x-icon\" class=\"js-site-favicon\" href=\"#{favicon_url}/dummy\"></head></html>"))
40
+ Ruboty.stubs(:const_defined?).with('Adapters::SlackRTM').returns(true)
39
41
  # mock
40
42
  attachments = [{
41
43
  color: '#E2E2E2',
@@ -44,10 +46,19 @@ describe Ruboty::Url::Actions::Title do
44
46
  author_name: og_site_name,
45
47
  author_icon: favicon_url,
46
48
  text: og_description,
47
- thumb_url: og_image,
49
+ thumb_url: og_image
48
50
  }]
49
51
  mock_message.expects(:reply).with(nil, attachments: attachments).once
50
52
  subject.call
51
53
  end
54
+
55
+ it 'should get HTML title (plain text), when Ruboty::Adapters::SlackRTM is not loaded' do
56
+ # stub
57
+ mock_message.stubs(:[]).with(0).returns(url)
58
+ OpenURI.stubs(:open_uri).yields(StringIO.new("<html><head><title>#{title}</title></head></html>"))
59
+ # mock
60
+ mock_message.expects(:reply).with(title).once
61
+ subject.call
62
+ end
52
63
  end
53
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-url
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zeero