ruboty-url 1.0.1 → 1.1.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: 5875c125aeb79672d6464881fd321e191d4f08fe
4
- data.tar.gz: ecc1fc19fa58d06a0a23ae911616dbfb10ff9e32
3
+ metadata.gz: d91d6be5089da10c7c5913ca4e0de2f8c82f2002
4
+ data.tar.gz: 569c8b8820e2be922454fc0573b7c84c2484f58e
5
5
  SHA512:
6
- metadata.gz: 1933500281d670c89f4565d96ad7a6cde5289de11778e45fbbe98604c5b41e539b12b89152842698da018a09881b7a04b78ad55c125a01d307c7908e5351725d
7
- data.tar.gz: 9530701599e817acad7bd4a988e763ca367b85f3b3360e606e15cfe227ef970480907656a94a140ae53aebde5c7561eb6061854918e10adce6cec18c88c99d28
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="671" alt="screenshot_ruboty-url" src="https://user-images.githubusercontent.com/105469/37558137-b9e5f8b0-2a52-11e8-93df-530e6547d259.png">
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
- title = ''
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
- message.reply(nil, attachments: attachments) unless title.empty?
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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Url
3
- VERSION = '1.0.1'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
@@ -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
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.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zeero