slack-incoming-webhooks 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/Rakefile +1 -0
- data/bin/console +15 -0
- data/bin/setup +7 -0
- data/lib/slack/incoming/webhooks.rb +21 -0
- data/lib/slack/incoming/webhooks/configuration.rb +29 -0
- data/lib/slack/incoming/webhooks/connection.rb +18 -0
- data/lib/slack/incoming/webhooks/request.rb +15 -0
- data/lib/slack/incoming/webhooks/version.rb +7 -0
- data/slack-incoming-webhooks.gemspec +24 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e9488331ba45f6066c5fddfd33cff93decc0b3cc
|
4
|
+
data.tar.gz: 8f2c3e47025f193555be8e2b4d41114ce18c44fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 67eb4e6be927f15387c05ed3c0a70c3c2d4f620635eb145106e4734561334854c859d3080917cf72ea246d9d58cd0e68d8411b582c1875dd4909084369926cdb
|
7
|
+
data.tar.gz: 5463129c70110bdd2cbf39eda765ba711b231a8b50cff985f88accb840c3e8b8437d132b051dcb3f45a4d27149e6783926b694a115d4bf96f716dcefedbf4a7f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Shohei Yamasaki
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Slack::Incoming::Webhooks
|
2
|
+
A simple wrapper for posting to slack.
|
3
|
+
|
4
|
+
## Example
|
5
|
+
```ruby
|
6
|
+
require 'slack-incoming-webhooks'
|
7
|
+
|
8
|
+
slack = Slack::Incoming::Webhooks.new "WEBHOOK_URL"
|
9
|
+
slack.post "Hello World"
|
10
|
+
|
11
|
+
# => if your webhook is setup, will message "Hello World"
|
12
|
+
# => to the default channel you set in slack
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'slack-incoming-webhooks'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install slack-incoming-webhooks
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Setting Defaults
|
34
|
+
On initialization you can set default payloads by passing an options hash.
|
35
|
+
Options please refer to [incoming-webhooks](https://api.slack.com/incoming-webhooks).
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
slack = Slack::Incoming::Webhooks.new "WEBHOOK_URL", channel: '#other-channel',
|
39
|
+
username: 'monkey-bot'
|
40
|
+
```
|
41
|
+
|
42
|
+
Once a notifier has been initialized, you can update the default channel or username or attachments .
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
slack.channel = '#other-channel'
|
46
|
+
slack.username = 'monkey-bot'
|
47
|
+
slack.attachments = { color: '#36a64f', title: 'Slack API Documentation' }
|
48
|
+
```
|
49
|
+
|
50
|
+
### Attachments
|
51
|
+
It is possible to create more richly-formatted messages using [Attachments](https://api.slack.com/docs/attachments).
|
52
|
+
slack-incoming-webhooks supports Attachments.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
attachments = {
|
56
|
+
fallback: "Required plain-text summary of the attachment.",
|
57
|
+
color: "#36a64f",
|
58
|
+
pretext: "Optional text that appears above the attachment block",
|
59
|
+
title: "Slack API Documentation",
|
60
|
+
title_link: "https://api.slack.com/",
|
61
|
+
text: "Optional text that appears within the attachment",
|
62
|
+
image_url: "http://my-website.com/path/to/image.jpg"
|
63
|
+
}
|
64
|
+
|
65
|
+
slack.post "with an attachment", attachments: [attachments]
|
66
|
+
```
|
67
|
+
|
68
|
+
or setting defaults.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
slack = Slack::Incoming::Webhooks.new "WEBHOOK_URL", attachments: [attachments]
|
72
|
+
slack.post "with an attachment"
|
73
|
+
```
|
74
|
+
|
75
|
+
or attachments method.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
slack.attachments = { color: '#36a64f', title: 'Slack API Documentation' }
|
79
|
+
```
|
80
|
+
## Console
|
81
|
+
run `bin/console` for an interactive prompt that will allow you to experiment.
|
82
|
+
|
83
|
+
```bash
|
84
|
+
$ bin/console
|
85
|
+
|
86
|
+
[1] pry(main)> slack = Slack::Incoming::Webhooks.new "WEBHOOK_URL"
|
87
|
+
=> #<Slack::Incoming::Webhooks:0x007fae6b871e48
|
88
|
+
[2] pry(main)> slack.post "Hello world!"
|
89
|
+
=> #<Net::HTTPOK 200 OK readbody=true>
|
90
|
+
```
|
91
|
+
|
92
|
+
## Testing
|
93
|
+
```bash
|
94
|
+
$ rspec
|
95
|
+
```
|
96
|
+
|
97
|
+
## Development
|
98
|
+
|
99
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
100
|
+
|
101
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it ( https://github.com/[my-github-username]/slack-incoming-webhooks/fork )
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "slack/incoming/webhooks"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "pry"
|
14
|
+
require "awesome_print"
|
15
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "slack/incoming/webhooks/configuration"
|
2
|
+
require "slack/incoming/webhooks/connection"
|
3
|
+
require "slack/incoming/webhooks/request"
|
4
|
+
require "slack/incoming/webhooks/version"
|
5
|
+
|
6
|
+
module Slack
|
7
|
+
module Incoming
|
8
|
+
class Webhooks
|
9
|
+
include Configuration
|
10
|
+
include Connection
|
11
|
+
include Request
|
12
|
+
|
13
|
+
attr_accessor :webhook_url, :payload
|
14
|
+
|
15
|
+
def initialize(webhook_url, payload={})
|
16
|
+
@webhook_url = webhook_url
|
17
|
+
@payload = payload
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Slack
|
2
|
+
module Incoming
|
3
|
+
module Configuration
|
4
|
+
def channel
|
5
|
+
payload[:channel]
|
6
|
+
end
|
7
|
+
|
8
|
+
def channel= channel
|
9
|
+
payload[:channel] = channel
|
10
|
+
end
|
11
|
+
|
12
|
+
def username
|
13
|
+
payload[:username]
|
14
|
+
end
|
15
|
+
|
16
|
+
def username= username
|
17
|
+
payload[:username] = username
|
18
|
+
end
|
19
|
+
|
20
|
+
def attachments
|
21
|
+
payload[:attachments]
|
22
|
+
end
|
23
|
+
|
24
|
+
def attachments= attachments
|
25
|
+
payload[:attachments] = [attachments]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module Slack
|
6
|
+
module Incoming
|
7
|
+
module Connection
|
8
|
+
def connection
|
9
|
+
uri = URI.parse(webhook_url)
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
http.use_ssl = true
|
12
|
+
http.ssl_version = :TLSv1
|
13
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
14
|
+
http
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Slack
|
5
|
+
module Incoming
|
6
|
+
module Request
|
7
|
+
def post message, options={}
|
8
|
+
uri = URI.parse(webhook_url)
|
9
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
10
|
+
req.set_form_data(payload: payload.merge(options).merge(text: message).to_json)
|
11
|
+
connection.request(req)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -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 'slack/incoming/webhooks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "slack-incoming-webhooks"
|
8
|
+
spec.version = Slack::Incoming::Webhooks::VERSION
|
9
|
+
spec.authors = ["Shohei Yamasaki"]
|
10
|
+
spec.email = ["s-yamasaki@pepabo.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple wrapper for posting to slack.}
|
13
|
+
spec.description = %q{A simple wrapper for posting to slack.}
|
14
|
+
spec.homepage = "https://github.com/shoyan/slack-incoming-webhooks"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slack-incoming-webhooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shohei Yamasaki
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: A simple wrapper for posting to slack.
|
42
|
+
email:
|
43
|
+
- s-yamasaki@pepabo.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
50
|
+
- ".travis.yml"
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/slack/incoming/webhooks.rb
|
59
|
+
- lib/slack/incoming/webhooks/configuration.rb
|
60
|
+
- lib/slack/incoming/webhooks/connection.rb
|
61
|
+
- lib/slack/incoming/webhooks/request.rb
|
62
|
+
- lib/slack/incoming/webhooks/version.rb
|
63
|
+
- slack-incoming-webhooks.gemspec
|
64
|
+
homepage: https://github.com/shoyan/slack-incoming-webhooks
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.2.2
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: A simple wrapper for posting to slack.
|
88
|
+
test_files: []
|