guard-webhook-notifier 0.0.1

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: ac3cc2f1445cf3f0e6744e0644706bb3a4f12d4e
4
+ data.tar.gz: a791b8a82874d5478eb9456a2bdbd1cd428cafaa
5
+ SHA512:
6
+ metadata.gz: fdd73cdb1749c20408b14a6a58eff097a8b8b81975a405ca5a090a48555ea3b3c8d82aa42f018993896c0ca913b31902fa5f2f90ac66cfca5852111d47796bcc
7
+ data.tar.gz: 004ad9caeb4f9a3558ea926a02b8ba2a5c0b7b600c14049b06c8fda0e5b90faf22768f2d449e5aa034824fbb932dc8a06e76127f33d99c7426a54faedc5b5287
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-webhook-notifier.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuku Takahashi
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,67 @@
1
+ [![Build Status](https://travis-ci.org/yuku-t/guard-webhook-notifier.svg?branch=master)](https://travis-ci.org/yuku-t/guard-webhook-notifier)
2
+
3
+ # NAME
4
+
5
+ `GuardWebHookNotifier` - Notify Guard Events by HTTP POST Requests.
6
+
7
+ # SYNOPSIS
8
+
9
+ ```rb
10
+ # Guardfile
11
+
12
+ require 'guard-webhook-notifier'
13
+ GuardWebHookNotifier.register
14
+
15
+ guard 'rspec' do
16
+ watch(%r{spec/.+_spec\.rb$})
17
+ notification :webhook, url: 'http://10.0.2.2:4001'
18
+ end
19
+ ```
20
+
21
+ ## Server Example
22
+
23
+ ```rb
24
+ # Running on OS X machine.
25
+
26
+ require 'listen'
27
+ require 'terminal-notifier'
28
+ require 'json'
29
+ require 'webrick'
30
+
31
+ # Forwarding events to Vagrant over TCP.
32
+ listener = Listen.to './', forward_to: '127.0.0.1:4000'
33
+
34
+ # HTTP server.
35
+ server = WEBrick::HTTPServer.new(Port: 4001)
36
+
37
+ # Handle POST requests sent from guard-webhook-notifier in Vagrant.
38
+ class TerminalNotifierServlet <
39
+ def do_POST(req, res)
40
+ json = JSON.parse(req.body)
41
+ message = json['message']
42
+ opts = json['options']
43
+ # Show notification.
44
+ TerminalNotifier.notify(message, title: opts['title'])
45
+ res.status = 200
46
+ end
47
+ end
48
+ server.mount('/', TerminalNotifierServlet)
49
+
50
+ trap 'INT' do
51
+ listener.stop
52
+ server.shutdown
53
+ end
54
+
55
+ listener.start
56
+ server.start
57
+ ```
58
+
59
+ # INSTALLATION
60
+
61
+ ```bash
62
+ gem install guard-webhook-notifier
63
+ ```
64
+
65
+ # LICENSE
66
+
67
+ This software is licensed under [MIT license](https://github.com/yuku-t/guard-webhook-notifier/tree/master/LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new("spec")
5
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "guard-webhook-notifier/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "guard-webhook-notifier"
7
+ spec.version = GuardWebHookNotifier::VERSION
8
+ spec.authors = ["Yuku Takahashi"]
9
+ spec.email = ["taka84u9@gmail.com"]
10
+ spec.summary = "Notify Guard Events by HTTP POST Requests"
11
+ spec.homepage = "https://github.com/yuku-t/guard-webhook-notifier"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "faraday", "~> 0.8"
20
+ spec.add_dependency "guard", "~> 2.8"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "webmock"
26
+ end
@@ -0,0 +1,10 @@
1
+ require "guard/notifier"
2
+
3
+ module GuardWebHookNotifier
4
+ require "guard-webhook-notifier/version"
5
+ require "guard-webhook-notifier/notifier"
6
+
7
+ def register(name = 'webhook')
8
+ Guard::Notifier::NOTIFIERS << { name => Notifier }
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ require "faraday"
2
+ require "guard/notifiers/base"
3
+ require "json"
4
+
5
+ module GuardWebHookNotifier
6
+ class Notifier < Guard::Notifier::Base
7
+ DEFAULTS = {
8
+ user_agent: "GuardWebHookNotifier/#{VERSION}",
9
+ url: "http://10.0.2.2:4001/"
10
+ }
11
+
12
+ def initialize(opts = {})
13
+ super
14
+ @options = DEFAULTS.merge(opts)
15
+ end
16
+
17
+ def notify(message, opts = {})
18
+ super
19
+ conn = Faraday.new(url: opts[:url])
20
+ conn.post do |req|
21
+ req.headers["Content-Type"] = "application/json"
22
+ req.headers["User-Agent"] = opts[:user_agent]
23
+ req.body = { message: message, options: opts }.to_json
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module GuardWebHookNotifier
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe GuardWebHookNotifier::Notifier do
4
+ it { should be_a(Guard::Notifier::Base) }
5
+
6
+ describe "#notify" do
7
+ subject do
8
+ notifier.notify(message)
9
+ end
10
+
11
+ let(:notifier) do
12
+ described_class.new(url: "http://10.0.2.2:4001")
13
+ end
14
+
15
+ let(:message) do
16
+ "message"
17
+ end
18
+
19
+ it 'sends a POST request with given message' do
20
+ stub = stub_request(:post, '10.0.2.2:4001').with(
21
+ body: /"message":"#{message}"/,
22
+ headers: {
23
+ "Content-Type" => "application/json",
24
+ "User-Agent" => "GuardWebHookNotifier/#{GuardWebHookNotifier::VERSION}"
25
+ }
26
+ )
27
+ subject
28
+ expect(stub).to have_been_requested.once
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ require "guard-webhook-notifier"
2
+ require "webmock/rspec"
3
+
4
+ RSpec.configure do |config|
5
+ config.color = true
6
+ config.run_all_when_everything_filtered = true
7
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-webhook-notifier
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuku Takahashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - taka84u9@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - guard-webhook-notifier.gemspec
111
+ - lib/guard-webhook-notifier.rb
112
+ - lib/guard-webhook-notifier/notifier.rb
113
+ - lib/guard-webhook-notifier/version.rb
114
+ - spec/guard-webhook-notifier/notifier_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: https://github.com/yuku-t/guard-webhook-notifier
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Notify Guard Events by HTTP POST Requests
140
+ test_files:
141
+ - spec/guard-webhook-notifier/notifier_spec.rb
142
+ - spec/spec_helper.rb