minter-raccdoc 0.0.8 → 0.0.9

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/lib/raccdoc.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Raccdoc
2
2
 
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.9'
4
4
  require 'socket'
5
5
  require 'time'
6
6
 
@@ -9,4 +9,13 @@ module Raccdoc
9
9
  require 'raccdoc/forum'
10
10
  require 'raccdoc/post'
11
11
 
12
+ end
13
+
14
+ class InvalidLogin < StandardError
15
+ end
16
+
17
+ class ConnectionError < StandardError
18
+ end
19
+
20
+ class ResponseError < StandardError
12
21
  end
@@ -2,6 +2,7 @@ module Raccdoc
2
2
  class Connection
3
3
 
4
4
  attr_reader :host
5
+ attr_reader :post
5
6
 
6
7
  # Creates a new Raccdoc connection. By default, it connects to bbs.iscabbs.com, port 6145, which is the
7
8
  # ISCABBS server.
@@ -17,22 +18,28 @@ module Raccdoc
17
18
  begin
18
19
  @socket = TCPSocket.new(args[:host],args[:port])
19
20
  rescue Errno::ECONNREFUSED
20
- raise RuntimeError, "Could not connect to #{args[:host]}, port #{args[:port]}\n"
21
+ raise ConnectionError, "Could not connect to #{args[:host]}, port #{args[:port]}\n"
21
22
  end
22
23
 
23
- response = @socket.readline.chomp
24
+ begin
25
+ response = @socket.readline.chomp
26
+ rescue EOFError
27
+ raise ConnectionError, "Got an unexpected EOF from the remote end"
28
+ end
29
+
24
30
  unless response.match(/^2/)
25
- raise RuntimeError, response
31
+ raise ConnectionError, response
26
32
  end
27
33
 
28
34
  if (args[:user] && args[:password])
29
35
  @socket.puts("LOGIN #{args[:user]}\t#{args[:password]}")
30
36
  response = @socket.readline.chomp
31
37
  unless response.match(/^2/)
32
- raise RuntimeError, response
38
+ raise InvalidLogin, response
33
39
  end
34
40
  end
35
41
  @host = args[:host]
42
+ @port = args[:port]
36
43
  end
37
44
 
38
45
  # Closes the Raccdoc connection, then closes the socket.
@@ -42,7 +49,7 @@ module Raccdoc
42
49
 
43
50
  response = @socket.readline.chomp
44
51
  unless response.match(/^2/)
45
- raise RuntimeError, response
52
+ raise ConnectionError, response
46
53
  end
47
54
  @socket.close
48
55
  end
@@ -77,7 +84,7 @@ module Raccdoc
77
84
 
78
85
  response = @socket.readline.chomp
79
86
  unless response.match(/^3/)
80
- raise RuntimeError, response
87
+ raise ResponseError, response
81
88
  end
82
89
 
83
90
  while line = @socket.readline.chomp
data/lib/raccdoc/forum.rb CHANGED
@@ -21,7 +21,7 @@ module Raccdoc
21
21
  @socket.puts "TOPIC #{forum.to_s}"
22
22
  response = @socket.readline.chomp
23
23
  unless response.match(/^2/)
24
- raise RuntimeError, response
24
+ raise ResponseError, response
25
25
  end
26
26
 
27
27
  @headers = {}
@@ -57,7 +57,7 @@ module Raccdoc
57
57
  @socket.puts("XHDR noteno #{range.to_s}")
58
58
  response = @socket.readline.chomp
59
59
  unless response.match(/^3/)
60
- raise RuntimeError, response
60
+ raise ResponseError, response
61
61
  end
62
62
 
63
63
  while line = @socket.readline.chomp
@@ -79,7 +79,7 @@ module Raccdoc
79
79
  @socket.puts("SHOW info")
80
80
  response = @socket.readline.chomp
81
81
  unless response.match(/^3/)
82
- raise RuntimeError, response
82
+ raise ResponseError, response
83
83
  end
84
84
 
85
85
  # Get header information
@@ -107,7 +107,7 @@ module Raccdoc
107
107
  @socket.puts("SETRC #{postid.to_s}")
108
108
  response = @socket.readline.chomp
109
109
  unless response.match(/^2/)
110
- raise RuntimeError, response
110
+ raise ResponseError, response
111
111
  end
112
112
  end
113
113
 
@@ -116,7 +116,7 @@ module Raccdoc
116
116
  @socket.puts("SHOW rcval")
117
117
  response = @socket.readline.chomp
118
118
  unless response.match(/^2/)
119
- raise RuntimeError, response
119
+ raise ResponseError, response
120
120
  end
121
121
  response.match(/\d+.*?:\s+(\d+)/)
122
122
  return $1
@@ -135,7 +135,7 @@ module Raccdoc
135
135
  @socket.puts("XHDR ALL #{range.to_s}")
136
136
  response = @socket.readline.chomp
137
137
  unless response.match(/^3/)
138
- raise RuntimeError, response
138
+ raise ResponseError, response
139
139
  end
