Class: GovernorBlogger::Blogger
- Inherits:
-
Object
- Object
- GovernorBlogger::Blogger
- Defined in:
- lib/governor_blogger/blogger.rb
Instance Method Summary collapse
-
#initialize(article) ⇒ Blogger
constructor
A new instance of Blogger.
- #post ⇒ Object
- #put ⇒ Object
Constructor Details
#initialize(article) ⇒ Blogger
Returns a new instance of Blogger.
3 4 5 6 7 8 9 |
# File 'lib/governor_blogger/blogger.rb', line 3 def initialize(article) @article = article @blogger = GData::Client::Blogger.new # log in @blogger.clientlogin(GovernorBlogger.config.username, GovernorBlogger.config.password) end |
Instance Method Details
#post ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/governor_blogger/blogger.rb', line 11 def post entry = Nokogiri::XML::Builder.new do |xml| xml.entry(:xmlns => 'http://www.w3.org/2005/Atom') do xml.title @article.title, :type => 'text' xml.content(:type => 'xhtml') { |content| content << body } end end.to_xml # post to page, retrieve blogger_id response = @blogger.post(page, entry) post_id = response.headers['location'].match(%r{posts/default/(\d+)})[1] post_id end |
#put ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/governor_blogger/blogger.rb', line 24 def put # retrieve post xml = @blogger.get(page).to_xml # transform XML xml.children.detect{|e| e.name == 'title' }.text = @article.title xml.children.detect{|e| e.name == 'content' }.text = body # post back to page @blogger.put(page, xml) end |