slack-notifier 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83db950c51929ccead9dbf89c58da3b9541962ce
4
- data.tar.gz: 5ee3e1251538ebae0fbdfc4424a9f9896e25dd91
3
+ metadata.gz: 343978628e7a8085818befad991f0c3629527237
4
+ data.tar.gz: c05543a0c0385f954bd79bd64def1743b2d8e346
5
5
  SHA512:
6
- metadata.gz: bc71aa9876f7243a9c62f2aa3538e225e8c987b9df937712c67587917f26a6fdcf6fa275864efd162612d3c056e63a2c1b3fc64452b3a00f06ce39d3705f1c2e
7
- data.tar.gz: 5003ed1c65c2c6f6555a1e5b41d9f3c436d4ec453e59c548699249adac6d77cd9bac59ebb631c0a9959f50911324c7a4d1cae97ca977f3382f74174824c825c3
6
+ metadata.gz: cb4ab2e7781936a0d9829e5426848a89832063f2e9791ab5531f89df244acfc29d01b814ac8e2f6d7d36797d7229f8d1acdf2e8b27992a13255980f29bf66d06
7
+ data.tar.gz: c21154be148aa4e44d432f3006229989e29a889b4302de2f7b5170a15e481150fe733809ea98ec5971eca428ce70fe3a2599e88fb490bd1e8ecb39de1d17dfbb
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
3
 
4
+ require_relative 'slack-notifier/link_formatter'
5
+
4
6
  module Slack
5
7
  class Notifier
6
8
 
@@ -39,47 +41,5 @@ module Slack
39
41
  "https://#{team}.slack.com/services/hooks/incoming-webhook?token=#{token}"
40
42
  end
41
43
 
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
-
84
44
  end
85
45
  end