140
140
 
141
141
  posts = Hash.new
@@ -171,7 +171,7 @@ module Raccdoc
171
171
  @socket.puts("POST")
172
172
  response = @socket.readline.chomp
173
173
  unless response.match(/^3/)
174
- raise RuntimeError, response
174
+ raise ResponseError, response
175
175
  end
176
176
 
177
177
  @socket.puts(body)
@@ -182,7 +182,7 @@ module Raccdoc
182
182
  postid = response.split(/:\s+/)[1]
183
183
  return Post.new(@socket,postid)
184
184
  else
185
- raise RuntimeError, response
185
+ raise ResponseError, response
186
186
  end
187
187
  end
188
188
 
@@ -197,7 +197,7 @@ module Raccdoc
197
197
  elsif response.match(/^4/)
198
198
  return false
199
199
  else
200
- raise RuntimeError, response
200
+ raise ResponseError, response
201
201
  end
202
202
  end
203
203
  end
data/lib/raccdoc/post.rb CHANGED
@@ -22,7 +22,7 @@ module Raccdoc
22
22
  @socket.puts "READ #{postid.to_s} #{dammit}"
23
23
  response = @socket.readline.chomp
24
24
  unless response.match(/^3/)
25
- raise RuntimeError, response
25
+ raise ResponseError, response
26
26
  end
27
27
 
28
28
  # Get header information
@@ -61,7 +61,7 @@ module Raccdoc
61
61
  elsif response.match(/^4/)
62
62
  return false
63
63
  else
64
- raise RuntimeError, response
64
+ raise ResponseError, response
65
65
  end
66
66
  end
67
67
 
@@ -76,7 +76,7 @@ module Raccdoc
76
76
  elsif response.match(/^4/)
77
77
  return false
78
78
  else
79
- raise RuntimeError, response
79
+ raise ResponseError, response
80
80
  end
81
81
  end
82
82
  end
data/raccdoc.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{raccdoc}
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["H. Wade Minter"]
9
- s.date = %q{2009-01-14}
9
+ s.date = %q{2009-09-03}
10
10
  s.description = %q{A Ruby interface into the Raccdoc protocol}
11
11
  s.email = %q{minter@lunenburg.org}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "lib/raccdoc/connection.rb", "lib/raccdoc/forum.rb", "lib/raccdoc/post.rb", "lib/raccdoc.rb", "LICENSE", "README.rdoc"]
@@ -16,7 +16,7 @@ class RaccdocConnectionTest < Test::Unit::TestCase
16
16
 
17
17
  def test_connection_refused_anonymous
18
18
  TCPSocket.expects(:new).with('test.bbs.example', '6145').raises(Errno::ECONNREFUSED)
19
- assert_raise(RuntimeError, 'Could not connect to test.bbs.example, port 6145') do
19
+ assert_raise(ConnectionError, 'Could not connect to test.bbs.example, port 6145') do
20
20
  bbs = Raccdoc::Connection.new(:host => 'test.bbs.example')
21
21
  end
22
22
  end
@@ -26,7 +26,7 @@ class RaccdocConnectionTest < Test::Unit::TestCase
26
26
  socket.stubs(:readline).returns("200 Server started seed:Ci0B2YeMio8ftYjElTa+EQ==").then.returns("405 Cannot process login Invalid password")
27
27
  socket.stubs(:puts)
28
28
  TCPSocket.expects(:new).returns(socket)
29
- assert_raise(RuntimeError, '404 User does not exist') do
29
+ assert_raise(InvalidLogin, '404 User does not exist') do
30
30
  bbs = Raccdoc::Connection.new(:host => 'test.bbs.example', :user => 'Bugcrusher', :password => 'BadPassword')
31
31
  end
32
32
  end
@@ -35,7 +35,7 @@ class RaccdocConnectionTest < Test::Unit::TestCase
35
35
  socket = mock()
36
36
  TCPSocket.expects(:new).returns(socket)
37
37
  socket.expects(:readline).returns("999 Stuff is messed up")
38
- assert_raise(RuntimeError) do
38
+ assert_raise(ConnectionError) do
39
39
  bbs = Raccdoc::Connection.new(:host => 'test.bbs.example')
40
40
  end
41
41
  end
@@ -52,7 +52,7 @@ class RaccdocConnectionTest < Test::Unit::TestCase
52
52
  @socket.stubs(:close)
53
53
  @socket.stubs(:closed?).returns(false)
54
54
  @socket.stubs(:readline).returns("999 Something Broke")
55
- assert_raise(RuntimeError) do
55
+ assert_raise(ConnectionError) do
56
56
  @bbs.logout
57
57
  end
58
58
  end
@@ -74,7 +74,7 @@ class RaccdocConnectionTest < Test::Unit::TestCase
74
74
 
75
75
  def test_forums_failure
76
76
  @socket.stubs(:readline).returns("999 Stuff Broke")
77
- assert_raise(RuntimeError) do
77
+ assert_raise(ResponseError) do
78
78
  forums = @bbs.forums
