Class: Blogger::Blog
- Inherits:
-
Object
- Object
- Blogger::Blog
- Defined in:
- lib/blogger.rb
Overview
Blog
Encapsulates a Blog retrieved from your user account. This class can be used for searching for posts, or for uploading posts via the post
method. Blog objects are only safely retrieved via the Blogger::Account class, either via Account#blogs or Account#blog_for_id.
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#authors ⇒ Object
Returns the value of attribute authors.
-
#id ⇒ Object
Returns the value of attribute id.
-
#published ⇒ Object
Returns the value of attribute published.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Blog
constructor
:nodoc:.
-
#post(post) ⇒ Object
Uploads the provided post to this blog.
- #posts(force_reload = false) ⇒ Object
-
#retrieve_posts ⇒ Object
Downloads all the posts for this blog.
Constructor Details
#initialize(opts = {}) ⇒ Blog
:nodoc:
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/blogger.rb', line 198 def initialize(opts = {}) #:nodoc: entry = opts[:atom] @authors = [] @title = entry.title.html.strip @id = $2 if entry.id =~ /tag:blogger\.com,1999:user\-([0-9]+)\.blog\-([0-9]+)$/ entry..each do || @authors << end @updated = entry.updated @published = entry.published @account = opts[:account] if opts[:account] end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
197 198 199 |
# File 'lib/blogger.rb', line 197 def account @account end |
#authors ⇒ Object
Returns the value of attribute authors.
194 195 196 |
# File 'lib/blogger.rb', line 194 def @authors end |
#id ⇒ Object
Returns the value of attribute id.
193 194 195 |
# File 'lib/blogger.rb', line 193 def id @id end |
#published ⇒ Object
Returns the value of attribute published.
195 196 197 |
# File 'lib/blogger.rb', line 195 def published @published end |
#title ⇒ Object
Returns the value of attribute title.
192 193 194 |
# File 'lib/blogger.rb', line 192 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
196 197 198 |
# File 'lib/blogger.rb', line 196 def updated @updated end |
Instance Method Details
#post(post) ⇒ Object
Uploads the provided post to this blog. Requires that you be logged into your blogger account via the Blogger::Account class.
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/blogger.rb', line 213 def post(post) NotLoggedInError.new("You aren't logged into Blogger.").raise unless @account.authenticated? path = "/feeds/#{@id}/posts/default" data = post.to_s resp = GoogleAuth.post(path, data, @account.auth_token) raise Blogger::PostingError.new("Error while posting to blog_id #{@id}: #{resp.}") unless resp.code.eql? '201' post.parse Atom::Entry.parse(resp.body) end |
#posts(force_reload = false) ⇒ Object
225 226 227 228 |
# File 'lib/blogger.rb', line 225 def posts(force_reload = false) return @posts if @posts && !(force_reload) retrieve_posts end |
#retrieve_posts ⇒ Object
Downloads all the posts for this blog.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/blogger.rb', line 231 def retrieve_posts NotLoggedInError.new("You aren't logged into Blogger.").raise unless @account.authenticated? path = "/feeds/#{@id}/posts/default" resp = GoogleAuth.get(path, @account.auth_token) raise Blogger::RetrievalError.new("Error while retrieving posts for blog id ##{@id}: #{resp.}") unless resp.code.eql? '200' feed = Atom::Feed.parse(resp.body) @posts = [] feed.entries.each do |entry| @posts << Post.new(:atom => entry, :blog => self) end @posts end |