Class: Writeboard
- Inherits:
-
Object
- Object
- Writeboard
- Defined in:
- lib/rwriteboard.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#cookie ⇒ Object
Returns the value of attribute cookie.
-
#header ⇒ Object
Returns the value of attribute header.
-
#http ⇒ Object
Returns the value of attribute http.
-
#name ⇒ Object
Returns the value of attribute name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#path ⇒ Object
Returns the value of attribute path.
-
#session ⇒ Object
Returns the value of attribute session.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(hash) ⇒ Writeboard
constructor
A new instance of Writeboard.
- #logged_in ⇒ Object
- #post_without_revision(hash = {}) ⇒ Object
- #set_attributes_from_hash(hash) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Writeboard
Returns a new instance of Writeboard.
27 28 29 30 31 32 33 |
# File 'lib/rwriteboard.rb', line 27 def initialize(hash) self.password = hash[:password] self.path = hash[:path] self.name = hash[:name] @@writeboards << self self end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def body @body end |
#cookie ⇒ Object
Returns the value of attribute cookie.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def end |
#header ⇒ Object
Returns the value of attribute header.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def header @header end |
#http ⇒ Object
Returns the value of attribute http.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def http @http end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def name @name end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def password @password end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def path @path end |
#session ⇒ Object
Returns the value of attribute session.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def session @session end |
#title ⇒ Object
Returns the value of attribute title.
7 8 9 |
# File 'lib/rwriteboard.rb', line 7 def title @title end |
Class Method Details
.count ⇒ Object
91 92 93 |
# File 'lib/rwriteboard.rb', line 91 def self.count @@writeboards.size end |
.create(hash) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rwriteboard.rb', line 70 def self.create(hash) password = hash[:password] path = hash[:path] || hash[:id] || hash[:address] || "" path = "/" + path unless path =~ /^\// name = hash[:name] || self.count + 1 wb = self.new(:password => password, :path => path, :name => name) if block_given? wb.logged_in do |_wb| yield _wb end end wb end |
.find(hash) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rwriteboard.rb', line 19 def @@writeboards.find(hash) memo = self hash.each do |k,v| memo = [memo.detect {|wb| !wb.nil? && wb.respond_to?(k.to_sym) && wb.send(k.to_sym) == v}] end memo.first end |
.writeboards ⇒ Object
95 96 97 |
# File 'lib/rwriteboard.rb', line 95 def self.writeboards @@writeboards end |
Instance Method Details
#get ⇒ Object
35 36 37 38 39 40 |
# File 'lib/rwriteboard.rb', line 35 def get response_body = self.http.get(self.path, self.).body.html_entity_quotes self.title = response_body.scan(%r{<div class="writeboardtitle">(.*?)</div>}m).to_s. self.body = response_body.scan(%r{<div class="writeboardbody">(.*?)</div>}m).to_s..unescape_newlines self end |
#logged_in ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rwriteboard.rb', line 42 def logged_in Net::HTTP.start('123.writeboard.com') do |http| login_path = self.path + "/login" self.header = "password=#{self.password}" login_response = http.post(login_path, self.header) = {'Cookie' => login_response.response['Set-Cookie']} self.http = http self. = self.session = ['Cookie'][1] yield self end end |
#post_without_revision(hash = {}) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rwriteboard.rb', line 55 def post_without_revision(hash={}) raise "There is no connection" unless self.http set_attributes_from_hash(hash) self.get unless self.title && self.body postdata = "minor_edit=1" + "&" + "commit=Save over the current version" + "&" + "version[body]=#{self.body.gsub(%r(\\n), "<br />")}" + "&" + "version[title]=#{self.title}" self.http.post(self.path + "/v/create", postdata, self.) end |
#set_attributes_from_hash(hash) ⇒ Object
66 67 68 |
# File 'lib/rwriteboard.rb', line 66 def set_attributes_from_hash(hash) hash.each {|k,v| self.send(k.to_s.concat("=").to_sym, v)} end |