@@ -0,0 +1,49 @@
1
+ module Slack
2
+ class Notifier
3
+ class LinkFormatter
4
+
5
+ class << self
6
+
7
+ def format string
8
+ LinkFormatter.new(string).formatted
9
+ end
10
+
11
+ end
12
+
13
+ def initialize string
14
+ @orig = string
15
+ end
16
+
17
+ def formatted
18
+ @orig.gsub( html_pattern ) do |match|
19
+ link = Regexp.last_match[1]
20
+ text = Regexp.last_match[2]
21
+ slack_link link, text
22
+ end.gsub( markdown_pattern ) do |match|
23
+ link = Regexp.last_match[2]
24
+ text = Regexp.last_match[1]
25
+ slack_link link, text
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def slack_link link, text=nil
32
+ out = "<#{link}"
33
+ out << "|#{text}" if text && !text.empty?
34
+ out << ">"
35
+
36
+ return out
37
+ end
38
+
39
+ def html_pattern
40
+ / <a (?:.*?) href=['"](.+)['"] (?:.*)> (.+?) <\/a> /x
41
+ end
42
+
43
+ def markdown_pattern
44
+ /\[(.*?)\]\((.+?)\)/
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  module Slack
2
2
  class Notifier
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack::Notifier::LinkFormatter do
4
+
5
+ describe "::format" do
6
+
7
+ it "formats html links" do
8
+ formatted = described_class.format("Hello World, enjoy <a href='http://example.com'>this</a>.")
9
+ expect( formatted ).to include("<http://example.com|this>")
10
+ end
11
+
12
+ it "formats markdown links" do
13
+ formatted = described_class.format("Hello World, enjoy [this](http://example.com).")
14
+ expect( formatted ).to include("<http://example.com|this>")
15
+ end
16
+
17
+ it "formats markdown links with no title" do
18
+ formatted = described_class.format("Hello World, enjoy [](http://example.com).")
19
+ expect( formatted ).to include("<http://example.com>")
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe Slack::Notifier do
4
+
5
+ describe "#initialize" do
6
+ it "sets the given team" do
7
+ subject = described_class.new 'team', 'token'
8
+ expect( subject.team ).to eq 'team'
9
+ end
10
+
11
+ it "sets the given token" do
12
+ subject = described_class.new 'team', 'token'
13
+ expect( subject.token ).to eq 'token'
14
+ end
15
+ end
16
+
17
+ describe "#ping" do
18
+ it "passes the message through LinkFormatter" do
19
+ allow( HTTParty ).to receive(:post)
20
+ expect( Slack::Notifier::LinkFormatter ).to receive(:format)
21
+ .with("the message")
22
+
23
+ described_class.new('team','token').ping "the message", channel: 'foo'
24
+ end
25
+
26
+ it "requires a channel to be set" do
27
+ allow( HTTParty ).to receive(:post)
28
+
29
+ expect{
30
+ described_class.new('team','token').ping "the message"
31
+ }.to raise_error
32
+ end
33
+
34
+ context "with a default channel set" do
35
+
36
+ before :each do
37
+ allow( HTTParty ).to receive(:post)
38
+ @subject = described_class.new('team','token')
39
+ @subject.channel = 'default'
40
+ end
41
+
42
+ it "does not require a channel to ping" do
43
+ expect{
44
+ @subject.ping "the message"
45
+ }.not_to raise_error
46
+ end
47
+
48
+ it "uses default channel" do
49
+ expect( HTTParty ).to receive(:post)
50
+ .with "https://team.slack.com/services/hooks/incoming-webhook?token=token",
51
+ body: 'payload={"text":"the message","channel":"default"}'
52
+
53
+ @subject.ping "the message"
54
+ end
55
+
56
+ it "allows override channel to be set" do
57
+ expect( HTTParty ).to receive(:post)
58
+ .with "https://team.slack.com/services/hooks/incoming-webhook?token=token",
59
+ body: 'payload={"text":"the message","channel":"new"}'
60
+
61
+ @subject.ping "the message", channel: "new"
62
+ end
63
+
64
+ end
65
+
66
+ it "posts with the correct endpoint & data" do
67
+ expect( HTTParty ).to receive(:post)
68
+ .with "https://team.slack.com/services/hooks/incoming-webhook?token=token",
69
+ body: 'payload={"text":"the message","channel":"channel"}'
70
+
71
+ described_class.new("team","token").ping "the message", channel: "channel"
72
+ end
73
+ end
74
+
75
+ end
@@ -1,2 +1,13 @@
1
+ require 'rspec'
1
2
  require 'slack-notifier'
2
- require 'pry-debugger'
3
+
4
+ if ENV['DEBUG']
5
+ require 'pry'
6
+ end
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_doubled_constant_names = true
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slack-notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Sloan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-07 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -16,24 +16,26 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 0.11.0
19
+ version: '0.11'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 0.11.0
27
- description: ' A simple wrapper for posting to slack channels '
26
+ version: '0.11'
27
+ description: ' A slim ruby wrapper for posting to slack channels '
28
28
  email:
29
29
  - stevenosloan@gmail.com
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/slack-notifier/version.rb
35
34
  - lib/slack-notifier.rb
36
- - spec/slack-notifier_spec.rb
35
+ - lib/slack-notifier/link_formatter.rb
36
+ - lib/slack-notifier/version.rb
37
+ - spec/lib/slack-notifier/link_formatter_spec.rb
38
+ - spec/lib/slack-notifier_spec.rb
37
39
  - spec/spec_helper.rb
38
40
  homepage: http://github.com/stevenosloan/slack-notifier
39
41
  licenses:
@@ -55,10 +57,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  version: '0'
56
58
  requirements: []
57
59
  rubyforge_project:
58
- rubygems_version: 2.0.5
60
+ rubygems_version: 2.2.2
59
61
  signing_key:
60
62
  specification_version: 4
61
- summary: A simple wrapper for posting to slack channels
63
+ summary: A slim ruby wrapper for posting to slack channels
62
64
  test_files:
63
- - spec/slack-notifier_spec.rb
65
+ - spec/lib/slack-notifier/link_formatter_spec.rb
66
+ - spec/lib/slack-notifier_spec.rb
64
67
  - spec/spec_helper.rb
@@ -1,22 +0,0 @@
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