Class: Raccdoc::Forum
- Inherits:
-
Object
- Object
- Raccdoc::Forum
- Defined in:
- lib/raccdoc/forum.rb
Instance Attribute Summary collapse
-
#admin ⇒ Object
readonly
Returns the value of attribute admin.
-
#anonymous ⇒ Object
readonly
Returns the value of attribute anonymous.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#private ⇒ Object
readonly
Returns the value of attribute private.
Instance Method Summary collapse
-
#first_unread ⇒ Object
Returns the post ID number of the last read post in the forum.
-
#first_unread=(postid = 0) ⇒ Object
Sets the current user’s first-unread pointer to the specified number.
-
#forum_information ⇒ Object
Returns a hash of the forum information.
-
#initialize(socket, forum = 0) ⇒ Forum
constructor
Sets the active forum on the server to the specified forum number (0) or name (Lobby, Program), then returns a new Raccdoc::Forum object.
-
#noteids(range = "") ⇒ Object
Returns an array of all current post IDs in the forum.
-
#post(body) ⇒ Object
Creates a new post in the current forum using the text provided in the argument.
-
#post? ⇒ Boolean
Checks to see if the currently logged in user has permission to post in the current forum.
-
#post_headers(range = "") ⇒ Object
Returns a hash of information about the posts in the forum.
-
#read(postid) ⇒ Object
Returns a new Raccdoc::Post object for the specified post ID in the current forum.
-
#read!(postid) ⇒ Object
Attempts to do a “DAMMIT” read, overriding anonymous and deleted flags.
Constructor Details
#initialize(socket, forum = 0) ⇒ Forum
Sets the active forum on the server to the specified forum number (0) or name (Lobby, Program), then returns a new Raccdoc::Forum object.
There are five instance variables exposed through attr_reader:
-
id - The forum ID number
-
name - The forum name
-
admin - The name of the forum administrator
-
anonymous - either true, false, or force, depending on whether the anonymous posting option is on, off, or required
-
private - True if the forum is private (invite-only), false otherwise
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/raccdoc/forum.rb', line 19 def initialize(socket, forum = 0) @socket = socket @socket.puts "TOPIC #{forum.to_s}" response = @socket.readline.chomp unless response.match(/^2/) raise ResponseError, response end @headers = {} tuples = response.split(/\t/) tuples.delete_at(0) tuples.each do |pair| (key, value) = pair.split(/:/) @headers[key.downcase.to_sym] = value end flags = @headers[:flags].split(',') if flags.include?("forceanonymous") @anonymous = "force" elsif flags.include?("cananonymous") @anonymous = true else @anonymous = false end @private = flags.include?("private") ? true : false @id = @headers[:topic] @name = @headers[:name] @admin = @headers[:admin].split('/')[1] end |
Instance Attribute Details
#admin ⇒ Object (readonly)
Returns the value of attribute admin.
6 7 8 |
# File 'lib/raccdoc/forum.rb', line 6 def admin @admin end |
#anonymous ⇒ Object (readonly)
Returns the value of attribute anonymous.
7 8 9 |
# File 'lib/raccdoc/forum.rb', line 7 def anonymous @anonymous end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/raccdoc/forum.rb', line 4 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/raccdoc/forum.rb', line 5 def name @name end |
#private ⇒ Object (readonly)
Returns the value of attribute private.
8 9 10 |
# File 'lib/raccdoc/forum.rb', line 8 def private @private end |
Instance Method Details
#first_unread ⇒ Object
Returns the post ID number of the last read post in the forum. Any posts greater than that number can be considered unread.
115 116 117 118 119 120 121 122 123 |
# File 'lib/raccdoc/forum.rb', line 115 def first_unread @socket.puts("SHOW rcval") response = @socket.readline.chomp unless response.match(/^2/) raise ResponseError, response end response.match(/\d+.*?:\s+(\d+)/) return $1 end |
#first_unread=(postid = 0) ⇒ Object
Sets the current user’s first-unread pointer to the specified number. Any posts greater than that number will be listed as unread.
106 107 108 109 110 111 112 |
# File 'lib/raccdoc/forum.rb', line 106 def first_unread=(postid = 0) @socket.puts("SETRC #{postid.to_s}") response = @socket.readline.chomp unless response.match(/^2/) raise ResponseError, response end end |
#forum_information ⇒ Object
Returns a hash of the forum information. Keys are:
-
from - The username of the user who last updated the FI
-
date - The date the forum information was last updated (a Time object)
-
body - The actual text of the FI
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/raccdoc/forum.rb', line 77 def forum_information fi = Hash.new @socket.puts("SHOW info") response = @socket.readline.chomp unless response.match(/^3/) raise ResponseError, response end # Get header information while line = @socket.readline.chomp break if line.match(/^$/) (key, value) = line.split(/: /) if key.downcase == "date" value = Time.parse(value) end fi[key.downcase.to_sym] = value end body = "" while line = @socket.readline break if line.match(/^\.$/) body << line end fi[:body] = body return fi end |
#noteids(range = "") ⇒ Object
Returns an array of all current post IDs in the forum.
Takes an optional range string of the form oldest_noteid-newest_noteid. The oldest or newest can be omitted as needed.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/raccdoc/forum.rb', line 55 def noteids(range = "") noteids = Array.new @socket.puts("XHDR noteno #{range.to_s}") response = @socket.readline.chomp unless response.match(/^3/) raise ResponseError, response end while line = @socket.readline.chomp break if line.match(/^\.$/) (tag,noteid) = line.split(/:/) noteids.push(noteid.to_i) end return noteids end |
#post(body) ⇒ Object
Creates a new post in the current forum using the text provided in the argument.
Returns a new Raccdoc::Post object that results from reading the newly created post.
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/raccdoc/forum.rb', line 170 def post(body) @socket.puts("POST") response = @socket.readline.chomp unless response.match(/^3/) raise ResponseError, response end @socket.puts(body) @socket.puts(".") response = @socket.readline.chomp if response.match(/^2/) postid = response.split(/:\s+/)[1] return Post.new(@socket,postid) else raise ResponseError, response end end |
#post? ⇒ Boolean
Checks to see if the currently logged in user has permission to post in the current forum.
Returns true or false.
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/raccdoc/forum.rb', line 192 def post? @socket.puts("OKAY POST") response = @socket.readline.chomp if response.match(/^2/) return true elsif response.match(/^4/) return false else raise ResponseError, response end end |
#post_headers(range = "") ⇒ Object
Returns a hash of information about the posts in the forum. The hash is keyed off of the post ID, and the value is a hash containing the following information:
-
author - The username of the user who created the post
-
date - The date the post was created or, if the post is anonymous, the current date in UTC
-
subject - The first line of the post
-
size - The size of the post in bytes
-
authority - If the post was made with Sysop or Forum Manager status, this is set
You may provide an optional range (in the form “start_id-end_id”) to limit the number of posts returned. The default is to return all posts in the forum.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/raccdoc/forum.rb', line 134 def post_headers(range = "") @socket.puts("XHDR ALL #{range.to_s}") response = @socket.readline.chomp unless response.match(/^3/) raise ResponseError, response end posts = Hash.new while (line = @socket.readline.chomp) break if line.match(/^\.$/) tmpdata = Hash.new line.split(/\t/).each do |tuple| (key, value) = tuple.split(/:/, 2) tmpdata[key.downcase.to_sym] = value end tmpdata[:date] = tmpdata[:date] ? Time.parse(tmpdata[:date]) : Time.new.getgm tmpdata[:author] = tmpdata[:"formal-author"] ? tmpdata[:"formal-author"].split('/')[1] : 'Anonymous' posts[tmpdata[:noteno]] = tmpdata end return posts end |