carrier-pigeon 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.org CHANGED
@@ -56,12 +56,4 @@ Identify with NickServ
56
56
  : :nickserv_password => "secret"
57
57
  : )
58
58
 
59
- Register (ping reply) prior to joining or messaging a channel
60
- (required for some private servers)
61
59
 
62
- : CarrierPigeon.send(
63
- : :uri => "irc://nick:password@irc.domain.com:6667/#channel",
64
- : :message => "cooooo, coo coo",
65
- : :register_first => true,
66
- : :join => true
67
- : )
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "carrier-pigeon"
3
- s.version = "0.6.0"
3
+ s.version = "0.7.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Sean Porter"]
6
6
  s.email = ["portertech@gmail.com"]
@@ -22,16 +22,15 @@ class CarrierPigeon
22
22
  sendln "PASS #{options[:password]}" if options[:password]
23
23
  sendln "NICK #{options[:nick]}"
24
24
  sendln "USER #{options[:nick]} 0 * :#{options[:nick]}"
25
- sendln options[:nickserv_command] if options[:nickserv_command]
26
- if options[:register_first]
27
- while line = @socket.gets
28
- case line
29
- when /^PING :(.+)$/i
30
- sendln "PONG :#{$1}"
31
- break
32
- end
25
+ while line = @socket.gets
26
+ case line
27
+ when /00[1-4] #{Regexp.escape(options[:nick])}/
28
+ break
29
+ when /^PING :(.+)$/i
30
+ sendln "PONG :#{$1}"
33
31
  end
34
32
  end
33
+ sendln options[:nickserv_command] if options[:nickserv_command]
35
34
  if options[:join]
36
35
  join = "JOIN #{options[:channel]}"
37
36
  join += " #{options[:channel_password]}" if options[:channel_password]
@@ -26,18 +26,18 @@ PRIVMSG #test :test
26
26
  QUIT :quit
27
27
  EXPECTED
28
28
 
29
- JOIN_PASSWORD = <<"EXPECTED"
29
+ PONG = <<"EXPECTED"
30
30
  NICK foo
31
31
  USER foo 0 * :foo
32
- JOIN #test bar
32
+ PONG :dummy
33
33
  PRIVMSG #test :test
34
34
  QUIT :quit
35
35
  EXPECTED
36
36
 
37
- REGISTER = <<"EXPECTED"
37
+ JOIN_PASSWORD = <<"EXPECTED"
38
38
  NICK foo
39
39
  USER foo 0 * :foo
40
- PONG :hello
40
+ JOIN #test bar
41
41
  PRIVMSG #test :test
42
42
  QUIT :quit
43
43
  EXPECTED
@@ -51,13 +51,12 @@ QUIT :quit
51
51
  EXPECTED
52
52
 
53
53
  describe CarrierPigeon do
54
-
55
54
  before do
56
55
  @server_received = ""
57
56
  @tcp_server = TCPServer.new(16667)
58
57
  Thread.new do
59
58
  socket = @tcp_server.accept
60
- socket.puts "PING :hello"
59
+ server_messages.each { |msg| socket.puts msg }
61
60
  while line = socket.gets
62
61
  @server_received << line
63
62
  socket.close if line =~ /:quit/
@@ -70,70 +69,91 @@ describe CarrierPigeon do
70
69
  sleep 1
71
70
  end
72
71
 
73
- it "can send a private message to an irc channel" do
74
- CarrierPigeon.send(
75
- :uri => "irc://foo@localhost:16667/#test",
76
- :message => "test"
77
- )
78
- @server_received.must_equal(PRIVATE_MESSAGE)
79
- end
72
+ describe "with server reply" do
73
+ let :server_messages do
74
+ [
75
+ ":dummy 001 foo :Welcome to the Internet Relay Network",
76
+ ":dummy 002 foo :Your host is dummy",
77
+ ":dummy 003 foo :This server was created now",
78
+ ":dummy 004 foo dummy"
79
+ ]
80
+ end
80
81
 
81
- it "can send a notice to an irc channel" do
82
- CarrierPigeon.send(
83
- :uri => "irc://foo@localhost:16667/#test",
84
- :message => "test",
85
- :notice => true
86
- )
87
- @server_received.must_equal(NOTICE)
88
- end
82
+ it "can send a private message to an irc channel" do
83
+ CarrierPigeon.send(
84
+ :uri => "irc://foo@localhost:16667/#test",
85
+ :message => "test"
86
+ )
87
+ @server_received.must_equal(PRIVATE_MESSAGE)
88
+ end
89
89
 
