hato-plugin-ikachan 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +11 -0
- data/hato-plugin-ikachan.gemspec +29 -0
- data/lib/hato/plugin/ikachan.rb +48 -0
- data/lib/hato/plugin/ikachan/version.rb +10 -0
- data/spec/lib/hato/plugin/ikachan_spec.rb +117 -0
- data/spec/spec_helper.rb +4 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73f921780dd1ecda43a1f03122e1b330da2a2dba
|
4
|
+
data.tar.gz: 3f564113ce2c019c79bf9ac930f5b56da1840ad2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d68a4899cc845e944d3a2ed61f84091318f7b095aa838d8f25d51d6a222a57881f827de5812c78c71ba5f45e02a82ed08f661bc5a3d27e839a7763c790bef3b
|
7
|
+
data.tar.gz: 1ba3d50636e391f3dd9946bb0e80b8776bb5f9f59389d20a2d7b0ec7b24501b8007a00f94902d7ce72f905dca2af037b1370aeeb8c0afd9330b96f122049ed19
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kentaro Kuribayashi
|
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,49 @@
|
|
1
|
+
# Hato::Plugin::Ikachan [![BuildStatus](https://secure.travis-ci.org/kentaro/hato-plugin-ikachan.png)](http://travis-ci.org/kentaro/hato-plugin-ikachan)
|
2
|
+
|
3
|
+
This plugin provides a method to send messages via [Ikachan](https://metacpan.org/release/App-Ikachan).
|
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 'Ikachan' do
|
17
|
+
scheme 'http'
|
18
|
+
host 'irc.example.com'
|
19
|
+
port 4979
|
20
|
+
channel %w[hato pigeon],
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# ...
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
gem 'hato-plugin-ikachan'
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
$ gem install hato-plugin-ikachan
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
49
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
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/ikachan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hato-plugin-ikachan"
|
8
|
+
spec.version = Hato::Plugin::Ikachan::VERSION
|
9
|
+
spec.authors = ["Kentaro Kuribayashi"]
|
10
|
+
spec.email = ["kentarok@gmail.com"]
|
11
|
+
spec.description = %q{Hato plugin to send messages via Ikachan}
|
12
|
+
spec.summary = %q{Hato plugin to send messages via Ikachan}
|
13
|
+
spec.homepage = "https://github.com/kentaro/hato-plugin-ikachan"
|
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
|
29
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'hato/plugin'
|
2
|
+
require 'hato/plugin/ikachan/version'
|
3
|
+
|
4
|
+
require 'uri'
|
5
|
+
require 'net/http'
|
6
|
+
|
7
|
+
module Hato
|
8
|
+
module Plugin
|
9
|
+
class Ikachan < Base
|
10
|
+
def notify(args)
|
11
|
+
channel = config.channel
|
12
|
+
channel = [channel] if channel.is_a?(String)
|
13
|
+
|
14
|
+
channel.each do |c|
|
15
|
+
send_message(:join, c)
|
16
|
+
send_message(:notice, c, args[:message])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def send_message(action, channel, message='')
|
23
|
+
url = '%s://%s:%s/%s' % [
|
24
|
+
config.scheme || 'http',
|
25
|
+
config.host,
|
26
|
+
config.port || 4979,
|
27
|
+
action.to_s,
|
28
|
+
]
|
29
|
+
params = {
|
30
|
+
'channel' => "##{channel}",
|
31
|
+
'message' => message,
|
32
|
+
}
|
33
|
+
|
34
|
+
res = send_request(url, params)
|
35
|
+
res.value
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_requiest(url, params)
|
39
|
+
http = Net::HTTP.new(URI(url).host, URI(url).port)
|
40
|
+
req = Net::HTTP::Post.new(URI(url).path)
|
41
|
+
req.form_data = params
|
42
|
+
|
43
|
+
http.request(req)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
require 'hato/config'
|
3
|
+
|
4
|
+
describe Hato::Plugin::Ikachan do
|
5
|
+
describe '#notify' do
|
6
|
+
context 'arguments' do
|
7
|
+
context 'channel' do
|
8
|
+
context 'when channel is passed as a string' do
|
9
|
+
subject {
|
10
|
+
described_class.new(
|
11
|
+
Hato::Config::Plugin.new('Ikachan') {
|
12
|
+
scheme 'example.com'
|
13
|
+
channel 'test'
|
14
|
+
}
|
15
|
+
)
|
16
|
+
}
|
17
|
+
before {
|
18
|
+
allow(subject).to receive(:send_message)
|
19
|
+
}
|
20
|
+
|
21
|
+
it {
|
22
|
+
expect(subject).to receive(:send_message).exactly(2).times
|
23
|
+
subject.notify(tag: 'test', message: 'test')
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when channel is passed as an array' do
|
28
|
+
subject {
|
29
|
+
described_class.new(
|
30
|
+
Hato::Config::Plugin.new('Ikachan') {
|
31
|
+
scheme 'example.com'
|
32
|
+
channel %w[test1 test2]
|
33
|
+
}
|
34
|
+
)
|
35
|
+
}
|
36
|
+
before {
|
37
|
+
allow(subject).to receive(:send_message)
|
38
|
+
}
|
39
|
+
|
40
|
+
it {
|
41
|
+
expect(subject).to receive(:send_message).exactly(4).times
|
42
|
+
subject.notify(tag: 'test', message: 'test')
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'success' do
|
49
|
+
subject {
|
50
|
+
described_class.new(
|
51
|
+
Hato::Config::Plugin.new('Ikachan') {
|
52
|
+
scheme 'example.com'
|
53
|
+
channel 'test'
|
54
|
+
}
|
55
|
+
)
|
56
|
+
}
|
57
|
+
before {
|
58
|
+
allow(subject).to receive(:send_request).and_return(
|
59
|
+
Net::HTTPSuccess.new('1.1', '200', 'success')
|
60
|
+
)
|
61
|
+
}
|
62
|
+
|
63
|
+
it {
|
64
|
+
expect {
|
65
|
+
subject.notify(tag: 'test', message: 'test')
|
66
|
+
}.not_to raise_error
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'failure' do
|
71
|
+
context 'network error' do
|
72
|
+
subject {
|
73
|
+
described_class.new(
|
74
|
+
Hato::Config::Plugin.new('Ikachan') {
|
75
|
+
scheme 'example.com'
|
76
|
+
channel 'test'
|
77
|
+
}
|
78
|
+
)
|
79
|
+
}
|
80
|
+
before {
|
81
|
+
allow(subject).to receive(:send_request).and_raise(
|
82
|
+
Timeout::Error.new('timeout')
|
83
|
+
)
|
84
|
+
}
|
85
|
+
|
86
|
+
it {
|
87
|
+
expect {
|
88
|
+
subject.notify(tag: 'test', message: 'test')
|
89
|
+
}.to raise_error(Timeout::Error)
|
90
|
+
}
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'http error' do
|
94
|
+
subject {
|
95
|
+
described_class.new(
|
96
|
+
Hato::Config::Plugin.new('Ikachan') {
|
97
|
+
scheme 'example.com'
|
98
|
+
channel 'text'
|
99
|
+
}
|
100
|
+
)
|
101
|
+
}
|
102
|
+
before {
|
103
|
+
allow(subject).to receive(:send_request).and_return(
|
104
|
+
Net::HTTPServerError.new('1.1', '500', 'forbidden')
|
105
|
+
)
|
106
|
+
}
|
107
|
+
|
108
|
+
it {
|
109
|
+
expect {
|
110
|
+
subject.notify(tag: 'test', message: 'test')
|
111
|
+
}.to raise_error(Net::HTTPFatalError)
|
112
|
+
}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hato-plugin-ikachan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kentaro Kuribayashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-17 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 Ikachan
|
70
|
+
email:
|
71
|
+
- kentarok@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- hato-plugin-ikachan.gemspec
|
83
|
+
- lib/hato/plugin/ikachan.rb
|
84
|
+
- lib/hato/plugin/ikachan/version.rb
|
85
|
+
- spec/lib/hato/plugin/ikachan_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/kentaro/hato-plugin-ikachan
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 1.9.2
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Hato plugin to send messages via Ikachan
|
111
|
+
test_files:
|
112
|
+
- spec/lib/hato/plugin/ikachan_spec.rb
|
113
|
+
- spec/spec_helper.rb
|