Class: Redsync::RemoteWiki
- Inherits:
-
Object
- Object
- Redsync::RemoteWiki
- Defined in:
- lib/redsync/remote_wiki.rb
Instance Method Summary collapse
- #get(name) ⇒ Object
-
#initialize(options) ⇒ RemoteWiki
constructor
A new instance of RemoteWiki.
- #list ⇒ Object
- #write(name, content) ⇒ Object
Constructor Details
#initialize(options) ⇒ RemoteWiki
Returns a new instance of RemoteWiki.
6 7 8 9 10 |
# File 'lib/redsync/remote_wiki.rb', line 6 def initialize() @url = [:url] @api_key = [:api_key] @agent = Mechanize.new end |
Instance Method Details
#get(name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/redsync/remote_wiki.rb', line 29 def get(name) list unless @pages return nil if @pages[name].nil? unless @pages[name].content page = @agent.get(@url + "/#{URI.encode(name)}.xml?key=#{@api_key}") @pages[name].content = page.at("text").text end @pages[name] end |
#list ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/redsync/remote_wiki.rb', line 12 def list unless @pages @pages = {} index = @agent.get(@url + "/index.xml?key=#{@api_key}") index.xml.at("wiki_pages").children.each do |node| name = node.at("title").text @pages[name] = WikiPage.new( :name => name, :mtime => Time.parse(node.at("updated_on").text), ) end end @pages.values end |
#write(name, content) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/redsync/remote_wiki.rb', line 43 def write(name, content) doc = Nokogiri::XML::Document.new wiki_page = Nokogiri::XML::Node.new("wiki_page", doc) text = Nokogiri::XML::Node.new("text", doc) text.content = content comments = Nokogiri::XML::Node.new("comments", doc) comments.content = "Uploaded by Redsync" doc << wiki_page wiki_page << text wiki_page << comments @agent.put(@url + "/#{URI.encode(name)}.xml?key=#{@api_key}", doc.to_s, 'Content-Type' => "text/xml") end |