hato-plugin-hipchat 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: a759419d5ecb4e6223b6e8ced4ac2d318a5a3ef7
4
+ data.tar.gz: 07ba929b716274dc0ac1e8c7e7ef6e8e29b41f81
5
+ SHA512:
6
+ metadata.gz: bc90c87f97bc56242410baca26f845246d0d9d3d63d9e412dae7c6f893f531476814b13c5612014337812dc6b6123be566aec6eff9fcdfe1ae1981d1b5fa95e9
7
+ data.tar.gz: 70d6345fd12d8f4ca25fc8979f9fe37cf081b577d849d57b9adce774eb2e568e829b442279337bfc7bf04aba5aac5ba8c4731fad9b1681d26fd7cb4a4eb732a7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hato-plugin-hipchat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kohei Hasegawa
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,47 @@
1
+ # Hato::Plugin::Hipchat
2
+
3
+ This plugin provides a method to send messages via [HipChat](https://www.hipchat.com/).
4
+
5
+ ## Configuration
6
+
7
+ ```ruby
8
+ Hato::Config.define do
9
+ api_key 'test'
10
+ host '0.0.0.0'
11
+ port 9699
12
+
13
+ # ...
14
+
15
+ tag 'test' do
16
+ plugin 'Hipchat' do
17
+ auth_token 'yes your secret token here'
18
+ room %w[hato pigeon]
19
+ from 'hato-bot'
20
+ end
21
+ end
22
+
23
+ # ...
24
+ end
25
+ ```
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ gem 'hato-plugin-hipchat'
32
+
33
+ And then execute:
34
+
35
+ $ bundle
36
+
37
+ Or install it yourself as:
38
+
39
+ $ gem install hato-plugin-hipchat
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ spec.ruby_opts = %w[-w]
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hato/plugin/hipchat/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hato-plugin-hipchat"
8
+ spec.version = Hato::Plugin::Hipchat::VERSION
9
+ spec.authors = ["Kohei Hasegawa"]
10
+ spec.email = ["ameutau@gmail.com"]
11
+ spec.description = %q{Hato plugin to send messages via HipChat}
12
+ spec.summary = %q{Hato plugin to send messages via HipChat}
13
+ spec.homepage = "https://github.com/banyan/hato-plugin-hipchat"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = '>= 1.9.2'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "hato"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'hato/plugin'
2
+ require "hato/plugin/hipchat/version"
3
+
4
+ require 'uri'
5
+ require 'net/http'
6
+
7
+ module Hato
8
+ module Plugin
9
+ class Hipchat < Base
10
+ def notify(args)
11
+ room = config.room
12
+ room = [room] if room.is_a?(String)
13
+
14
+ room.each do |r|
15
+ send_message(r, args[:message])
16
+ end
17
+ end
18
+
19
+ protected
20
+
21
+ def send_message(room, message = '')
22
+ url = 'https://api.hipchat.com/v1/rooms/message?auth_token=%s&format=json' % config.auth_token
23
+ params = {
24
+ 'room_id' => room,
25
+ 'message' => message,
26
+ 'color' => config.color || 'green',
27
+ 'from' => config.from || 'hato',
28
+ 'notify' => config.notify || 0
29
+ }
30
+ send_request(url, params)
31
+ end
32
+
33
+ def send_request(url, params)
34
+ Net::HTTP.post_form URI.parse(url), params
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,9 @@
1
+ require 'hato/plugin'
2
+
3
+ module Hato
4
+ module Plugin
5
+ class Hipchat < Base
6
+ VERSION = "0.0.1"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,92 @@
1
+ require_relative '../../../spec_helper'
2
+ require 'hato/config'
3
+
4
+ describe Hato::Plugin::Hipchat do
5
+ describe '#notify' do
6
+ context 'arguments' do
7
+ context 'room' do
8
+ context 'when room is passed as a string' do
9
+ subject {
10
+ described_class.new(
11
+ Hato::Config::Plugin.new('Hipchat') {
12
+ room 'test'
13
+ }
14
+ )
15
+ }
16
+ before {
17
+ allow(subject).to receive(:send_message)
18
+ }
19
+
20
+ it {
21
+ expect(subject).to receive(:send_message).exactly(1).times
22
+ subject.notify(tag: 'test', message: 'test')
23
+ }
24
+ end
25
+
26
+ context 'when room is passed as an array' do
27
+ subject {
28
+ described_class.new(
29
+ Hato::Config::Plugin.new('Hipchat') {
30
+ room %w[test1 test2]
31
+ }
32
+ )
33
+ }
34
+ before {
35
+ allow(subject).to receive(:send_message)
36
+ }
37
+
38
+ it {
39
+ expect(subject).to receive(:send_message).exactly(2).times
40
+ subject.notify(tag: 'test', message: 'test')
41
+ }
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'success' do
47
+ subject {
48
+ described_class.new(
49
+ Hato::Config::Plugin.new('Hipchat') {
50
+ room 'test'
51
+ auth_token 'foobar'
52
+ }
53
+ )
54
+ }
55
+ before {
56
+ allow(subject).to receive(:send_request).and_return(
57
+ Net::HTTPSuccess.new('1.1', '200', 'success')
58
+ )
59
+ }
60
+
61
+ it {
62
+ expect {
63
+ subject.notify(tag: 'test', message: 'test')
64
+ }.not_to raise_error
65
+ }
66
+ end
67
+
68
+ context 'failure' do
69
+ context 'network error' do
70
+ subject {
71
+ described_class.new(
72
+ Hato::Config::Plugin.new('Hipchat') {
73
+ room 'test'
74
+ auth_token 'foobar'
75
+ }
76
+ )
77
+ }
78
+ before {
79
+ allow(subject).to receive(:send_request).and_raise(
80
+ Timeout::Error.new('timeout')
81
+ )
82
+ }
83
+
84
+ it {
85
+ expect {
86
+ subject.notify(tag: 'test', message: 'test')
87
+ }.to raise_error(Timeout::Error)
88
+ }
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../lib/hato/plugin/hipchat'
2
+
3
+ RSpec.configure do |config|
4
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hato-plugin-hipchat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kohei Hasegawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hato
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
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Hato plugin to send messages via HipChat
70
+ email:
71
+ - ameutau@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - hato-plugin-hipchat.gemspec
82
+ - lib/hato/plugin/hipchat.rb
83
+ - lib/hato/plugin/hipchat/version.rb
84
+ - spec/lib/hato/plugin/hipchat_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/banyan/hato-plugin-hipchat
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 1.9.2
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Hato plugin to send messages via HipChat
110
+ test_files:
111
+ - spec/lib/hato/plugin/hipchat_spec.rb
112
+ - spec/spec_helper.rb