Class: Blogger::Comment

Inherits:
Object
  • Object
show all
Includes:
Formattable
Defined in:
lib/blogger.rb

Overview

Comment

Represents a comment on a Blogger blog. Currently, Blogger only supports titles and contents for comments. The currently authenticated user will be used as the poster. To post a comment in response to a blogger post, simply use something like the following:

my_comment = Comment.new(:title => "cool", :content => "I *loved* this post!", :formatter => :rdiscount)
mypost.comment(my_comment)

or, more easily

mypost.comment(:title => "cool", :content => "I *loved* this post!", :formatter => :rdiscount)

Constant Summary

Constants included from Formattable

Formattable::ACCEPTABLE_FORMATTERS

Instance Attribute Summary collapse

Attributes included from Formattable

#formatter

Instance Method Summary collapse

Methods included from Formattable

#format_bluecloth, #format_content, #format_haml, #format_maruku, #format_peg_markdown, #format_raw, #format_rdiscount, #format_redcloth

Constructor Details

#initialize(opts = {}) ⇒ Comment

Creates a new comment. You can pass the following options:

* :title  -  the title of the comment
* :content - the content of the comment, either marked up or not
* :formatter - the formatter to use. :raw, :bluecloth, :redcloth, :peg_markdown, :maruku, :haml or :rdiscount


486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/blogger.rb', line 486

def initialize(opts={})
  if opts[:atom]
    parse(opts[:atom])
  else
    opts.each do |key, value|
      next if key =~ /blog/
      instance_variable_set("@#{key}".to_sym, value)
    end
  end
  @post = opts[:post]
  @formatter = :raw
end

Instance Attribute Details

#contentObject

content of the comment, possibly in a markdown/textile format



476
477
478
# File 'lib/blogger.rb', line 476

def content
  @content
end

#idObject

the comment’s ID (for deletion)



480
481
482
# File 'lib/blogger.rb', line 480

def id
  @id
end

#postObject

the blog this comment belongs to (for already posted comments)



478
479
480
# File 'lib/blogger.rb', line 478

def post
  @post
end

#titleObject

title of the comment



474
475
476
# File 'lib/blogger.rb', line 474

def title
  @title
end

Instance Method Details

#deleteObject

Deletes the comment from your blog.



521
522
523
524
525
526
527
528
529
530
531
532
# File 'lib/blogger.rb', line 521

def delete
  NotLoggedInError.new("You aren't logged into Blogger.").raise unless @post.blog..authenticated?
  
  path = "/feeds/#{@post.blog.id}/#{@post.id}/comments/default/#{@id}"
  
  resp = GoogleAuth.delete(path,@post.blog..auth_token, @etag)
  
  raise Blogger::PostingError.new("Error while deleting comment \"#{@title}\": #{resp.message}") unless resp.code.eql? '200'
  @post.comments.delete self
  
  self
end

#inspectObject

:nodoc:



539
540
541
# File 'lib/blogger.rb', line 539

def inspect #:nodoc:
  {:title => @title, :content => @subject}.to_yaml
end

#parse(atom) ⇒ Object

:nodoc:



499
500
501
502
503
# File 'lib/blogger.rb', line 499

def parse(atom) #:nodoc:
  @id = $2 if atom.id =~ /^tag:blogger\.com,1999:blog\-([0-9]+)\.post\-([0-9]+)$/
  @title = atom.title
  @content = atom.content
end

#post_to(post) ⇒ Object

Submits the comment to the provided post. Must be an actual post object, not an ID.



535
536
537
# File 'lib/blogger.rb', line 535

def post_to(post)
  post.comment(self)
end

#to_sObject

formats the comment as an atom entry



508
509
510
511
512
513
514
515
516
517
518
# File 'lib/blogger.rb', line 508

def to_s
  entry = Atom::Entry.new
  entry.title = @title

  content = Atom::Content.new(format_content)
  content.type = 'html'
  entry.content = content
  entry.content.type = 'html'

  entry.to_s
end