90
- it "can join an irc channel and send a private message" do
91
- CarrierPigeon.send(
92
- :uri => "irc://foo@localhost:16667/#test",
93
- :message => "test",
94
- :join => true
95
- )
96
- @server_received.must_equal(JOIN)
97
- end
90
+ it "can send a notice to an irc channel" do
91
+ CarrierPigeon.send(
92
+ :uri => "irc://foo@localhost:16667/#test",
93
+ :message => "test",
94
+ :notice => true
95
+ )
96
+ @server_received.must_equal(NOTICE)
97
+ end
98
98
 
99
- it "can join an irc channel with a password and send a private message" do
100
- CarrierPigeon.send(
101
- :uri => "irc://foo@localhost:16667/#test",
102
- :message => "test",
103
- :channel_password => "bar",
104
- :join => true
105
- )
106
- @server_received.must_equal(JOIN_PASSWORD)
107
- end
99
+ it "can join an irc channel and send a private message" do
100
+ CarrierPigeon.send(
101
+ :uri => "irc://foo@localhost:16667/#test",
102
+ :message => "test",
103
+ :join => true
104
+ )
105
+ @server_received.must_equal(JOIN)
106
+ end
108
107
 
109
- it "can identify with nickserv and send a private message to an irc channel" do
110
- CarrierPigeon.send(
111
- :uri => "irc://foo@localhost:16667/#test",
112
- :message => "test",
113
- :nickserv_password => "bar"
114
- )
115
- @server_received.must_equal(NICKSERV_PASSWORD)
116
- end
108
+ it "can join an irc channel with a password and send a private message" do
109
+ CarrierPigeon.send(
110
+ :uri => "irc://foo@localhost:16667/#test",
111
+ :message => "test",
112
+ :channel_password => "bar",
113
+ :join => true
114
+ )
115
+ @server_received.must_equal(JOIN_PASSWORD)
116
+ end
117
117
 
118
- it "can require registration and send a private message to an irc channel" do
119
- CarrierPigeon.send(
120
- :uri => "irc://foo@localhost:16667/#test",
121
- :message => "test",
122
- :register_first => true
123
- )
124
- @server_received.must_equal(REGISTER)
125
- end
118
+ it "can identify with nickserv and send a private message to an irc channel" do
119
+ CarrierPigeon.send(
120
+ :uri => "irc://foo@localhost:16667/#test",
121
+ :message => "test",
122
+ :nickserv_password => "bar"
123
+ )
124
+ @server_received.must_equal(NICKSERV_PASSWORD)
125
+ end
126
126
 
127
- it "must be provided an irc uri" do
128
- lambda {
129
- CarrierPigeon.send(:message => "test")
130
- }.must_raise RuntimeError
131
- end
127
+ it "must be provided an irc uri" do
128
+ lambda {
129
+ CarrierPigeon.send(:message => "test")
130
+ }.must_raise RuntimeError
131
+ end
132
132
 
133
- it "must be provided an irc message" do
134
- lambda {
135
- CarrierPigeon.send(:uri => "irc://foo@localhost:16667/#test")
136
- }.must_raise RuntimeError
133
+ it "must be provided an irc message" do
134
+ lambda {
135
+ CarrierPigeon.send(:uri => "irc://foo@localhost:16667/#test")
136
+ }.must_raise RuntimeError
137
+ end
137
138
  end
138
139
 
140
+ describe "with server PING before initial reply" do
141
+ let :server_messages do
142
+ [
143
+ "PING :dummy",
144
+ ":dummy 001 foo :Welcome to the Internet Relay Network",
145
+ ":dummy 002 foo :Your host is dummy",
146
+ ":dummy 003 foo :This server was created now",
147
+ ":dummy 004 foo dummy"
148
+ ]
149
+ end
150
+
151
+ it "must reply with PONG" do
152
+ CarrierPigeon.send(
153
+ :uri => "irc://foo@localhost:16667/#test",
154
+ :message => "test"
155
+ )
156
+ @server_received.must_equal(PONG)
157
+ end
158
+ end
139
159
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrier-pigeon
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sean Porter
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-29 00:00:00 -07:00
18
+ date: 2013-04-15 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency