irc-notify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b1f6125a6fb0e594d0764e5c49127fc3252042e
4
+ data.tar.gz: 2b5358bb0523a3e30e7d0a0ba5421498d411f450
5
+ SHA512:
6
+ metadata.gz: 066e0cafa15cc4606f837c2875c6437cebf0c89b8c25becb5046c374a23fadbe325caad4d0bccc2268b6c7665ad343f06e84b3ab36d29b7a55978ce016cffc69
7
+ data.tar.gz: ab6dc383aa63ed3d9bd8e2cc3586f46ebc4781be6f129ace5f513fddeacb7f74c88a0b0827c614934b40b79a8a3cf2e691b41b4508262311bada125869f94dc0
@@ -0,0 +1 @@
1
+ Gemfile.lock
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-2.1.1
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ platform :rbx do
6
+ gem "rubysl"
7
+ end
@@ -0,0 +1,10 @@
1
+ guard "bundler" do
2
+ watch("Gemfile")
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec, cli: "-fs --color --order rand" do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/irc-notify/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch("spec/spec_helper.rb") { "spec" }
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Henrik Hodne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ irc-notify
2
+ ==========
3
+
4
+ irc-notify is a very small IRC library meant for publishing notifications to
5
+ IRC. It's used by [Travis CI](https://travis-ci.org) to publish IRC
6
+ notifications.
7
+
8
+ Basic example
9
+ -------------
10
+
11
+ ``` Ruby
12
+ require "irc-notify"
13
+ client = IrcNotify::Client.build("irc.example.com", 6697, ssl: true)
14
+
15
+ client.register("nick")
16
+ client.notify("#channel", "Hello, world!")
17
+ client.quit
18
+ ```
19
+
20
+ Installation
21
+ ------------
22
+
23
+ $ gem install irc-notify
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "irc-notify/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "irc-notify"
8
+ spec.version = IrcNotify::VERSION
9
+ spec.authors = ["Henrik Hodne"]
10
+ spec.email = ["henrik@hodne.io"]
11
+ spec.description = "irc-notify is a minimal library for publishing IRC notifications"
12
+ spec.summary = "irc-notify is a minimal library for publishing IRC notifications"
13
+ spec.homepage = "https://github.com/henrikhodne/irc-notify"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^spec/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "guard"
24
+ spec.add_development_dependency "guard-bundler"
25
+ spec.add_development_dependency "guard-rspec"
26
+ end
@@ -0,0 +1,5 @@
1
+ require "irc-notify/version"
2
+ require "irc-notify/client"
3
+
4
+ module IrcNotify
5
+ end
@@ -0,0 +1,89 @@
1
+ module IrcNotify
2
+ class Client
3
+ def self.build(host, port = 6667, options = {})
4
+ require "socket"
5
+ socket = TCPSocket.new(host, port)
6
+ if options[:ssl]
7
+ require "openssl"
8
+ ssl_context = OpenSSL::SSL::SSLContext.new
9
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
10
+ socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context).tap do |sock|
11
+ sock.sync = true
12
+ sock.connect
13
+ end
14
+ end
15
+
16
+ new(socket)
17
+ end
18
+
19
+ def initialize(socket)
20
+ @socket = socket
21
+ end
22
+
23
+ def register(nick, options = {})
24
+ print("PASS #{options[:password]}") if options[:password]
25
+ print("NICK #{nick}")
26
+ print("USER #{nick} * * :#{nick}")
27
+
28
+ loop do
29
+ case @socket.gets
30
+ when /00[1-4] #{Regexp.escape(nick)}/
31
+ break
32
+ when /^PING\s*:\s*(.*)$/
33
+ print("PONG #{$1}")
34
+ end
35
+ end
36
+
37
+ identify_nickserv(options[:nickserv_password]) if options[:nickserv_password]
38
+ end
39
+
40
+ def notify(channel, message, options = {})
41
+ join(channel, options[:channel_key]) if options.fetch(:join, true)
42
+ if options[:notice]
43
+ notice(channel, message)
44
+ else
45
+ privmsg(channel, message)
46
+ end
47
+ end
48
+
49
+ def quit(message = nil)
50
+ message = " :#{message}" if message
51
+ print("QUIT#{message}")
52
+ @socket.gets until @socket.eof?
53
+ end
54
+
55
+ private
56
+
57
+ def identify_nickserv(password)
58
+ privmsg("NickServ", "IDENTIFY #{password}")
59
+ loop do
60
+ case @socket.gets
61
+ when /^:NickServ/i
62
+ break
63
+ when /^PING\s*:\s*(.*)$/
64
+ print("PONG #{$1}")
65
+ end
66
+ end
67
+ end
68
+
69
+ def privmsg(receiver, message)
70
+ print("PRIVMSG #{receiver} :#{message}")
71
+ end
72
+
73
+ def notice(receiver, message)
74
+ print("NOTICE #{receiver} :#{message}")
75
+ end
76
+
77
+ def join(channel, key = nil)
78
+ if key
79
+ print("JOIN #{channel} #{key}")
80
+ else
81
+ print("JOIN #{channel}")
82
+ end
83
+ end
84
+
85
+ def print(line)
86
+ @socket.print("#{line}\r\n")
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,3 @@
1
+ module IrcNotify
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,84 @@
1
+ require "spec_helper"
2
+
3
+ describe IrcNotify::Client do
4
+ let(:nick) { "Bob" }
5
+ let(:socket) { double("socket", print: nil, gets: "001 #{nick}") }
6
+ subject(:client) { described_class.new(socket) }
7
+
8
+ describe "#register" do
9
+ it "sends NICK and USER" do
10
+ expect(socket).to receive(:print).with("NICK #{nick}\r\n").ordered
11
+ expect(socket).to receive(:print).with("USER #{nick} * * :#{nick}\r\n").ordered
12
+
13
+ client.register(nick)
14
+ end
15
+
16
+ context "with password" do
17
+ it "sends PASS before NICK and USER" do
18
+ expect(socket).to receive(:print).with("PASS foobar\r\n").ordered
19
+ expect(socket).to receive(:print).with("NICK #{nick}\r\n").ordered
20
+ expect(socket).to receive(:print).with("USER #{nick} * * :#{nick}\r\n").ordered
21
+
22
+ client.register(nick, password: "foobar")
23
+ end
24
+ end
25
+
26
+ context "with NickServ password" do
27
+ before(:each) do
28
+ allow(socket).to receive(:gets).and_return("001 #{nick}", ":NickServ foo")
29
+ end
30
+
31
+ it "messages NickServ with password" do
32
+ expect(socket).to receive(:print).with("NICK #{nick}\r\n").ordered
33
+ expect(socket).to receive(:print).with("USER #{nick} * * :#{nick}\r\n").ordered
34
+ expect(socket).to receive(:print).with("PRIVMSG NickServ :IDENTIFY foobar\r\n")
35
+
36
+ client.register(nick, nickserv_password: "foobar")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#notify" do
42
+ it "joins the channel" do
43
+ client.notify("#channel", "hello, world!")
44
+ expect(socket).to have_received(:print).with("JOIN #channel\r\n")
45
+ end
46
+
47
+ it "sends the message" do
48
+ client.notify("#channel", "Hello, world!")
49
+ expect(socket).to have_received(:print).with("PRIVMSG #channel :Hello, world!\r\n")
50
+ end
51
+
52
+ context "with a channel key" do
53
+ it "joins the channel with the key" do
54
+ client.notify("#channel", "Hello, world!", channel_key: "foobar")
55
+ expect(socket).to have_received(:print).with("JOIN #channel foobar\r\n")
56
+ end
57
+ end
58
+
59
+ context "when enabling :notice flag" do
60
+ it "sends a notice" do
61
+ client.notify("#channel", "Hello, world!", notice: true)
62
+ expect(socket).to have_received(:print).with("NOTICE #channel :Hello, world!\r\n")
63
+ end
64
+ end
65
+
66
+ context "when passing join: false" do
67
+ it "does not join the channel" do
68
+ client.notify("#channel", "hello, world!", join: false)
69
+ expect(socket).not_to have_received(:print).with(match(/^JOIN/))
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "#quit" do
75
+ before(:each) do
76
+ allow(socket).to receive(:eof?).and_return(true)
77
+ end
78
+
79
+ it "sends the command" do
80
+ client.quit("Goodbye")
81
+ expect(socket).to have_received(:print).with("QUIT :Goodbye\r\n")
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ GEM_ROOT = File.expand_path("../../", __FILE__)
2
+ $:.unshift(File.join(GEM_ROOT, "lib"))
3
+
4
+ require "irc-notify"
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irc-notify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Henrik Hodne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ type: :development
15
+ name: bundler
16
+ prerelease: false
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ type: :development
29
+ name: rake
30
+ prerelease: false
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ type: :development
43
+ name: rspec
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ type: :development
57
+ name: guard
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ name: guard-bundler
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ type: :development
85
+ name: guard-rspec
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: irc-notify is a minimal library for publishing IRC notifications
98
+ email:
99
+ - henrik@hodne.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - Guardfile
108
+ - LICENSE
109
+ - README.markdown
110
+ - Rakefile
111
+ - irc-notify.gemspec
112
+ - lib/irc-notify.rb
113
+ - lib/irc-notify/client.rb
114
+ - lib/irc-notify/version.rb
115
+ - spec/client_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://github.com/henrikhodne/irc-notify
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.1.5
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: irc-notify is a minimal library for publishing IRC notifications
141
+ test_files:
142
+ - spec/client_spec.rb
143
+ - spec/spec_helper.rb