ruboty-url 1.0.1 → 1.1.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 +1 -1
- data/lib/ruboty/url/actions/title.rb +19 -9
- data/lib/ruboty/url/version.rb +1 -1
- data/test/ruboty/url/actions/title_test.rb +24 -0
- 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: d91d6be5089da10c7c5913ca4e0de2f8c82f2002
|
4
|
+
data.tar.gz: 569c8b8820e2be922454fc0573b7c84c2484f58e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e90a115f062a6e264301a7de26f7f789403ea2bb96cf81e79ffd9695ed42b2fb7ad92281d2e6192e138bd86a257c309b8109609fab60f76be6e398e6d1134fc7
|
7
|
+
data.tar.gz: 3e89e85ee0dc70ee231d523147bab6916ea4bf564b9091e27ffdad15c5b93a2274fd7e76c289beccb4ece47165098181dc0524ed8dcb5d2cb251848cfe83cb17
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ And then execute:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
<img width="
|
23
|
+
<img width="675" alt="screenshot_ruboty-url" src="https://user-images.githubusercontent.com/105469/37563621-4c825b30-2ac8-11e8-917a-480b5ce74908.png">
|
24
24
|
|
25
25
|
This plugin responds with messages including specified URL (such as private URL), and shows HTML title.
|
26
26
|
|
@@ -7,17 +7,27 @@ module Ruboty
|
|
7
7
|
class Title < Ruboty::Actions::Base
|
8
8
|
def call
|
9
9
|
url = message[0]
|
10
|
-
|
11
|
-
open(url) do |f|
|
12
|
-
doc = Nokogiri::HTML(f)
|
13
|
-
title = doc.xpath('/html/head/title').text
|
14
|
-
end
|
15
|
-
attachments = [{
|
10
|
+
attachment = {
|
16
11
|
color: '#EEEEEE',
|
17
|
-
title: title,
|
18
12
|
title_link: url,
|
19
|
-
}
|
20
|
-
|
13
|
+
}
|
14
|
+
open(url) do |f|
|
15
|
+
html = Nokogiri::HTML(f)
|
16
|
+
attachment[:title] = html.xpath('/html/head/title').text
|
17
|
+
|
18
|
+
# optional infos
|
19
|
+
og_title = html.xpath('/html/head/meta[@property="og:title"]/@content').text
|
20
|
+
attachment[:title] = og_title if og_title.present?
|
21
|
+
og_site_name = html.xpath('/html/head/meta[@property="og:site_name"]/@content').text
|
22
|
+
attachment[:author_name] = og_site_name if og_site_name.present?
|
23
|
+
favicon_url = html.xpath('/html/head/link[@rel="icon"]/@href').text
|
24
|
+
attachment[:author_icon] = favicon_url if favicon_url.present?
|
25
|
+
og_description = html.xpath('/html/head/meta[@property="og:description"]/@content').text
|
26
|
+
attachment[:text] = og_description if og_description.present?
|
27
|
+
og_image = html.xpath('/html/head/meta[@property="og:image"]/@content').text
|
28
|
+
attachment[:thumb_url] = og_image if og_image.present?
|
29
|
+
end
|
30
|
+
message.reply(nil, attachments: [attachment]) if attachment[:title].present?
|
21
31
|
end
|
22
32
|
end
|
23
33
|
end
|
data/lib/ruboty/url/version.rb
CHANGED
@@ -19,8 +19,32 @@ describe Ruboty::Url::Actions::Title do
|
|
19
19
|
# mock
|
20
20
|
attachments = [{
|
21
21
|
color: '#EEEEEE',
|
22
|
+
title_link: url,
|
22
23
|
title: title,
|
24
|
+
}]
|
25
|
+
mock_message.expects(:reply).with(nil, attachments: attachments).once
|
26
|
+
subject.call
|
27
|
+
end
|
28
|
+
|
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" }
|
34
|
+
|
35
|
+
it 'should get optional infos' do
|
36
|
+
# stub
|
37
|
+
mock_message.stubs(:[]).with(0).returns(url)
|
38
|
+
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}\"></head></html>"))
|
39
|
+
# mock
|
40
|
+
attachments = [{
|
41
|
+
color: '#EEEEEE',
|
23
42
|
title_link: url,
|
43
|
+
title: og_title,
|
44
|
+
author_name: og_site_name,
|
45
|
+
author_icon: favicon_url,
|
46
|
+
text: og_description,
|
47
|
+
thumb_url: og_image,
|
24
48
|
}]
|
25
49
|
mock_message.expects(:reply).with(nil, attachments: attachments).once
|
26
50
|
subject.call
|