pushpop-slack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95c1e8c6d65e28ab5b56fbffbaab716765a5a65c
4
+ data.tar.gz: b71d5f05bd60072218c44bd0b1e0f90877c7e5e4
5
+ SHA512:
6
+ metadata.gz: 6cc87d58208b7f74dc9a62c756622d50b9bd7acfd58744fbc6dcf3ff95290673ac47b45197359e4df23652066f194b5bc88bd38798e442924f40969137156afb
7
+ data.tar.gz: b027d47c17a68810e2b4d4a94ee257cdedaae9b04b2f1440644be313c0fb455718ff8dda0f3ed177a00bf0e85c357314f24aa8861f8e973f6cf2c5051dccd2e0
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+
4
+ rvm:
5
+ - 2.1.1
6
+
7
+ script:
8
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pushpop'
4
+ gem 'slack-notifier'
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Author Joe Wegner
2
+ Copyright (c) 2014 Keen Labs
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ ## pushpop-plugin
2
+
3
+ A template for creating [Pushpop](https://github.com/keenlabs/pushpop) plugins that can
4
+ be published as gems and easily included in Pushpop projects.
5
+
6
+ See [pushpop-github](https://github.com/pushpop-project/pushpop-github) for an example
7
+ of a plugin/gem.
8
+
9
+ ### Usage
10
+
11
+ Clone this repository, and rename it to pushpop-<plugin>, where plugin is the name of
12
+ what you're building. Update files and references to reflect your plugin name, and add your code.
13
+
14
+ For others to easily use your plugin, you'll want to create a Ruby gem. Once you have a Rubygems
15
+ account and are authorized, you can publish the gem:
16
+
17
+ ``` shell
18
+ $ gem build pushpop-<plugin>.gemspec
19
+ $ gem push pushpop-<plugin>-0.1.0.gem
20
+ ```
21
+
22
+ Users will then be able to use your plugin by including it in their Gemfile:
23
+
24
+ ``` ruby
25
+ gem 'pushpop'
26
+ gem 'pushpop-<plugin>'
27
+ ```
28
+
29
+ ### Contributing
30
+
31
+ Code and documentation issues and pull requests are welcome. Help us make this template as
32
+ useful as possible!
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ $stdout.sync = true
2
+
3
+ $: << File.join(File.dirname(__FILE__), './lib')
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ desc 'Run Rspec unit tests'
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ task default: :spec
13
+ rescue LoadError
14
+ end
15
+
16
+
@@ -0,0 +1,5 @@
1
+ module Pushpop
2
+ class Slack
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,72 @@
1
+ require 'pushpop'
2
+ require 'slack-notifier'
3
+
4
+ WEBHOOK_URL = ENV['SLACK_WEBHOOK_URL']
5
+
6
+ module Pushpop
7
+
8
+ class Slack < Step
9
+
10
+ PLUGIN_NAME = 'slack'
11
+
12
+ Pushpop::Job.register_plugin(PLUGIN_NAME, self)
13
+
14
+ attr_accessor :_channel
15
+ attr_accessor :_username
16
+ attr_accessor :_message
17
+
18
+ def run(last_response=nil, step_responses=nil)
19
+
20
+ configure(last_response, step_responses)
21
+
22
+ unless _message
23
+ raise 'Please set the message to send to Slack'
24
+ end
25
+
26
+ send_message
27
+
28
+ end
29
+
30
+ def send_message
31
+ notifier = ::Slack::Notifier.new WEBHOOK_URL
32
+
33
+ notifier.ping _message, options
34
+ end
35
+
36
+ def options
37
+ opts = {}
38
+
39
+ if _channel
40
+ if _channel[0] == '#'
41
+ opts['channel'] = _channel
42
+ else
43
+ opts['channel'] = "##{_channel}"
44
+ end
45
+ end
46
+
47
+ if _username
48
+ opts['username'] = _username
49
+ end
50
+
51
+ return opts
52
+ end
53
+
54
+ def channel(channel)
55
+ self._channel = channel
56
+ end
57
+
58
+ def username(username)
59
+ self._username = username
60
+ end
61
+
62
+ def message(message)
63
+ self._message = message
64
+ end
65
+
66
+ def configure(last_response=nil, step_responses=nil)
67
+ self.instance_exec(last_response, step_responses, &block)
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'pushpop-slack/version'
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "pushpop-slack"
8
+ s.version = Pushpop::Slack::VERSION
9
+ s.authors = ["Joe Wegner"]
10
+ s.email = "joe@keen.io"
11
+ s.homepage = "https://github.com/pushpop-project/pushpop-slack"
12
+ s.summary = "Send messages to Slack via Pushpop!"
13
+ s.description = "pushpop-slack allows you to send messages to your slack channel inside of a Pushpop job"
14
+
15
+ s.add_dependency "pushpop"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
22
+
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushpop::Slack do
4
+ it 'should make sure there is a message' do
5
+ step = Pushpop::Slack.new do
6
+ message 'test'
7
+ end
8
+
9
+ expect{step.run}.to raise_error
10
+ end
11
+
12
+ it 'should prepend a # to the channel if its not there' do
13
+ step = Pushpop::Slack.new do
14
+ channel 'test'
15
+ end
16
+
17
+ step.options['channel'].should eq('#test')
18
+ end
19
+
20
+ it 'should not prepend a # to the channel if its already there' do
21
+ step = Pushpop::Slack.new do
22
+ channel '#test'
23
+ end
24
+
25
+ step.options['channel'].should eq('#test')
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ $: << File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ require 'pushpop'
4
+ require 'pushpop-plugin'
5
+
6
+ RSpec.configure do |config|
7
+ config.before :each do
8
+ Pushpop.jobs.clear
9
+ end
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushpop-slack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Wegner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pushpop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: pushpop-slack allows you to send messages to your slack channel inside
28
+ of a Pushpop job
29
+ email: joe@keen.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - .travis.yml
36
+ - Gemfile
37
+ - LICENSE
38
+ - README.md
39
+ - Rakefile
40
+ - lib/pushpop-slack.rb
41
+ - lib/pushpop-slack/version.rb
42
+ - pushpop-slack.gemspec
43
+ - spec/pushpop-slack_spec.rb
44
+ - spec/spec_helper.rb
45
+ homepage: https://github.com/pushpop-project/pushpop-slack
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.0.14
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Send messages to Slack via Pushpop!
68
+ test_files:
69
+ - spec/pushpop-slack_spec.rb
70
+ - spec/spec_helper.rb