slack-notifier 0.0.2 → 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83db950c51929ccead9dbf89c58da3b9541962ce
4
+ data.tar.gz: 5ee3e1251538ebae0fbdfc4424a9f9896e25dd91
5
+ SHA512:
6
+ metadata.gz: bc71aa9876f7243a9c62f2aa3538e225e8c987b9df937712c67587917f26a6fdcf6fa275864efd162612d3c056e63a2c1b3fc64452b3a00f06ce39d3705f1c2e
7
+ data.tar.gz: 5003ed1c65c2c6f6555a1e5b41d9f3c436d4ec453e59c548699249adac6d77cd9bac59ebb631c0a9959f50911324c7a4d1cae97ca977f3382f74174824c825c3
@@ -11,11 +11,12 @@ module Slack
11
11
  attr_reader :team, :token
12
12
 
13
13
  def initialize team, token
14
- @team = team
14
+ @team = team
15
15
  @token = token
16
16
  end
17
17
 
18
18
  def ping message, options={}
19
+ message = LinkFormatter.format(message)
19
20
  payload = { text: message }.merge(default_payload).merge(options)
20
21
 
21
22
  unless payload.has_key? :channel
@@ -29,7 +30,7 @@ module Slack
29
30
 
30
31
  def default_payload
31
32
  payload = {}
32
- payload[:channel] = channel if channel
33
+ payload[:channel] = channel if channel
33
34
  payload[:username] = username if username
34
35
  payload
35
36
  end
@@ -38,5 +39,47 @@ module Slack
38
39
  "https://#{team}.slack.com/services/hooks/incoming-webhook?token=#{token}"
39
40
  end
40
41
 
42
+ class LinkFormatter
43
+ class << self
44
+ def format string
45
+ LinkFormatter.new(string).formatted
46
+ end
47
+ end
48
+
49
+ def initialize string
50
+ @orig = string
51
+ end
52
+
53
+ def formatted
54
+ @orig.gsub( html_pattern ) do |match|
55
+ link = Regexp.last_match[1]
56
+ text = Regexp.last_match[2]
57
+ slack_link link, text
58
+ end.gsub( markdown_pattern ) do |match|
59
+ link = Regexp.last_match[2]
60
+ text = Regexp.last_match[1]
61
+ slack_link link, text
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def slack_link link, text=nil
68
+ out = "<#{link}"
69
+ out << "|#{text}" if text && !text.empty?
70
+ out << ">"
71
+
72
+ return out
73
+ end
74
+
75
+ def html_pattern
76
+ / <a (?:.*?) href=['"](.+)['"] (?:.*)> (.+?) <\/a> /x
77
+ end
78
+
79
+ def markdown_pattern
80
+ /\[(.*?)\]\((.+?)\)/
81
+ end
82
+ end
83
+
41
84
  end
42
85
  end
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  class Notifier
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack::Notifier do
4
+
5
+ describe Slack::Notifier::LinkFormatter do
6
+ it "formats html links" do
7
+ formatted = Slack::Notifier::LinkFormatter.format("Hello World, enjoy <a href='http://example.com'>this</a>.")
8
+ expect( formatted ).to include("<http://example.com|this>")
9
+ end
10
+
11
+ it "formats markdown links" do
12
+ formatted = Slack::Notifier::LinkFormatter.format("Hello World, enjoy [this](http://example.com).")
13
+ expect( formatted ).to include("<http://example.com|this>")
14
+ end
15
+
16
+ it "formats markdown links with no title" do
17
+ formatted = Slack::Notifier::LinkFormatter.format("Hello World, enjoy [](http://example.com).")
18
+ expect( formatted ).to include("<http://example.com>")
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,2 @@
1
+ require 'slack-notifier'
2
+ require 'pry-debugger'
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steven Sloan
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
11
+ date: 2013-09-07 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,12 +20,11 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.11.0
30
- description: ! ' A simple wrapper for posting to slack channels '
27
+ description: ' A simple wrapper for posting to slack channels '
31
28
  email:
32
29
  - stevenosloan@gmail.com
33
30
  executables: []
@@ -36,30 +33,32 @@ extra_rdoc_files: []
36
33
  files:
37
34
  - lib/slack-notifier/version.rb
38
35
  - lib/slack-notifier.rb
36
+ - spec/slack-notifier_spec.rb
37
+ - spec/spec_helper.rb
39
38
  homepage: http://github.com/stevenosloan/slack-notifier
40
39
  licenses:
41
40
  - MIT
41
+ metadata: {}
42
42
  post_install_message:
43
43
  rdoc_options: []
44
44
  require_paths:
45
45
  - lib
46
46
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
47
  requirements:
49
- - - ! '>='
48
+ - - '>='
50
49
  - !ruby/object:Gem::Version
51
50
  version: '0'
52
51
  required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
52
  requirements:
55
- - - ! '>='
53
+ - - '>='
56
54
  - !ruby/object:Gem::Version
57
55
  version: '0'
58
56
  requirements: []
59
57
  rubyforge_project:
60
- rubygems_version: 1.8.25
58
+ rubygems_version: 2.0.5
61
59
  signing_key:
62
- specification_version: 3
60
+ specification_version: 4
63
61
  summary: A simple wrapper for posting to slack channels
64
- test_files: []
65
- has_rdoc:
62
+ test_files:
63
+ - spec/slack-notifier_spec.rb
64
+ - spec/spec_helper.rb