quandl-slack 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +98 -4
- data/lib/quandl/slack/base.rb +5 -15
- data/lib/quandl/slack/generate.rb +12 -9
- data/lib/quandl/slack/version.rb +1 -1
- data/spec/fixtures/{dummy_app.rb → dummy_rails_app/application.rb} +0 -0
- data/spec/fixtures/{config → dummy_rails_app/config}/quandl/slack.yml +2 -2
- data/spec/quandl-slack_spec.rb +16 -3
- data/spec/spec_helper.rb +0 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 356d7eace5bf48dcb2cda29b4c0ef8d8e222643e
|
4
|
+
data.tar.gz: 066f85286302129f33e9194027e90557deb63d03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ec958b672dfc8a2d10c539f9985e7e4e03e16762e33e28c76b9d8010822b6311924cab58dbe1d5cd21353b924930079d36ce4643a54b4f11a1f4c7ce21ea147
|
7
|
+
data.tar.gz: 9ecd92f54ab700b2422c7905c42946092dee8b7bff3b528d7d13e499fa58a7ccbd4ccf3be2df32bdc19617d0f4985f6a5045ef5850087f0a3ce14c055f39a2ab
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Quandl::Slack
|
2
2
|
|
3
|
-
|
3
|
+
Use this gem to automatically generate Slack notifiers for you, or to quickly generate them on the fly.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -16,9 +16,103 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install quandl_slack
|
18
18
|
|
19
|
-
##
|
19
|
+
## Generating your notifiers
|
20
20
|
|
21
|
-
|
21
|
+
### Automatically
|
22
|
+
|
23
|
+
First, create a `slack.yml` file and place it in `config/quandl` in your project's root folder:
|
24
|
+
```YAML
|
25
|
+
defaults: &defaults
|
26
|
+
webhook_url: https://hooks.slack.com/services/fake/fake/fake
|
27
|
+
notifiers: &default_notifiers
|
28
|
+
asset_management:
|
29
|
+
channel: '#releases'
|
30
|
+
username: Next Asset Deployer
|
31
|
+
icon_emoji: ':airplane:'
|
32
|
+
stripe:
|
33
|
+
channel: '#stripe-testing'
|
34
|
+
username: stripe
|
35
|
+
icon_url: 'http://lorempixel.com/48/48'
|
36
|
+
ci:
|
37
|
+
channel: <%= ENV.fetch('SLACK_CHANNEL', "'#development'") %>
|
38
|
+
|
39
|
+
development:
|
40
|
+
<<: *defaults
|
41
|
+
|
42
|
+
staging:
|
43
|
+
<<: *defaults
|
44
|
+
|
45
|
+
test:
|
46
|
+
<<: *defaults
|
47
|
+
|
48
|
+
vagrant:
|
49
|
+
<<: *defaults
|
50
|
+
|
51
|
+
vagrant_test:
|
52
|
+
<<: *defaults
|
53
|
+
|
54
|
+
vagrant_staging:
|
55
|
+
<<: *defaults
|
56
|
+
|
57
|
+
production:
|
58
|
+
<<: *defaults
|
59
|
+
subclasses:
|
60
|
+
<<: *default_notifiers
|
61
|
+
stripe:
|
62
|
+
channel: '#stripe-events'
|
63
|
+
username: stripe
|
64
|
+
```
|
65
|
+
|
66
|
+
Then call `Quandl::Slack.autogenerate_notifiers` in an initializer. In the example above, you will get three notifiers:
|
67
|
+
- `Quandl::Slack::AssetManagement`
|
68
|
+
- `Quandl::Slack::Stripe`
|
69
|
+
- `Quandl::Slack::Ci`
|
70
|
+
|
71
|
+
### Manually and individually
|
72
|
+
|
73
|
+
#### Provide the webhook
|
74
|
+
|
75
|
+
Every Slack notifier needs a webook. Normally, you would use the same one throughout the project, and customize the channel, username and icon on a per-notifier basis.
|
76
|
+
|
77
|
+
To provide the webhook, either set the `ENV['SLACK_WEBHOOK']` environment variable:
|
78
|
+
```Ruby
|
79
|
+
ENV['SLACK_WEBHOOK'] = 'https://hooks.slack.com/services/XXX/YYYY/ZZZ'
|
80
|
+
```
|
81
|
+
OR
|
82
|
+
|
83
|
+
Create a `config/quandl/slack.yml` file with a `webhook_url` node and call:
|
84
|
+
```Ruby
|
85
|
+
Quandl::Slack.extend(Quandl::Configurable)
|
86
|
+
```
|
87
|
+
|
88
|
+
#### Provide the environment
|
89
|
+
|
90
|
+
If your project is a Rails app or you're using `ENV['SLACK_WEBHOOK']` to set the webhook URL, you don't need to do anything.
|
91
|
+
|
92
|
+
If your project is NOT a Rails app and you're using a config file to set the webhook URL, you will also need to let `Quandl::Slack` know what the environment is, so it knows which node in the `config` file to use. You can provide the environment using the `ENV['RAILS_ENV']` or `ENV['RAKE_ENV']` environment variable. If you do not, the `default` environment will be assumed.
|
93
|
+
|
94
|
+
#### Generate the notifier!
|
95
|
+
|
96
|
+
```Ruby
|
97
|
+
Quandl::Slack.generate_notifier('your_notifier', customizations_hash)
|
98
|
+
```
|
99
|
+
|
100
|
+
## Available customizations:
|
101
|
+
These can be placed in the yml file when autogenerating notifiers, or passed to `generate_notifier` when manually generating an individual notifier:
|
102
|
+
|
103
|
+
key | example value | notes
|
104
|
+
------- | ----------- | ----
|
105
|
+
`channel` | `'#development'` | remember the hash
|
106
|
+
`icon_url` | `http://lorempixel.com/200/200/people/` |
|
107
|
+
`icon_emoji` | `':alien:'` | see [emoji cheat sheet](http://www.emoji-cheat-sheet.com/)
|
108
|
+
`username` |`The Bot` |
|
109
|
+
|
110
|
+
## Pinging your notifiers
|
111
|
+
|
112
|
+
Simply call:
|
113
|
+
```ruby
|
114
|
+
Quandl::Slack::YourNotifier.ping('your message', additional_customizations_hash)
|
115
|
+
```
|
22
116
|
|
23
117
|
## Contributing
|
24
118
|
|
data/lib/quandl/slack/base.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
module Quandl
|
2
2
|
module Slack
|
3
|
-
extend Quandl::Configurable
|
4
|
-
|
5
3
|
class Base
|
6
4
|
attr_reader :client
|
7
5
|
|
8
6
|
def self.client
|
9
|
-
@client = ::Slack::Notifier.new
|
7
|
+
@client = ::Slack::Notifier.new webhook_url, customizations
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.webhook_url
|
11
|
+
ENV['SLACK_WEBHOOK'] || Quandl::Slack.configuration.webhook_url
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.customizations; end
|
@@ -15,17 +17,5 @@ module Quandl
|
|
15
17
|
client.ping(*args)
|
16
18
|
end
|
17
19
|
end
|
18
|
-
|
19
|
-
def self.generate_notifiers
|
20
|
-
configuration.notifiers.each do |subclass_name, subclass_customizations|
|
21
|
-
name = subclass_name.camelize
|
22
|
-
klass = Class.new(Quandl::Slack::Base) do
|
23
|
-
define_singleton_method :customizations do
|
24
|
-
subclass_customizations
|
25
|
-
end
|
26
|
-
end
|
27
|
-
const_set name, klass
|
28
|
-
end
|
29
|
-
end
|
30
20
|
end
|
31
21
|
end
|
@@ -1,17 +1,20 @@
|
|
1
1
|
module Quandl
|
2
2
|
module Slack
|
3
|
-
def self.
|
3
|
+
def self.autogenerate_notifiers
|
4
|
+
self.extend(Quandl::Configurable)
|
4
5
|
configuration.notifiers.each do |subclass_name, subclass_customizations|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
generate_notifier(subclass_name, subclass_customizations)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.generate_notifier(subclass_name, subclass_customizations={})
|
11
|
+
name = subclass_name.camelize
|
12
|
+
klass = Class.new(Quandl::Slack::Base) do
|
13
|
+
define_singleton_method :customizations do
|
14
|
+
subclass_customizations
|
10
15
|
end
|
11
|
-
const_set name, klass
|
12
16
|
end
|
17
|
+
const_set name, klass
|
13
18
|
end
|
14
19
|
end
|
15
20
|
end
|
16
|
-
|
17
|
-
Quandl::Slack.generate_notifiers
|
data/lib/quandl/slack/version.rb
CHANGED
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
defaults: &defaults
|
2
2
|
webhook_url: https://hooks.slack.com/services/fake/fake/fake
|
3
|
-
notifiers: &
|
3
|
+
notifiers: &default_notifiers
|
4
4
|
asset_management:
|
5
5
|
channel: '#releases'
|
6
6
|
username: Next Asset Deployer
|
@@ -33,7 +33,7 @@ vagrant_staging:
|
|
33
33
|
production:
|
34
34
|
<<: *defaults
|
35
35
|
subclasses:
|
36
|
-
<<: *
|
36
|
+
<<: *default_notifiers
|
37
37
|
stripe:
|
38
38
|
channel: '#stripe-events'
|
39
39
|
username: stripe
|
data/spec/quandl-slack_spec.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
|
+
require 'fixtures/dummy_rails_app/application'
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
describe Quandl::Slack do
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
describe '.autogenerate_notifiers' do
|
6
|
+
it 'autogenerates Slack::Notifier instances' do
|
7
|
+
Quandl::Slack.autogenerate_notifiers
|
8
|
+
expect(Quandl::Slack::AssetManagement.client).to be_kind_of(Slack::Notifier)
|
9
|
+
expect(Quandl::Slack::Ci.client.default_payload['channel']).to eq('#development')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.generate_notifier' do
|
14
|
+
it 'generates Slack::Notifier instance' do
|
15
|
+
ENV['SLACK_WEBHOOK'] = 'https://hooks.slack.com/services/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'
|
16
|
+
Quandl::Slack.generate_notifier('my_notifier', channel: '#stripe-testing', icon_emoji: ':christmas_tree:')
|
17
|
+
expect(Quandl::Slack::MyNotifier.client).to be_kind_of(Slack::Notifier)
|
18
|
+
expect(Quandl::Slack::MyNotifier.client.default_payload[:icon_emoji]).to eq(':christmas_tree:')
|
19
|
+
end
|
7
20
|
end
|
8
21
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quandl-slack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Najwa Azer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -183,8 +183,8 @@ files:
|
|
183
183
|
- lib/quandl/slack/generate.rb
|
184
184
|
- lib/quandl/slack/version.rb
|
185
185
|
- quandl-slack.gemspec
|
186
|
-
- spec/fixtures/
|
187
|
-
- spec/fixtures/
|
186
|
+
- spec/fixtures/dummy_rails_app/application.rb
|
187
|
+
- spec/fixtures/dummy_rails_app/config/quandl/slack.yml
|
188
188
|
- spec/quandl-slack_spec.rb
|
189
189
|
- spec/spec_helper.rb
|
190
190
|
homepage: ''
|
@@ -212,7 +212,7 @@ signing_key:
|
|
212
212
|
specification_version: 4
|
213
213
|
summary: Builds custom Slack notifiers from a quandl/slack.yml file.
|
214
214
|
test_files:
|
215
|
-
- spec/fixtures/
|
216
|
-
- spec/fixtures/
|
215
|
+
- spec/fixtures/dummy_rails_app/application.rb
|
216
|
+
- spec/fixtures/dummy_rails_app/config/quandl/slack.yml
|
217
217
|
- spec/quandl-slack_spec.rb
|
218
218
|
- spec/spec_helper.rb
|