ruboty-url 1.1.1 → 1.2.0
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 +4 -4
- data/README.md +5 -3
- data/lib/ruboty/url/actions/title.rb +5 -2
- data/lib/ruboty/url/version.rb +1 -1
- data/test/ruboty/url/actions/title_test.rb +19 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd9ad145142ab3c584b0af168992f0ba73a61f15
|
4
|
+
data.tar.gz: 482a30934a69c2c41f14c1c13d001c9869861785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cab8fd7a066d2c5bb07312f1da03860f2a4a67f17a6c2fddb468d26dee968b0daffef83cccbe826b5322876f29b9f131d328cd45188bc64c2434e873d3b816b
|
7
|
+
data.tar.gz: f5597045b6aaccdbb98676eda753b3cf2aa0394981e4912f4a372747c4ada160f4c2694229fd185817e874b27e1147ba9e1ab432f0e1ba5416b0e72de04f2d99
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
[](https://travis-ci.org/zeero/ruboty-url)
|
2
|
+
[](https://badge.fury.io/rb/ruboty-url)
|
3
|
+
[](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|(
|
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
|
-
|
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.
|
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
|
data/lib/ruboty/url/version.rb
CHANGED
@@ -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) {
|
30
|
-
let(:og_site_name) {
|
31
|
-
let(:favicon_url) {
|
32
|
-
let(:og_description) {
|
33
|
-
let(:og_image) {
|
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
|