79
79
  end
80
80
  end
@@ -21,7 +21,7 @@ class RaccdocForumTest < Test::Unit::TestCase
21
21
  socket = mock()
22
22
  socket.stubs(:puts)
23
23
  socket.stubs(:readline).returns('999 Stuff broke')
24
- assert_raise(RuntimeError) do
24
+ assert_raise(ResponseError) do
25
25
  forum = Raccdoc::Forum.new(socket,0)
26
26
  end
27
27
  end
@@ -51,7 +51,7 @@ class RaccdocForumTest < Test::Unit::TestCase
51
51
 
52
52
  def test_noteids_failure
53
53
  @socket.stubs(:readline).returns("999 Stuff Broke")
54
- assert_raise(RuntimeError) do
54
+ assert_raise(ResponseError) do
55
55
  notes = @forum.noteids
56
56
  end
57
57
  end
@@ -64,7 +64,7 @@ class RaccdocForumTest < Test::Unit::TestCase
64
64
 
65
65
  def test_forum_information_failure
66
66
  @socket.stubs(:readline).returns("999 Stuff broke")
67
- assert_raise(RuntimeError) do
67
+ assert_raise(ResponseError) do
68
68
  fi = @forum.forum_information
69
69
  end
70
70
  end
@@ -76,7 +76,7 @@ class RaccdocForumTest < Test::Unit::TestCase
76
76
 
77
77
  def test_set_first_unread_fails
78
78
  @socket.stubs(:readline).returns('999 Stuff Broke')
79
- assert_raises(RuntimeError) do
79
+ assert_raises(ResponseError) do
80
80
  @forum.first_unread=99999
81
81
  end
82
82
  end
@@ -89,7 +89,7 @@ class RaccdocForumTest < Test::Unit::TestCase
89
89
 
90
90
  def test_first_unread_fails
91
91
  @socket.stubs(:readline).returns("999 Stuff Broke")
92
- assert_raises(RuntimeError) do
92
+ assert_raises(ResponseError) do
93
93
  first = @forum.first_unread
94
94
  end
95
95
  end
@@ -108,7 +108,7 @@ class RaccdocForumTest < Test::Unit::TestCase
108
108
 
109
109
  def test_post_headers_fail
110
110
  @socket.stubs(:readline).returns("999 Stuff broke")
111
- assert_raise(RuntimeError) do
111
+ assert_raise(ResponseError) do
112
112
  headers = @forum.post_headers
113
113
  end
114
114
  end
@@ -134,14 +134,14 @@ class RaccdocForumTest < Test::Unit::TestCase
134
134
 
135
135
  def test_create_post_early_failure
136
136
  @socket.stubs(:readline).returns('999 Stuff broke')
137
- assert_raise(RuntimeError) do
137
+ assert_raise(ResponseError) do
138
138
  post = @forum.post("This is a test")
139
139
  end
140
140
  end
141
141
 
142
142
  def test_create_post_late_failure
143
143
  @socket.stubs(:readline).returns('350 Send note body maxsize:50000').then.returns('999 Stuff broke')
144
- assert_raise(RuntimeError) do
144
+ assert_raise(ResponseError) do
145
145
  post = @forum.post("This is a test")
146
146
  end
147
147
  end
@@ -158,7 +158,7 @@ class RaccdocForumTest < Test::Unit::TestCase
158
158
 
159
159
  def test_okay_post_fail
160
160
  @socket.stubs(:readline).returns("999 Stuff broke")
161
- assert_raise(RuntimeError) do
161
+ assert_raise(ResponseError) do
162
162
  @forum.post?
163
163
  end
164
164
  end
@@ -14,7 +14,7 @@ class RaccdocPostTest < Test::Unit::TestCase
14
14
 
15
15
  def test_post_object_creation_failure
16
16
  @socket.stubs(:readline).returns("410 No Such Note")
17
- assert_raise(RuntimeError) do
17
+ assert_raise(ResponseError) do
18
18
  @post = Raccdoc::Post.new(@socket, 9999)
19
19
  end
20
20
  end
@@ -33,7 +33,7 @@ class RaccdocPostTest < Test::Unit::TestCase
33
33
 
34
34
  def test_delete_exception
35
35
  @socket.stubs(:readline).returns("999 Stuff Broke")
36
- assert_raise(RuntimeError) do
36
+ assert_raise(ResponseError) do
37
37
  status = @post.delete
38
38
  end
39
39
  end
@@ -52,7 +52,7 @@ class RaccdocPostTest < Test::Unit::TestCase
52
52
 
53
53
  def test_delete_permissions_exception
54
54
  @socket.stubs(:readline).returns("999 Stuff broke")
55
- assert_raise(RuntimeError) do
55
+ assert_raise(ResponseError) do
56
56
  status = @post.delete?
57
57
  end
58
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minter-raccdoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - H. Wade Minter
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-14 00:00:00 -08:00
12
+ date: 2009-09-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: echoe
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements: