slackhook 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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +9 -0
- data/lib/slackhook.rb +21 -0
- data/lib/slackhook/version.rb +3 -0
- data/lib/slackhook/webhook_service.rb +28 -0
- data/slackhook.gemspec +24 -0
- data/test/test_slackhook.rb +14 -0
- metadata +97 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 67c80a31d87839cfc10443f08d3134e9e66f22f3
|
|
4
|
+
data.tar.gz: 4e37f2613048675d2909af139393883bb2a05bb9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f4b6665206f40023aa234ca4ed96067ce4e09086b5ecd373ee28f7c2cb9cba75d8c76d30b3cfb194f238926197788e164e240614964b59b31054d36137559116
|
|
7
|
+
data.tar.gz: 33f69d72a8a052e9a1acbae72fe0dc9107ebce3ec4b9abed4014ef67a99df97135299af53b1bcd7fa91485601c4561ddda94be6ab31c035008555fe840d7112a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Urielable
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Slackhook
|
|
2
|
+
|
|
3
|
+
Easily add Slack WebHooks integration and send messages from your Ruby application.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'slackhook'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
$ gem install slackhook
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
To use this gem you only need to configure the Incoming WebHook integration in Slack.
|
|
30
|
+
|
|
31
|
+
You can find this using your slack account and going to [Incoming WebHooks](https://api.slack.com/) and select your default channel.
|
|
32
|
+
|
|
33
|
+
Well, now you are ready to send messages to Slack channels \0/!
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
# This is how you send messages to your default channel.
|
|
40
|
+
Slackhook.send_hook({webhook_url: "your_webhook_url", text: "test message"})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
There are also ```username``` and ```icon_type``` (**slackbot** is the default) options to be more specific about the nickname and avatar which would appear on the chat.
|
|
44
|
+
|
|
45
|
+
You can use the ```channel``` option if the message is goint to be sent to a non default channel.
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
> require "slackhook"
|
|
49
|
+
> Slackhook.send_hook({ webhook_url: "your_webhook_url",
|
|
50
|
+
text: "test message",
|
|
51
|
+
channel: "@your-channel",
|
|
52
|
+
username: "testbot",
|
|
53
|
+
icon_type: ":trollface:"})
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Contributing
|
|
57
|
+
|
|
58
|
+
1. [Fork it](https://github.com/Urielable/slackhook/fork)
|
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/slackhook.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#encoding: UTF-8
|
|
2
|
+
require "slackhook/version"
|
|
3
|
+
require "slackhook/webhook_service"
|
|
4
|
+
|
|
5
|
+
module Slackhook
|
|
6
|
+
def self.send_hook options
|
|
7
|
+
# Send message to Slack
|
|
8
|
+
#
|
|
9
|
+
# Example:
|
|
10
|
+
# >> Slackhook.send_hook({webhook_url: "your_webhook_url", text: "message", channel: "@urielable", username: "testbot"})
|
|
11
|
+
# => "200"
|
|
12
|
+
#
|
|
13
|
+
# Arguments:
|
|
14
|
+
# webhook_url: (String)
|
|
15
|
+
# text: (String)
|
|
16
|
+
# channel: (String)
|
|
17
|
+
# username: (String)
|
|
18
|
+
|
|
19
|
+
WebhookService::Webhook.new(options).send
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#encoding: UTF-8
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require "uri"
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module WebhookService
|
|
7
|
+
class Webhook
|
|
8
|
+
def initialize options = {}
|
|
9
|
+
@text = options.fetch(:text, nil)
|
|
10
|
+
@icon_type = options.fetch(:icon_type, nil)
|
|
11
|
+
@channel = options.fetch(:channel, nil)
|
|
12
|
+
@username = options.fetch(:username, nil)
|
|
13
|
+
@webhook_url = options.fetch(:webhook_url, nil)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def send
|
|
17
|
+
uri = URI::encode(@webhook_url)
|
|
18
|
+
@toSend = { channel: @channel, text: @text, username: @username, icon_emoji: @icon_type}
|
|
19
|
+
uri = URI.parse(uri)
|
|
20
|
+
https = Net::HTTP.new(uri.host,uri.port)
|
|
21
|
+
https.use_ssl = true
|
|
22
|
+
req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
|
|
23
|
+
req.body = JSON.dump @toSend
|
|
24
|
+
res = https.request(req)
|
|
25
|
+
res.code
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/slackhook.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'slackhook/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "slackhook"
|
|
8
|
+
spec.version = Slackhook::VERSION
|
|
9
|
+
spec.authors = ["Urielable"]
|
|
10
|
+
spec.email = ["uriel85@gmail.com"]
|
|
11
|
+
spec.summary = %q{Easily add Slack Webhook integration to your Ruby application.}
|
|
12
|
+
spec.description = %q{Easily add Slack Webhook integration to your Ruby application.}
|
|
13
|
+
spec.homepage = "https://github.com/Urielable/slackhook"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.5.0"
|
|
24
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "minitest/autorun"
|
|
2
|
+
require "slackhook"
|
|
3
|
+
|
|
4
|
+
class SlackhookTest < Minitest::Test
|
|
5
|
+
def test_params_for_all_options_present
|
|
6
|
+
assert_equal "200",
|
|
7
|
+
Slackhook.send_hook({webhook_url: webhook_url, text: "Unit test message", icon_type: ":trollface:", channel: "channel", username: "testbot"})
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_params_for_missing_values
|
|
11
|
+
assert_equal "200",
|
|
12
|
+
Slackhook.send_hook({webhook_url: webhook_url, text: "Unit test missing", channel: "channel", username: "testbot"})
|
|
13
|
+
end
|
|
14
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: slackhook
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Urielable
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.7'
|
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
|
21
|
+
requirements:
|
|
22
|
+
- - ~>
|
|
23
|
+
- !ruby/object:Gem::Version
|
|
24
|
+
version: '1.7'
|
|
25
|
+
prerelease: false
|
|
26
|
+
type: :development
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ~>
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ~>
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '10.0'
|
|
39
|
+
prerelease: false
|
|
40
|
+
type: :development
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 5.5.0
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ~>
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 5.5.0
|
|
53
|
+
prerelease: false
|
|
54
|
+
type: :development
|
|
55
|
+
description: Easily add Slack Webhook integration to your Ruby application.
|
|
56
|
+
email:
|
|
57
|
+
- uriel85@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- .gitignore
|
|
63
|
+
- Gemfile
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- lib/slackhook.rb
|
|
68
|
+
- lib/slackhook/version.rb
|
|
69
|
+
- lib/slackhook/webhook_service.rb
|
|
70
|
+
- slackhook.gemspec
|
|
71
|
+
- test/test_slackhook.rb
|
|
72
|
+
homepage: https://github.com/Urielable/slackhook
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata: {}
|
|
76
|
+
post_install_message:
|
|
77
|
+
rdoc_options: []
|
|
78
|
+
require_paths:
|
|
79
|
+
- lib
|
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - '>='
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - '>='
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
requirements: []
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 2.1.9
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 4
|
|
95
|
+
summary: Easily add Slack Webhook integration to your Ruby application.
|
|
96
|
+
test_files:
|
|
97
|
+
- test/test_slackhook.rb
|